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
40 changes: 14 additions & 26 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,41 +181,29 @@ jobs:
- name: Cargo check all targets.
run: cargo check --all-targets

# Next, check subxt features.
# Next, check each subxt feature in isolation.
# - `native` feature must always be enabled
# - `web` feature is always ignored.
# - This means, don't check --no-default-features and don't try enabling --all-features; both will fail
- name: Cargo hack; check each subxt feature
run: cargo hack -p subxt --each-feature check --exclude-no-default-features --exclude-all-features --exclude-features web --features native
run: cargo hack -p subxt --each-feature check --exclude-features web --features native

# Same with subxt-historic
- name: Cargo hack; check each subxt feature
run: cargo hack -p subxt-historic --each-feature check --exclude-no-default-features --exclude-all-features --exclude-features web --features native
run: cargo hack -p subxt-historic --each-feature check --exclude-features web --features native

# Subxt-signer has the "subxt" features enabled in the "check all targets" test. Run it on its own to
# check it without. We can't enable subxt or web features here, so no cargo hack.
- name: Cargo check subxt-signer
run: |
cargo check -p subxt-signer
cargo check -p subxt-signer --no-default-features --features sr25519
cargo check -p subxt-signer --no-default-features --features ecdsa
cargo check -p subxt-signer --no-default-features --features unstable-eth
# And with subxt-rpcs
- name: Cargo hack; check each subxt-rpcs feature
run: cargo hack -p subxt-rpcs --each-feature check --exclude-features web --features native

# Subxt-rpcs has a bunch of clients that can be exposed. Check that they all stand on their own.
- name: Cargo check subxt-rpcs
run: |
cargo check -p subxt-rpcs
cargo check -p subxt-rpcs --no-default-features --features native
cargo check -p subxt-rpcs --no-default-features --features native,subxt
cargo check -p subxt-rpcs --no-default-features --features native,jsonrpsee
cargo check -p subxt-rpcs --no-default-features --features native,reconnecting-rpc-client
cargo check -p subxt-rpcs --no-default-features --features native,mock-rpc-client
cargo check -p subxt-rpcs --no-default-features --features native,unstable-light-client

# We can't enable web features here, so no cargo hack.
# And with subxt-signer (seems to work with a more basic check here; disable web if it becomes an issue).
- name: Cargo hack; check each subxt-signer feature
run: cargo hack -p subxt-signer --each-feature check

# And for subxt-lightclient.
- name: Cargo check subxt-lightclient
run: cargo check -p subxt-lightclient
run: cargo hack -p subxt-lightclient --each-feature check --exclude-features web --features native

# Next, check each other package in isolation.
# Next, check all other crates.
- name: Cargo hack; check each feature/crate on its own
run: cargo hack --exclude subxt --exclude subxt-historic --exclude subxt-signer --exclude subxt-lightclient --exclude subxt-rpcs --exclude-all-features --each-feature check --workspace

