-
Notifications
You must be signed in to change notification settings - Fork 1
Add storage-subxt crate with static codegen runtime bindings #282
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
Changes from all commits
c27e484
325edb7
73b4e1d
4c06c6e
d83397d
195783e
5ed1d46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| [package] | ||
| name = "storage-subxt" | ||
| description = "Rust bindings and interface to interact with Web3 Storage using subxt" | ||
| version = "0.1.0" | ||
| authors.workspace = true | ||
| edition.workspace = true | ||
| license = "Apache-2.0" | ||
| repository.workspace = true | ||
| exclude = ["./metadata"] | ||
| readme = "README.md" | ||
|
|
||
|
|
||
| [dependencies] | ||
| codec = { workspace = true } | ||
| scale-info = { workspace = true } | ||
| subxt = { workspace = true, features = ["jsonrpsee"], optional = true } | ||
| subxt-signer = { workspace = true, features = ["ecdsa", "sr25519", "subxt"] } | ||
| serde = { workspace = true, features = ["derive"] } | ||
| subxt-core = { workspace = true } | ||
|
|
||
| [features] | ||
| default = ["std"] | ||
| std = [ | ||
| "codec/std", | ||
| "dep:subxt", | ||
| "scale-info/std", | ||
| "serde/std", | ||
| "subxt-core/std", | ||
| "subxt-signer/std", | ||
| "subxt/jsonrpsee", | ||
| "subxt/native", | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # Web3-Storage-Subxt | ||
|
|
||
| ### Downloading metadata from a Substrate node | ||
|
|
||
| Use the [`subxt-cli`](https://crates.io/crates/subxt-cli) tool to download the metadata for your target runtime from a node. | ||
|
|
||
| 1. Install: | ||
|
|
||
| ```bash | ||
| cargo install subxt-cli@0.44.3 --force --locked | ||
| ``` | ||
|
|
||
| 2. To Save the metadata of runtime: | ||
| Run the release build of the web3-storage runtime: | ||
| ```rust | ||
| just start-paseo-chain | ||
| ``` | ||
|
|
||
| Then on another terminal run: | ||
| ```bash | ||
| subxt metadata -f bytes --url ws://localhost:2222 > ./metadata/storage_paseo_runtime.scale | ||
| ``` | ||
|
|
||
| 3. Generating the subxt code from the metadata: | ||
|
|
||
| ```bash | ||
| subxt codegen --file ./metadata/storage_paseo_runtime.scale \ | ||
| --crate "::subxt_core" \ | ||
| --derive Clone \ | ||
| --derive Eq \ | ||
| --derive PartialEq \ | ||
| --derive-for-type "pallet_storage_provider::pallet::ProviderInfo=serde::Serialize" \ | ||
| --derive-for-type "pallet_storage_provider::pallet::ProviderInfo=serde::Deserialize" \ | ||
| --derive-for-type "pallet_storage_provider::pallet::ProviderSettings=serde::Serialize" \ | ||
| --derive-for-type "pallet_storage_provider::pallet::ProviderSettings=serde::Deserialize" \ | ||
| --derive-for-type "pallet_storage_provider::pallet::ProviderStats=serde::Serialize" \ | ||
| --derive-for-type "pallet_storage_provider::pallet::ProviderStats=serde::Deserialize" \ | ||
| --derive-for-type "bounded_collections::bounded_vec::BoundedVec=serde::Serialize" \ | ||
| --derive-for-type "bounded_collections::bounded_vec::BoundedVec=serde::Deserialize" \ | ||
| --derive-for-type "sp_runtime::MultiSignature=codec::Encode" \ | ||
| --derive-for-type "sp_runtime::MultiSignature=codec::Decode" \ | ||
| | rustfmt --edition=2021 --emit=stdout > ./src/storage_paseo_runtime.rs | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| // TODO: resolve mainnet scale | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @danielbui12 why was this not removed? we discussed to remove all the mainnet stuff..
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bkontur my bad for not checking changes |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #![deny( | ||
| stable_features, | ||
| non_shorthand_field_patterns, | ||
| renamed_and_removed_lints, | ||
| unsafe_code | ||
| )] | ||
|
|
||
| pub use codec; | ||
| pub use scale_info; | ||
| #[cfg(feature = "std")] | ||
| pub use subxt; | ||
| #[cfg(feature = "std")] | ||
| pub use subxt::ext::subxt_core; | ||
| #[cfg(not(feature = "std"))] | ||
| pub use subxt_core; | ||
| pub use subxt_signer; | ||
|
|
||
| #[rustfmt::skip] | ||
| pub mod storage_paseo_runtime; | ||
| pub use storage_paseo_runtime::*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand all these are good-to-haves, but so far they're not really required by any consumers, right? And as long as we can avoid anything hand-enumerative, I'd rather do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say yes, we do need. subxt codegen generates the runtime types with only a minimal set of derives.
As my experience in #239, when wiring subxt codegen with rust clients, I faced several errors like
the trait X is not implemented for struct....We could use
subxt codegen ...--derive <Derive>to apply to all structs/types . but I prefer--derive-for-typeto scope them to only the types that actually need them.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not fan of duplicating the info (this can go out-of-sync easily), can we just reference
just subxt-codegen?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@danielbui12 what about this one?