Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resolver = "2"
members = [
# Layer 0: Scalable Web3 Storage
"client",
"crates/storage-subxt",
"pallet",
"primitives",
"provider-node",
Expand Down Expand Up @@ -43,6 +44,7 @@ storage-client = { path = "client" }
storage-parachain-runtime = { path = "runtimes/web3-storage-local" }
storage-primitives = { path = "primitives", default-features = false }
storage-provider-node = { path = "provider-node" }
storage-subxt = { path = "crates/storage-subxt" }

# Storage Interfaces: File System Interface
file-system-client = { path = "storage-interfaces/file-system/client" }
Expand Down Expand Up @@ -166,6 +168,7 @@ rand = "0.8"

# Subxt (chain interaction for off-chain clients)
subxt = { version = "0.44.3" }
subxt-core = { version = "0.44.3", default-features = false }
subxt-signer = { version = "0.44.3", features = ["sr25519"] }

# Testing
Expand Down
32 changes: 32 additions & 0 deletions crates/storage-subxt/Cargo.toml
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",
]
43 changes: 43 additions & 0 deletions crates/storage-subxt/README.md
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" \
Comment on lines +32 to +41

Copy link
Copy Markdown
Collaborator

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.

Copy link
Copy Markdown
Member Author

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-type to scope them to only the types that actually need them.

Copy link
Copy Markdown
Collaborator

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?

Copy link
Copy Markdown
Collaborator

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?

@danielbui12 what about this one?

| 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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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..

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@bkontur my bad for not checking changes

Binary file not shown.
22 changes: 22 additions & 0 deletions crates/storage-subxt/src/lib.rs
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::*;
Loading
Loading