Expand Down
48 changes: 33 additions & 15 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ darling = "0.20.10"
derive-where = "1.2.7"
either = { version = "1.13.0", default-features = false }
finito = { version = "0.1.0", default-features = false }
frame-decode = { version = "0.10.0", default-features = false }
frame-decode = { version = "0.15.0", default-features = false }
frame-metadata = { version = "23.0.0", default-features = false }
futures = { version = "0.3.31", default-features = false, features = ["std"] }
getrandom = { version = "0.2", default-features = false }
Expand All @@ -98,13 +98,13 @@ proc-macro2 = "1.0.86"
quote = "1.0.37"
regex = { version = "1.11.0", default-features = false }
scale-info = { version = "2.11.4", default-features = false }
scale-value = { version = "0.18.0", default-features = false }
scale-value = { version = "0.18.1", default-features = false }
scale-bits = { version = "0.7.0", default-features = false }
scale-decode = { version = "0.16.0", default-features = false }
scale-decode = { version = "0.16.2", default-features = false }
scale-encode = { version = "0.10.0", default-features = false }
scale-type-resolver = { version = "0.2.0" }
scale-info-legacy = { version = "0.2.3" }
scale-typegen = "0.11.1"
scale-info-legacy = { version = "0.4.0", default-features = false }
scale-typegen = "0.12.0"
scale-typegen-description = "0.11.0"
serde = { version = "1.0.210", default-features = false, features = ["derive"] }
serde_json = { version = "1.0.128", default-features = false }
Expand Down
Binary file added artifacts/kusama/metadata_v10_1038.scale
Binary file not shown.
Binary file added artifacts/kusama/metadata_v11_1045.scale
Binary file not shown.
Binary file added artifacts/kusama/metadata_v12_2025.scale
Binary file not shown.
Binary file added artifacts/kusama/metadata_v13_9030.scale
Binary file not shown.
Binary file added artifacts/kusama/metadata_v14_9111.scale
Binary file not shown.
Binary file added artifacts/kusama/metadata_v9_1021.scale
Binary file not shown.
4 changes: 3 additions & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ subxt-codegen = { workspace = true }
scale-typegen = { workspace = true }
subxt-utils-fetchmetadata = { workspace = true, features = ["url"] }
subxt-utils-stripmetadata = { workspace = true }
subxt-metadata = { workspace = true }
subxt-metadata = { workspace = true, features = ["legacy"] }
subxt = { workspace = true, features = ["default"] }
clap = { workspace = true }
serde = { workspace = true, features = ["derive"] }
color-eyre = { workspace = true }
serde_json = { workspace = true }
hex = { workspace = true }
frame-decode = { workspace = true, features = ["legacy-types"] }
frame-metadata = { workspace = true }
codec = { package = "parity-scale-codec", workspace = true }
scale-info = { workspace = true }
scale-info-legacy = { workspace = true }
scale-value = { workspace = true }
syn = { workspace = true }
quote = { workspace = true }
Expand Down
96 changes: 93 additions & 3 deletions cli/src/commands/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

use crate::utils::{FileOrUrl, validate_url_security};
use clap::Parser as ClapParser;
use codec::Decode;
use color_eyre::eyre::eyre;
use scale_typegen_description::scale_typegen::typegen::{
settings::substitutes::path_segments,
validation::{registry_contains_type_path, similar_type_paths_in_registry},
};
use std::path::PathBuf;
use subxt_codegen::CodegenBuilder;
use subxt_metadata::Metadata;

