From 0a617eb2a96b26233cd1bb73aa25969698d828f2 Mon Sep 17 00:00:00 2001 From: James Wilson Date: Wed, 3 Dec 2025 10:41:16 +0000 Subject: [PATCH] Add metadata types to our legacy type registry too --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- new/src/client/online_client.rs | 31 ++++++++++++++++++++----------- new/src/error.rs | 15 ++++++++------- new/src/transactions.rs | 2 +- 5 files changed, 32 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3a62eefa5b..64ff8fc237 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1953,9 +1953,9 @@ dependencies = [ [[package]] name = "frame-decode" -version = "0.16.0" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cb2b069fdf47c62526c6c7a64c5edba9c3c41b4bb11dac8e4fbf8e2857859a0" +checksum = "e63257bb5f8d7a707d626aa1b4e464c3b9720edd168b73cee98f48f0dd6386e4" dependencies = [ "frame-metadata 23.0.0", "parity-scale-codec", diff --git a/Cargo.toml b/Cargo.toml index 9f9cee07e1..a1fc16a6cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -82,7 +82,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.16.0", default-features = false } +frame-decode = { version = "0.16.1", 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 } diff --git a/new/src/client/online_client.rs b/new/src/client/online_client.rs index 61e9c594af..394aa75cbc 100644 --- a/new/src/client/online_client.rs +++ b/new/src/client/online_client.rs @@ -10,6 +10,7 @@ use blocks::Blocks; use codec::{Compact, Decode, Encode}; use core::marker::PhantomData; use frame_metadata::{RuntimeMetadata, RuntimeMetadataPrefixed}; +use frame_decode::helpers::ToTypeRegistry; use scale_info_legacy::TypeRegistrySet; use std::sync::Arc; use subxt_metadata::Metadata; @@ -321,7 +322,7 @@ impl OnlineClient { }); } RuntimeMetadata::V8(m) => { - let types = get_legacy_types(self, spec_version)?; + let types = get_legacy_types(self, &m, spec_version)?; Metadata::from_v8(&m, &types).map_err(|e| { OnlineClientAtBlockError::CannotConvertLegacyMetadata { block_hash: block_hash.into(), @@ -331,7 +332,7 @@ impl OnlineClient { })? } RuntimeMetadata::V9(m) => { - let types = get_legacy_types(self, spec_version)?; + let types = get_legacy_types(self, &m, spec_version)?; Metadata::from_v9(&m, &types).map_err(|e| { OnlineClientAtBlockError::CannotConvertLegacyMetadata { block_hash: block_hash.into(), @@ -341,7 +342,7 @@ impl OnlineClient { })? } RuntimeMetadata::V10(m) => { - let types = get_legacy_types(self, spec_version)?; + let types = get_legacy_types(self, &m, spec_version)?; Metadata::from_v10(&m, &types).map_err(|e| { OnlineClientAtBlockError::CannotConvertLegacyMetadata { block_hash: block_hash.into(), @@ -351,7 +352,7 @@ impl OnlineClient { })? } RuntimeMetadata::V11(m) => { - let types = get_legacy_types(self, spec_version)?; + let types = get_legacy_types(self, &m, spec_version)?; Metadata::from_v11(&m, &types).map_err(|e| { OnlineClientAtBlockError::CannotConvertLegacyMetadata { block_hash: block_hash.into(), @@ -361,7 +362,7 @@ impl OnlineClient { })? } RuntimeMetadata::V12(m) => { - let types = get_legacy_types(self, spec_version)?; + let types = get_legacy_types(self, &m, spec_version)?; Metadata::from_v12(&m, &types).map_err(|e| { OnlineClientAtBlockError::CannotConvertLegacyMetadata { block_hash: block_hash.into(), @@ -371,7 +372,7 @@ impl OnlineClient { })? } RuntimeMetadata::V13(m) => { - let types = get_legacy_types(self, spec_version)?; + let types = get_legacy_types(self, &m, spec_version)?; Metadata::from_v13(&m, &types).map_err(|e| { OnlineClientAtBlockError::CannotConvertLegacyMetadata { block_hash: block_hash.into(), @@ -485,15 +486,23 @@ impl OfflineClientAtBlockT for OnlineClientAtBlock { } } -fn get_legacy_types( - client: &OnlineClient, +fn get_legacy_types<'a, T: Config, Md: ToTypeRegistry>( + client: &'a OnlineClient, + metadata: &Md, spec_version: u32, -) -> Result, OnlineClientAtBlockError> { - client +) -> Result, OnlineClientAtBlockError> { + let mut types = client .inner .config .legacy_types_for_spec_version(spec_version) - .ok_or(OnlineClientAtBlockError::MissingLegacyTypes) + .ok_or(OnlineClientAtBlockError::MissingLegacyTypes)?; + + // Extend the types with information from the metadata (ie event/error/call enums): + let additional_types = frame_decode::helpers::type_registry_from_metadata(metadata) + .map_err(|e| OnlineClientAtBlockError::CannotInjectMetadataTypes { parse_error: e })?; + types.prepend(additional_types); + + Ok(types) } async fn get_metadata( diff --git a/new/src/error.rs b/new/src/error.rs index 422f37e5f4..df3d273d20 100644 --- a/new/src/error.rs +++ b/new/src/error.rs @@ -362,13 +362,14 @@ pub enum OnlineClientAtBlockError { metadata_version: u32, /// Reason the conversion failed. reason: subxt_metadata::TryFromError, - }, // #[error( - // "Cannot construct OnlineClientAtBlock: cannot inject types from metadata: failure to parse a type found in the metadata: {parse_error}" - // )] - // CannotInjectMetadataTypes { - // /// Error parsing a type found in the metadata. - // parse_error: scale_info_legacy::lookup_name::ParseError, - // }, + }, + #[error( + "Cannot construct OnlineClientAtBlock: cannot inject types from metadata: failure to parse a type found in the metadata: {parse_error}" + )] + CannotInjectMetadataTypes { + /// Error parsing a type found in the metadata. + parse_error: scale_info_legacy::lookup_name::ParseError, + }, } impl OnlineClientAtBlockError { diff --git a/new/src/transactions.rs b/new/src/transactions.rs index 8c9fd53dae..dd5aa9c3cd 100644 --- a/new/src/transactions.rs +++ b/new/src/transactions.rs @@ -129,7 +129,7 @@ impl<'atblock, T: Config, C: OfflineClientAtBlockT> Transactions<'atblock, T, metadata: self.client.metadata(), }; - let tx = match self.default_transaction_version(&metadata)? { + let tx = match self.default_transaction_version()? { TransactionVersion::V4 => { PartialTransactionInner::V4(self.create_v4_signed(call, &client_state, params)?) }