Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Api no_std compatible #377

Merged
merged 6 commits into from
Dec 23, 2022
Merged

Make Api no_std compatible #377

merged 6 commits into from
Dec 23, 2022

Conversation

haerdib
Copy link
Contributor

@haerdib haerdib commented Dec 15, 2022

🌈 Featuring added no_std compatibility for the full Api included traits and the implementations (except for the rpc clients)

  • removes sp-std dependency. Whenever possible, depend on core or alloc directly. The std version itself points to them as well. No need for an extra library to do that,
  • Introduces a lot of substrate types in primitives/serde_impls to implement serde also in no_std. Wherever sensible, the conversion from substrate type and redefined type has been implemented with From. So the newly self-implemented types should not pose a big problem for the user. Another good thing: If substrate updates the types, this will be noticed quite fast via the unit tests.
  • Removed MaybeSerializeDeserialize because this only enforces (De)Serialization only in std mode.
  • Reimplemented NumberOrHex because sp-rpc is not no_std compatible.
  • Removed some unused error types in src/api/error.rs

closes #279

@haerdib haerdib self-assigned this Dec 15, 2022
@haerdib haerdib force-pushed the bh/make-api-no-std-compatible branch 3 times, most recently from ee62727 to 175e991 Compare December 20, 2022 15:22
@haerdib haerdib changed the title Make api no_std compatible Make Api no_std compatible Dec 21, 2022
@haerdib haerdib force-pushed the bh/make-api-no-std-compatible branch from a5210cd to e5b0b78 Compare December 22, 2022 09:24
@haerdib haerdib marked this pull request as ready for review December 22, 2022 10:30
Copy link
Collaborator

@clangenb clangenb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool we were not so far away after all! :D I only have a comment about documentation.

use codec::{Decode, Encode, Error as CodecError};
use frame_metadata::{
PalletConstantMetadata, RuntimeMetadata, RuntimeMetadataLastVersion, RuntimeMetadataPrefixed,
StorageEntryMetadata, META_RESERVED,
};
use scale_info::{form::PortableForm, PortableRegistry, Type};
use sp_core::storage::StorageKey;

#[cfg(feature = "std")]
use serde::Serialize;

// We use `BTreeMap` because we can't use `HashMap` in `no_std`.
Copy link
Collaborator

@clangenb clangenb Dec 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you move this comment too?

Comment on lines +29 to +30
+ Serialize
+ DeserializeOwned
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we enforce something that is more than what the trait bounds in substrate guarantee Hence, we should maybe add a comment that those types need to re-implement serialization similar to how you re-implemented it for substrate types. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree. I also added two issues in that regard: #393 & #391

But a comment here would not hurt.

Copy link
Contributor

@Niederb Niederb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and a nice improvement. The type duplication from substrate is a bit unfortunate, let's hope they agree to provide serialization also in no_std environments.

primitives/src/types.rs Outdated Show resolved Hide resolved
primitives/src/types.rs Outdated Show resolved Hide resolved
remove rpc crate dep

always use alloc

make api no-std compatible

fix NumberOrHex

update deps

remove unused error

make rpc open as well

add postcard as Deserializer

fix rpc params

some further fixes

amek rpc no-std compatible

enfore Serialize and Deserialize instead of Maybe

compile :)

fix CI

fix build

fmt

fix rebase errors

add insert_with_allocation_test works

fix no_std build

more copy paste

add no_std compatibility

fix taplo

remove sp_std

cargo fmt

remove extra space

remove std feature obsolete

remove obsolsete std feature

remove unused comment

Fix ci.yml (#389)

* fix ci.yml

* fix ci

fmt

impl serialize for NumberOrHex

remove unnecessary redefined types

extract serde impls from types and import whatever possible

add from impls and tests

add comment

some more comments

udpate comment

add storage change set

fix from serde impl

fix build

remove std only feature to subscription

let it compile again :)

fix tests

remove some more std only feature

make tx payment no_std compatible

add extrinsic to no_std compatibility

add balances extrinisc to no-std
@haerdib haerdib force-pushed the bh/make-api-no-std-compatible branch from 84a40e2 to d03d7cd Compare December 23, 2022 07:10
Copy link
Collaborator

@clangenb clangenb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful, thanks for the extra documentation!

@haerdib haerdib merged commit 346db81 into master Dec 23, 2022
@haerdib haerdib deleted the bh/make-api-no-std-compatible branch December 23, 2022 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Be fully no_std compatible (except for ws rpc)
3 participants