Expand All @@ -28,6 +28,12 @@ pub struct Opts {
/// Additional attributes
#[clap(long = "attribute")]
attributes: Vec<String>,
/// Path to legacy type definitions (required for metadatas pre-V14)
#[clap(long)]
legacy_types: Option<PathBuf>,
/// The spec version of the legacy metadata (required for metadatas pre-V14)
#[clap(long)]
legacy_spec_version: Option<u64>,
/// Additional derives for a given type.
///
/// Example 1: `--derive-for-type my_module::my_type=serde::Serialize`.
Expand Down Expand Up @@ -145,9 +151,20 @@ pub async fn run(opts: Opts, output: &mut impl std::io::Write) -> color_eyre::Re
validate_url_security(opts.file_or_url.url.as_ref(), opts.allow_insecure)?;

let bytes = opts.file_or_url.fetch().await?;
let legacy_types = opts
.legacy_types
.map(|path| {
let bytes = std::fs::read(path).map_err(|e| eyre!("Cannot read legacy_types: {e}"))?;
let types = frame_decode::legacy_types::from_bytes(&bytes)
.map_err(|e| eyre!("Cannot deserialize legacy_types: {e}"))?;
Ok::<_, color_eyre::eyre::Error>(types)
})
.transpose()?;

codegen(
&bytes,
legacy_types,
opts.legacy_spec_version,
opts.derives,
opts.attributes,
opts.derives_for_type,
Expand Down Expand Up @@ -175,6 +192,8 @@ impl syn::parse::Parse for OuterAttribute {
#[allow(clippy::too_many_arguments)]
fn codegen(
metadata_bytes: &[u8],
legacy_types: Option<scale_info_legacy::ChainTypeRegistry>,
legacy_spec_version: Option<u64>,
raw_derives: Vec<String>,
raw_attributes: Vec<String>,
derives_for_type: Vec<DeriveForType>,
Expand Down Expand Up @@ -211,8 +230,79 @@ fn codegen(
}

let metadata = {
let mut metadata = subxt_metadata::Metadata::decode(&mut &*metadata_bytes)
.map_err(|e| eyre!("Cannot decode the provided metadata: {e}"))?;
let runtime_metadata = subxt_metadata::decode_runtime_metadata(metadata_bytes)?;
let mut metadata = match runtime_metadata {
// Too old to work with:
frame_metadata::RuntimeMetadata::V0(_)
| frame_metadata::RuntimeMetadata::V1(_)
| frame_metadata::RuntimeMetadata::V2(_)
| frame_metadata::RuntimeMetadata::V3(_)
| frame_metadata::RuntimeMetadata::V4(_)
| frame_metadata::RuntimeMetadata::V5(_)
| frame_metadata::RuntimeMetadata::V6(_)
| frame_metadata::RuntimeMetadata::V7(_) => {
Err(eyre!("Metadata V1-V7 cannot be decoded from"))
}
// Converting legacy metadatas:
frame_metadata::RuntimeMetadata::V8(md) => {
let legacy_types = legacy_types
.ok_or_else(|| eyre!("--legacy-types needed to load V8 metadata"))?;
let legacy_spec = legacy_spec_version
.ok_or_else(|| eyre!("--legacy-spec-version needed to load V8 metadata"))?;
Metadata::from_v8(&md, &legacy_types.for_spec_version(legacy_spec))
.map_err(|e| eyre!("Cannot load V8 metadata: {e}"))
}
frame_metadata::RuntimeMetadata::V9(md) => {
let legacy_types = legacy_types
.ok_or_else(|| eyre!("--legacy-types needed to load V9 metadata"))?;
let legacy_spec = legacy_spec_version
.ok_or_else(|| eyre!("--legacy-spec-version needed to load V9 metadata"))?;
Metadata::from_v9(&md, &legacy_types.for_spec_version(legacy_spec))
.map_err(|e| eyre!("Cannot load V9 metadata: {e}"))
}
frame_metadata::RuntimeMetadata::V10(md) => {
let legacy_types = legacy_types
.ok_or_else(|| eyre!("--legacy-types needed to load V10 metadata"))?;
let legacy_spec = legacy_spec_version
.ok_or_else(|| eyre!("--legacy-spec-version needed to load V10 metadata"))?;
Metadata::from_v10(&md, &legacy_types.for_spec_version(legacy_spec))
.map_err(|e| eyre!("Cannot load V10 metadata: {e}"))
}
frame_metadata::RuntimeMetadata::V11(md) => {
let legacy_types = legacy_types
.ok_or_else(|| eyre!("--legacy-types needed to load V11 metadata"))?;
let legacy_spec = legacy_spec_version
.ok_or_else(|| eyre!("--legacy-spec-version needed to load V11 metadata"))?;
Metadata::from_v11(&md, &legacy_types.for_spec_version(legacy_spec))
.map_err(|e| eyre!("Cannot load V11 metadata: {e}"))
}
frame_metadata::RuntimeMetadata::V12(md) => {
let legacy_types = legacy_types
.ok_or_else(|| eyre!("--legacy-types needed to load V12 metadata"))?;
let legacy_spec = legacy_spec_version
.ok_or_else(|| eyre!("--legacy-spec-version needed to load V12 metadata"))?;
Metadata::from_v12(&md, &legacy_types.for_spec_version(legacy_spec))
.map_err(|e| eyre!("Cannot load V12 metadata: {e}"))
}
frame_metadata::RuntimeMetadata::V13(md) => {
let legacy_types = legacy_types
.ok_or_else(|| eyre!("--legacy-types needed to load V13 metadata"))?;
let legacy_spec = legacy_spec_version
.ok_or_else(|| eyre!("--legacy-spec-version needed to load V13 metadata"))?;
Metadata::from_v13(&md, &legacy_types.for_spec_version(legacy_spec))
.map_err(|e| eyre!("Cannot load V13 metadata: {e}"))
}
// Converting modern metadatas:
frame_metadata::RuntimeMetadata::V14(md) => {
Metadata::from_v14(md).map_err(|e| eyre!("Cannot load V14 metadata: {e}"))
}
frame_metadata::RuntimeMetadata::V15(md) => {
Metadata::from_v15(md).map_err(|e| eyre!("Cannot load V15 metadata: {e}"))
}
frame_metadata::RuntimeMetadata::V16(md) => {
Metadata::from_v16(md).map_err(|e| eyre!("Cannot load V16 metadata: {e}"))
}
}?;

// Run this first to ensure type paths are unique (which may result in 1,2,3 suffixes being added
// to type paths), so that when we validate derives/substitutions below, they are allowed for such
Expand Down
Loading
Loading