mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 12:11:02 +00:00
Add metadata types to our legacy type registry too
This commit is contained in:
Generated
+2
-2
@@ -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",
|
||||
|
||||
+1
-1
@@ -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 }
|
||||
|
||||
@@ -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<T: Config> OnlineClient<T> {
|
||||
});
|
||||
}
|
||||
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<T: Config> OnlineClient<T> {
|
||||
})?
|
||||
}
|
||||
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<T: Config> OnlineClient<T> {
|
||||
})?
|
||||
}
|
||||
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<T: Config> OnlineClient<T> {
|
||||
})?
|
||||
}
|
||||
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<T: Config> OnlineClient<T> {
|
||||
})?
|
||||
}
|
||||
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<T: Config> OnlineClient<T> {
|
||||
})?
|
||||
}
|
||||
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<T: Config> OfflineClientAtBlockT<T> for OnlineClientAtBlock<T> {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_legacy_types<T: Config>(
|
||||
client: &OnlineClient<T>,
|
||||
fn get_legacy_types<'a, T: Config, Md: ToTypeRegistry>(
|
||||
client: &'a OnlineClient<T>,
|
||||
metadata: &Md,
|
||||
spec_version: u32,
|
||||
) -> Result<TypeRegistrySet<'_>, OnlineClientAtBlockError> {
|
||||
client
|
||||
) -> Result<TypeRegistrySet<'a>, 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<T: Config>(
|
||||
|
||||
+8
-7
@@ -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 {
|
||||
|
||||
@@ -129,7 +129,7 @@ impl<'atblock, T: Config, C: OfflineClientAtBlockT<T>> 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)?)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user