diff --git a/Cargo.toml b/Cargo.toml index cf2eda7e78..14160571fc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,9 +71,9 @@ frame-metadata = { version = "16.0.0", default-features = false } futures = { version = "0.3.30", default-features = false, features = ["std"] } getrandom = { version = "0.2", default-features = false } hashbrown = "0.14.3" -hex = "0.4.3" +hex = { version = "0.4.3", default-features = false } heck = "0.4.1" -impl-serde = { version = "0.4.0" } +impl-serde = { version = "0.4.0", default-features = false } indoc = "2" jsonrpsee = { version = "0.21" } pretty_assertions = "1.4.0" @@ -87,8 +87,8 @@ scale-value = { version = "0.13.0", default-features = false } scale-bits = { version = "0.4.0", default-features = false } scale-decode = { version = "0.10.0", default-features = false } scale-encode = { version = "0.5.0", default-features = false } -serde = { version = "1.0.196" } -serde_json = { version = "1.0.113" } +serde = { version = "1.0.196", default-features = false, features = ["derive"] } +serde_json = { version = "1.0.113", default-features = false } syn = { version = "2.0.15", features = ["full", "extra-traits"] } thiserror = "1.0.53" tokio = { version = "1.35", default-features = false } diff --git a/core/Cargo.toml b/core/Cargo.toml index a184871dec..1121a682cc 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -31,16 +31,16 @@ frame-metadata = { workspace = true, default-features = false } subxt-metadata = { workspace = true, default-features = false } derivative = { workspace = true, features = ["use_core"] } derive_more = { workspace = true } -hex = { workspace = true } -serde = { workspace = true, features = ["derive"] } -serde_json = { workspace = true, features = ["raw_value"] } +hex = { workspace = true, default-features = false, features = ["alloc"] } +serde = { workspace = true, default-features = false, features = ["derive"] } +serde_json = { workspace = true, default-features = false, features = ["raw_value", "alloc"] } # For ss58 encoding AccountId32 to serialize them properly: base58 = { workspace = true } blake2 = { workspace = true } # Provides some deserialization, types like U256/H256 and hashing impls like twox/blake256: -impl-serde = { workspace = true } +impl-serde = { workspace = true, default-features = false } primitive-types = { workspace = true, default-features = false, features = ["codec", "serde_no_std", "scale-info"] } sp-core-hashing = { workspace = true } diff --git a/core/src/dynamic.rs b/core/src/dynamic.rs index e0260b1920..160864331d 100644 --- a/core/src/dynamic.rs +++ b/core/src/dynamic.rs @@ -1,20 +1,21 @@ -// // Copyright 2019-2023 Parity Technologies (UK) Ltd. -// // This file is dual-licensed as Apache-2.0 or GPL-3.0. -// // see LICENSE for license details. +// Copyright 2019-2023 Parity Technologies (UK) Ltd. +// This file is dual-licensed as Apache-2.0 or GPL-3.0. +// see LICENSE for license details. -// //! This module provides the entry points to create dynamic -// //! transactions, storage and constant lookups. +//! This module provides the entry points to create dynamic +//! transactions, storage and constant lookups. -// use crate::metadata::{DecodeWithMetadata, Metadata}; -// use scale_decode::DecodeAsType; +use crate::metadata::{DecodeWithMetadata, Metadata}; +use crate::prelude::*; +use scale_decode::DecodeAsType; +pub use scale_value::{At, Value}; +use vec::Vec; -// pub use scale_value::{At, Value}; - -// /// A [`scale_value::Value`] type endowed with contextual information -// /// regarding what type was used to decode each part of it. This implements -// /// [`crate::metadata::DecodeWithMetadata`], and is used as a return type -// /// for dynamic requests. -// pub type DecodedValue = scale_value::Value; +/// A [`scale_value::Value`] type endowed with contextual information +/// regarding what type was used to decode each part of it. This implements +/// [`subxt_core::metadata::DecodeWithMetadata`], and is used as a return type +/// for dynamic requests. +pub type DecodedValue = scale_value::Value; // // Submit dynamic transactions. // pub use crate::tx::dynamic as tx; @@ -28,56 +29,56 @@ // // Execute runtime API function call dynamically. // pub use crate::runtime_api::dynamic as runtime_api_call; -// /// This is the result of making a dynamic request to a node. From this, -// /// we can return the raw SCALE bytes that we were handed back, or we can -// /// complete the decoding of the bytes into a [`DecodedValue`] type. -// pub struct DecodedValueThunk { -// type_id: u32, -// metadata: Metadata, -// scale_bytes: Vec, -// } +/// This is the result of making a dynamic request to a node. From this, +/// we can return the raw SCALE bytes that we were handed back, or we can +/// complete the decoding of the bytes into a [`DecodedValue`] type. +pub struct DecodedValueThunk { + type_id: u32, + metadata: Metadata, + scale_bytes: Vec, +} -// impl DecodeWithMetadata for DecodedValueThunk { -// fn decode_with_metadata( -// bytes: &mut &[u8], -// type_id: u32, -// metadata: &Metadata, -// ) -> Result { -// let mut v = Vec::with_capacity(bytes.len()); -// v.extend_from_slice(bytes); -// *bytes = &[]; -// Ok(DecodedValueThunk { -// type_id, -// metadata: metadata.clone(), -// scale_bytes: v, -// }) -// } -// } +impl DecodeWithMetadata for DecodedValueThunk { + fn decode_with_metadata( + bytes: &mut &[u8], + type_id: u32, + metadata: &Metadata, + ) -> Result { + let mut v = Vec::with_capacity(bytes.len()); + v.extend_from_slice(bytes); + *bytes = &[]; + Ok(DecodedValueThunk { + type_id, + metadata: metadata.clone(), + scale_bytes: v, + }) + } +} -// impl DecodedValueThunk { -// /// Return the SCALE encoded bytes handed back from the node. -// pub fn into_encoded(self) -> Vec { -// self.scale_bytes -// } -// /// Return the SCALE encoded bytes handed back from the node without taking ownership of them. -// pub fn encoded(&self) -> &[u8] { -// &self.scale_bytes -// } -// /// Decode the SCALE encoded storage entry into a dynamic [`DecodedValue`] type. -// pub fn to_value(&self) -> Result { -// let val = DecodedValue::decode_as_type( -// &mut &*self.scale_bytes, -// self.type_id, -// self.metadata.types(), -// )?; -// Ok(val) -// } -// /// decode the `DecodedValueThunk` into a concrete type. -// pub fn as_type(&self) -> Result { -// T::decode_as_type( -// &mut &self.scale_bytes[..], -// self.type_id, -// self.metadata.types(), -// ) -// } -// } +impl DecodedValueThunk { + /// Return the SCALE encoded bytes handed back from the node. + pub fn into_encoded(self) -> Vec { + self.scale_bytes + } + /// Return the SCALE encoded bytes handed back from the node without taking ownership of them. + pub fn encoded(&self) -> &[u8] { + &self.scale_bytes + } + /// Decode the SCALE encoded storage entry into a dynamic [`DecodedValue`] type. + pub fn to_value(&self) -> Result { + let val = DecodedValue::decode_as_type( + &mut &*self.scale_bytes, + self.type_id, + self.metadata.types(), + )?; + Ok(val) + } + /// decode the `DecodedValueThunk` into a concrete type. + pub fn as_type(&self) -> Result { + T::decode_as_type( + &mut &self.scale_bytes[..], + self.type_id, + self.metadata.types(), + ) + } +} diff --git a/core/src/lib.rs b/core/src/lib.rs index fe618ae167..910e4204c7 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -21,5 +21,7 @@ pub use config::{ PolkadotExtrinsicParams, SubstrateConfig, SubstrateExtrinsicParams, }; +pub use metadata::Metadata; + #[macro_use] mod macros; diff --git a/core/src/metadata/metadata_type.rs b/core/src/metadata/metadata_type.rs index 24b052c2ad..18e4d8843d 100644 --- a/core/src/metadata/metadata_type.rs +++ b/core/src/metadata/metadata_type.rs @@ -22,7 +22,7 @@ impl core::ops::Deref for Metadata { } impl Metadata { - pub(crate) fn new(md: subxt_metadata::Metadata) -> Self { + pub fn new(md: subxt_metadata::Metadata) -> Self { Metadata { inner: Arc::new(md), } @@ -125,3 +125,6 @@ pub enum MetadataError { #[display(fmt = "Custom value with name {_0} not found")] CustomValueNameNotFound(String), } + +#[cfg(feature = "std")] +impl std::error::Error for MetadataError {} diff --git a/core/src/metadata/mod.rs b/core/src/metadata/mod.rs index a6ef00ae6f..0ba35ec5ec 100644 --- a/core/src/metadata/mod.rs +++ b/core/src/metadata/mod.rs @@ -8,7 +8,7 @@ mod decode_encode_traits; mod metadata_type; pub use decode_encode_traits::{DecodeWithMetadata, EncodeWithMetadata}; -pub use metadata_type::Metadata; +pub use metadata_type::{Metadata, MetadataError}; // Expose metadata types under a sub module in case somebody needs to reference them: pub use subxt_metadata as types; diff --git a/subxt/src/backend/legacy/rpc_methods.rs b/subxt/src/backend/legacy/rpc_methods.rs index 4dde85ee98..84a8200adb 100644 --- a/subxt/src/backend/legacy/rpc_methods.rs +++ b/subxt/src/backend/legacy/rpc_methods.rs @@ -5,12 +5,12 @@ //! An interface to call the raw legacy RPC methods. use crate::backend::rpc::{rpc_params, RpcClient, RpcSubscription}; -use crate::metadata::Metadata; use crate::{Config, Error}; use codec::Decode; use derivative::Derivative; use primitive_types::U256; use serde::{Deserialize, Serialize}; +use subxt_core::metadata::Metadata; /// An interface to call the legacy RPC methods. This interface is instantiated with /// some `T: Config` trait which determines some of the types that the RPC methods will @@ -530,7 +530,7 @@ impl DryRunResultBytes { /// Attempt to decode the error bytes into a [`DryRunResult`] using the provided [`Metadata`]. pub fn into_dry_run_result( self, - metadata: &crate::metadata::Metadata, + metadata: &subxt_core::metadata::Metadata, ) -> Result { // dryRun returns an ApplyExtrinsicResult, which is basically a // `Result, TransactionValidityError>`. diff --git a/subxt/src/backend/mod.rs b/subxt/src/backend/mod.rs index 3db06818b3..4bbd9f6159 100644 --- a/subxt/src/backend/mod.rs +++ b/subxt/src/backend/mod.rs @@ -11,13 +11,13 @@ pub mod rpc; pub mod unstable; use crate::error::Error; -use crate::metadata::Metadata; use crate::Config; use async_trait::async_trait; use codec::{Decode, Encode}; use futures::{Stream, StreamExt}; use std::pin::Pin; use std::sync::Arc; +use subxt_core::metadata::Metadata; /// Prevent the backend trait being implemented externally. #[doc(hidden)] diff --git a/subxt/src/blocks/extrinsic_types.rs b/subxt/src/blocks/extrinsic_types.rs index 333ee5bfe8..d7575123aa 100644 --- a/subxt/src/blocks/extrinsic_types.rs +++ b/subxt/src/blocks/extrinsic_types.rs @@ -7,11 +7,11 @@ use crate::{ client::{OfflineClientT, OnlineClientT}, config::{Config, Hasher}, error::{BlockError, Error, MetadataError}, - events, - metadata::types::PalletMetadata, - Metadata, + events, Metadata, }; +use subxt_core::metadata::types::PalletMetadata; + use crate::config::signed_extensions::{ ChargeAssetTxPayment, ChargeTransactionPayment, CheckNonce, }; diff --git a/subxt/src/client/light_client/mod.rs b/subxt/src/client/light_client/mod.rs index a4b116652e..cc8c022976 100644 --- a/subxt/src/client/light_client/mod.rs +++ b/subxt/src/client/light_client/mod.rs @@ -117,8 +117,8 @@ impl LightClient { // think about importing the OnlineClientT/OfflineClientT // traits to use these things: - /// Return the [`crate::Metadata`] used in this client. - fn metadata(&self) -> crate::Metadata { + /// Return the [`subxt_core::metadata`] used in this client. + fn metadata(&self) -> subxt_core::metadata { self.client.metadata() } @@ -180,7 +180,7 @@ impl OnlineClientT for LightClient { } impl OfflineClientT for LightClient { - fn metadata(&self) -> crate::Metadata { + fn metadata(&self) -> subxt_core::metadata { self.metadata() } diff --git a/subxt/src/constants/constant_address.rs b/subxt/src/constants/constant_address.rs index e9a0eb37b0..bac9677ccf 100644 --- a/subxt/src/constants/constant_address.rs +++ b/subxt/src/constants/constant_address.rs @@ -2,9 +2,10 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::{dynamic::DecodedValueThunk, metadata::DecodeWithMetadata}; +use crate::dynamic::DecodedValueThunk; use derivative::Derivative; use std::borrow::Cow; +use subxt_core::metadata::DecodeWithMetadata; /// This represents a constant address. Anything implementing this trait /// can be used to fetch constants. diff --git a/subxt/src/constants/constants_client.rs b/subxt/src/constants/constants_client.rs index de688bba6b..1190811ac7 100644 --- a/subxt/src/constants/constants_client.rs +++ b/subxt/src/constants/constants_client.rs @@ -6,10 +6,11 @@ use super::ConstantAddress; use crate::{ client::OfflineClientT, error::{Error, MetadataError}, - metadata::DecodeWithMetadata, Config, }; + use derivative::Derivative; +use subxt_core::metadata::DecodeWithMetadata; /// A client for accessing constants. #[derive(Derivative)] diff --git a/subxt/src/custom_values/custom_value_address.rs b/subxt/src/custom_values/custom_value_address.rs index f8034a161b..d1708eec46 100644 --- a/subxt/src/custom_values/custom_value_address.rs +++ b/subxt/src/custom_values/custom_value_address.rs @@ -2,7 +2,7 @@ use derivative::Derivative; use std::marker::PhantomData; use crate::dynamic::DecodedValueThunk; -use crate::metadata::DecodeWithMetadata; +use subxt_core::metadata::DecodeWithMetadata; /// This represents the address of a custom value in in the metadata. /// Anything, that implements the [CustomValueAddress] trait can be used, to fetch diff --git a/subxt/src/custom_values/custom_values_client.rs b/subxt/src/custom_values/custom_values_client.rs index 3b8c1f54c2..b45dd39ce8 100644 --- a/subxt/src/custom_values/custom_values_client.rs +++ b/subxt/src/custom_values/custom_values_client.rs @@ -1,9 +1,9 @@ use crate::client::OfflineClientT; use crate::custom_values::custom_value_address::{CustomValueAddress, Yes}; use crate::error::MetadataError; -use crate::metadata::DecodeWithMetadata; use crate::{Config, Error}; use derivative::Derivative; +use subxt_core::metadata::DecodeWithMetadata; /// A client for accessing custom values stored in the metadata. #[derive(Derivative)] diff --git a/subxt/src/dynamic.rs b/subxt/src/dynamic.rs index 2801feb683..771815825a 100644 --- a/subxt/src/dynamic.rs +++ b/subxt/src/dynamic.rs @@ -5,17 +5,16 @@ //! This module provides the entry points to create dynamic //! transactions, storage and constant lookups. -use crate::{ - error::Error, - metadata::{DecodeWithMetadata, Metadata}, -}; +use crate::error::Error; + use scale_decode::DecodeAsType; +use subxt_core::metadata::{DecodeWithMetadata, Metadata}; pub use scale_value::{At, Value}; /// A [`scale_value::Value`] type endowed with contextual information /// regarding what type was used to decode each part of it. This implements -/// [`crate::metadata::DecodeWithMetadata`], and is used as a return type +/// [`subxt_core::metadata::DecodeWithMetadata`], and is used as a return type /// for dynamic requests. pub type DecodedValue = scale_value::Value; @@ -30,57 +29,3 @@ pub use crate::storage::dynamic as storage; // Execute runtime API function call dynamically. pub use crate::runtime_api::dynamic as runtime_api_call; - -/// This is the result of making a dynamic request to a node. From this, -/// we can return the raw SCALE bytes that we were handed back, or we can -/// complete the decoding of the bytes into a [`DecodedValue`] type. -pub struct DecodedValueThunk { - type_id: u32, - metadata: Metadata, - scale_bytes: Vec, -} - -impl DecodeWithMetadata for DecodedValueThunk { - fn decode_with_metadata( - bytes: &mut &[u8], - type_id: u32, - metadata: &Metadata, - ) -> Result { - let mut v = Vec::with_capacity(bytes.len()); - v.extend_from_slice(bytes); - *bytes = &[]; - Ok(DecodedValueThunk { - type_id, - metadata: metadata.clone(), - scale_bytes: v, - }) - } -} - -impl DecodedValueThunk { - /// Return the SCALE encoded bytes handed back from the node. - pub fn into_encoded(self) -> Vec { - self.scale_bytes - } - /// Return the SCALE encoded bytes handed back from the node without taking ownership of them. - pub fn encoded(&self) -> &[u8] { - &self.scale_bytes - } - /// Decode the SCALE encoded storage entry into a dynamic [`DecodedValue`] type. - pub fn to_value(&self) -> Result { - let val = DecodedValue::decode_as_type( - &mut &*self.scale_bytes, - self.type_id, - self.metadata.types(), - )?; - Ok(val) - } - /// decode the `DecodedValueThunk` into a concrete type. - pub fn as_type(&self) -> Result { - T::decode_as_type( - &mut &self.scale_bytes[..], - self.type_id, - self.metadata.types(), - ) - } -} diff --git a/subxt/src/error/dispatch_error.rs b/subxt/src/error/dispatch_error.rs index 817a441dd6..2dd59da35b 100644 --- a/subxt/src/error/dispatch_error.rs +++ b/subxt/src/error/dispatch_error.rs @@ -5,10 +5,10 @@ //! A representation of the dispatch error; an error returned when //! something fails in trying to submit/execute a transaction. -use crate::metadata::{DecodeWithMetadata, Metadata}; use core::fmt::Debug; use scale_decode::{visitor::DecodeAsTypeResult, DecodeAsType}; use std::borrow::Cow; +use subxt_core::metadata::{DecodeWithMetadata, Metadata}; use super::{Error, MetadataError}; @@ -214,7 +214,7 @@ impl ModuleError { /// Details about the module error. pub struct ModuleErrorDetails<'a> { /// The pallet that the error is in - pub pallet: crate::metadata::types::PalletMetadata<'a>, + pub pallet: subxt_core::metadata::types::PalletMetadata<'a>, /// The variant representing the error pub variant: &'a scale_info::Variant, } diff --git a/subxt/src/error/mod.rs b/subxt/src/error/mod.rs index 78c5528012..062734dac2 100644 --- a/subxt/src/error/mod.rs +++ b/subxt/src/error/mod.rs @@ -17,11 +17,13 @@ pub use dispatch_error::{ ArithmeticError, DispatchError, ModuleError, TokenError, TransactionalError, }; +pub use subxt_core::metadata::MetadataError; + // Re-expose the errors we use from other crates here: pub use crate::config::ExtrinsicParamsError; -pub use crate::metadata::Metadata; pub use scale_decode::Error as DecodeError; pub use scale_encode::Error as EncodeError; +pub use subxt_core::metadata::Metadata; pub use subxt_metadata::TryFromError as MetadataTryFromError; /// The underlying error enum, generic over the type held by the `Runtime` @@ -199,54 +201,3 @@ pub enum StorageAddressError { fields: usize, }, } - -/// Something went wrong trying to access details in the metadata. -#[derive(Clone, Debug, PartialEq, thiserror::Error)] -#[non_exhaustive] -pub enum MetadataError { - /// The DispatchError type isn't available in the metadata - #[error("The DispatchError type isn't available")] - DispatchErrorNotFound, - /// Type not found in metadata. - #[error("Type with ID {0} not found")] - TypeNotFound(u32), - /// Pallet not found (index). - #[error("Pallet with index {0} not found")] - PalletIndexNotFound(u8), - /// Pallet not found (name). - #[error("Pallet with name {0} not found")] - PalletNameNotFound(String), - /// Variant not found. - #[error("Variant with index {0} not found")] - VariantIndexNotFound(u8), - /// Constant not found. - #[error("Constant with name {0} not found")] - ConstantNameNotFound(String), - /// Call not found. - #[error("Call with name {0} not found")] - CallNameNotFound(String), - /// Runtime trait not found. - #[error("Runtime trait with name {0} not found")] - RuntimeTraitNotFound(String), - /// Runtime method not found. - #[error("Runtime method with name {0} not found")] - RuntimeMethodNotFound(String), - /// Call type not found in metadata. - #[error("Call type not found in pallet with index {0}")] - CallTypeNotFoundInPallet(u8), - /// Event type not found in metadata. - #[error("Event type not found in pallet with index {0}")] - EventTypeNotFoundInPallet(u8), - /// Storage details not found in metadata. - #[error("Storage details not found in pallet with name {0}")] - StorageNotFoundInPallet(String), - /// Storage entry not found. - #[error("Storage entry {0} not found")] - StorageEntryNotFound(String), - /// The generated interface used is not compatible with the node. - #[error("The generated code is not compatible with the node")] - IncompatibleCodegen, - /// Custom value not found. - #[error("Custom value with name {0} not found")] - CustomValueNameNotFound(String), -} diff --git a/subxt/src/events/events_type.rs b/subxt/src/events/events_type.rs index 831268ad00..079ce5f208 100644 --- a/subxt/src/events/events_type.rs +++ b/subxt/src/events/events_type.rs @@ -9,13 +9,13 @@ use crate::{ client::OnlineClientT, error::{Error, MetadataError}, events::events_client::get_event_bytes, - metadata::types::PalletMetadata, Config, Metadata, }; use codec::{Compact, Decode}; use derivative::Derivative; use scale_decode::DecodeAsType; use std::sync::Arc; +use subxt_core::metadata::types::PalletMetadata; /// A collection of events obtained from a block, bundled with the necessary /// information needed to decode and iterate over them. diff --git a/subxt/src/lib.rs b/subxt/src/lib.rs index b50880e1ea..e982f2b138 100644 --- a/subxt/src/lib.rs +++ b/subxt/src/lib.rs @@ -51,7 +51,6 @@ pub mod custom_values; pub mod dynamic; pub mod error; pub mod events; -pub mod metadata; pub mod runtime_api; pub mod storage; pub mod tx; @@ -67,9 +66,10 @@ pub use crate::{ client::{OfflineClient, OnlineClient}, config::{Config, PolkadotConfig, SubstrateConfig}, error::Error, - metadata::Metadata, }; +use subxt_core::metadata::Metadata; + /// Re-export external crates that are made use of in the subxt API. pub mod ext { pub use codec; diff --git a/subxt/src/metadata/decode_encode_traits.rs b/subxt/src/metadata/decode_encode_traits.rs deleted file mode 100644 index 81dbaea131..0000000000 --- a/subxt/src/metadata/decode_encode_traits.rs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2019-2023 Parity Technologies (UK) Ltd. -// This file is dual-licensed as Apache-2.0 or GPL-3.0. -// see LICENSE for license details. - -use super::Metadata; -use crate::error::Error; - -/// This trait is implemented for all types that also implement [`scale_decode::DecodeAsType`]. -pub trait DecodeWithMetadata: Sized { - /// Given some metadata and a type ID, attempt to SCALE decode the provided bytes into `Self`. - fn decode_with_metadata( - bytes: &mut &[u8], - type_id: u32, - metadata: &Metadata, - ) -> Result; -} - -impl DecodeWithMetadata for T { - fn decode_with_metadata( - bytes: &mut &[u8], - type_id: u32, - metadata: &Metadata, - ) -> Result { - let val = T::decode_as_type(bytes, type_id, metadata.types())?; - Ok(val) - } -} - -/// This trait is implemented for all types that also implement [`scale_encode::EncodeAsType`]. -pub trait EncodeWithMetadata { - /// SCALE encode this type to bytes, possibly with the help of metadata. - fn encode_with_metadata( - &self, - type_id: u32, - metadata: &Metadata, - bytes: &mut Vec, - ) -> Result<(), Error>; -} - -impl EncodeWithMetadata for T { - /// SCALE encode this type to bytes, possibly with the help of metadata. - fn encode_with_metadata( - &self, - type_id: u32, - metadata: &Metadata, - bytes: &mut Vec, - ) -> Result<(), Error> { - self.encode_as_type_to(type_id, metadata.types(), bytes)?; - Ok(()) - } -} diff --git a/subxt/src/metadata/metadata_type.rs b/subxt/src/metadata/metadata_type.rs deleted file mode 100644 index 29ae567afa..0000000000 --- a/subxt/src/metadata/metadata_type.rs +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2019-2023 Parity Technologies (UK) Ltd. -// This file is dual-licensed as Apache-2.0 or GPL-3.0. -// see LICENSE for license details. - -use crate::error::MetadataError; - -use std::sync::Arc; - -/// A cheaply clone-able representation of the runtime metadata received from a node. -#[derive(Clone, Debug)] -pub struct Metadata { - inner: Arc, -} - -impl std::ops::Deref for Metadata { - type Target = subxt_metadata::Metadata; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl Metadata { - pub(crate) fn new(md: subxt_metadata::Metadata) -> Self { - Metadata { - inner: Arc::new(md), - } - } - - /// Identical to `metadata.pallet_by_name()`, but returns an error if the pallet is not found. - pub fn pallet_by_name_err( - &self, - name: &str, - ) -> Result { - self.pallet_by_name(name) - .ok_or_else(|| MetadataError::PalletNameNotFound(name.to_owned())) - } - - /// Identical to `metadata.pallet_by_index()`, but returns an error if the pallet is not found. - pub fn pallet_by_index_err( - &self, - index: u8, - ) -> Result { - self.pallet_by_index(index) - .ok_or(MetadataError::PalletIndexNotFound(index)) - } - - /// Identical to `metadata.runtime_api_trait_by_name()`, but returns an error if the trait is not found. - pub fn runtime_api_trait_by_name_err( - &self, - name: &str, - ) -> Result { - self.runtime_api_trait_by_name(name) - .ok_or_else(|| MetadataError::RuntimeTraitNotFound(name.to_owned())) - } -} - -impl From for Metadata { - fn from(md: subxt_metadata::Metadata) -> Self { - Metadata::new(md) - } -} - -impl TryFrom for Metadata { - type Error = subxt_metadata::TryFromError; - fn try_from(value: frame_metadata::RuntimeMetadataPrefixed) -> Result { - subxt_metadata::Metadata::try_from(value).map(Metadata::from) - } -} - -impl codec::Decode for Metadata { - fn decode(input: &mut I) -> Result { - subxt_metadata::Metadata::decode(input).map(Metadata::new) - } -} diff --git a/subxt/src/metadata/mod.rs b/subxt/src/metadata/mod.rs deleted file mode 100644 index a6ef00ae6f..0000000000 --- a/subxt/src/metadata/mod.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2019-2023 Parity Technologies (UK) Ltd. -// This file is dual-licensed as Apache-2.0 or GPL-3.0. -// see LICENSE for license details. - -//! Types representing the metadata obtained from a node. - -mod decode_encode_traits; -mod metadata_type; - -pub use decode_encode_traits::{DecodeWithMetadata, EncodeWithMetadata}; -pub use metadata_type::Metadata; - -// Expose metadata types under a sub module in case somebody needs to reference them: -pub use subxt_metadata as types; diff --git a/subxt/src/runtime_api/runtime_payload.rs b/subxt/src/runtime_api/runtime_payload.rs index cd5a3355b8..3725fcae22 100644 --- a/subxt/src/runtime_api/runtime_payload.rs +++ b/subxt/src/runtime_api/runtime_payload.rs @@ -10,7 +10,9 @@ use std::borrow::Cow; use crate::dynamic::DecodedValueThunk; use crate::error::MetadataError; -use crate::{metadata::DecodeWithMetadata, Error, Metadata}; +use crate::Error; + +use subxt_core::metadata::{DecodeWithMetadata, Metadata}; /// This represents a runtime API payload that can call into the runtime of node. /// diff --git a/subxt/src/runtime_api/runtime_types.rs b/subxt/src/runtime_api/runtime_types.rs index 3ea8c93947..f9247547db 100644 --- a/subxt/src/runtime_api/runtime_types.rs +++ b/subxt/src/runtime_api/runtime_types.rs @@ -6,12 +6,12 @@ use crate::{ backend::{BackendExt, BlockRef}, client::OnlineClientT, error::{Error, MetadataError}, - metadata::DecodeWithMetadata, Config, }; use codec::Decode; use derivative::Derivative; use std::{future::Future, marker::PhantomData}; +use subxt_core::metadata::DecodeWithMetadata; use super::RuntimeApiPayload; diff --git a/subxt/src/storage/storage_address.rs b/subxt/src/storage/storage_address.rs index 893474b518..e1a3ef504f 100644 --- a/subxt/src/storage/storage_address.rs +++ b/subxt/src/storage/storage_address.rs @@ -5,9 +5,11 @@ use crate::{ dynamic::DecodedValueThunk, error::{Error, MetadataError, StorageAddressError}, - metadata::{DecodeWithMetadata, EncodeWithMetadata, Metadata}, utils::{Encoded, Static}, }; + +use subxt_core::metadata::{DecodeWithMetadata, EncodeWithMetadata, Metadata}; + use derivative::Derivative; use scale_info::TypeDef; use std::borrow::Cow; diff --git a/subxt/src/storage/storage_type.rs b/subxt/src/storage/storage_type.rs index 2669c1abce..26b7c60ccf 100644 --- a/subxt/src/storage/storage_type.rs +++ b/subxt/src/storage/storage_type.rs @@ -8,13 +8,13 @@ use crate::{ backend::{BackendExt, BlockRef}, client::OnlineClientT, error::{Error, MetadataError}, - metadata::{DecodeWithMetadata, Metadata}, Config, }; use codec::Decode; use derivative::Derivative; use futures::StreamExt; use std::{future::Future, marker::PhantomData}; +use subxt_core::metadata::{DecodeWithMetadata, Metadata}; use subxt_metadata::{PalletMetadata, StorageEntryMetadata, StorageEntryType}; /// This is returned from a couple of storage functions. diff --git a/subxt/src/storage/utils.rs b/subxt/src/storage/utils.rs index 728a581baf..33581a3261 100644 --- a/subxt/src/storage/utils.rs +++ b/subxt/src/storage/utils.rs @@ -7,7 +7,9 @@ //! the trait itself. use super::StorageAddress; -use crate::{error::Error, metadata::Metadata}; +use crate::error::Error; + +use subxt_core::metadata::Metadata; /// Return the root of a given [`StorageAddress`]: hash the pallet name and entry name /// and append those bytes to the output. diff --git a/subxt/src/tx/tx_payload.rs b/subxt/src/tx/tx_payload.rs index 508a6a99e6..1a7cdeb941 100644 --- a/subxt/src/tx/tx_payload.rs +++ b/subxt/src/tx/tx_payload.rs @@ -8,12 +8,12 @@ use crate::{ dynamic::Value, error::{Error, MetadataError}, - metadata::Metadata, }; use codec::Encode; use scale_encode::EncodeAsFields; use scale_value::{Composite, ValueDef, Variant}; use std::{borrow::Cow, sync::Arc}; +use subxt_core::metadata::Metadata; /// This represents a transaction payload that can be submitted /// to a node. diff --git a/subxt/src/tx/tx_progress.rs b/subxt/src/tx/tx_progress.rs index b949de2be4..732c738752 100644 --- a/subxt/src/tx/tx_progress.rs +++ b/subxt/src/tx/tx_progress.rs @@ -337,7 +337,7 @@ mod test { struct MockClient; impl OfflineClientT for MockClient { - fn metadata(&self) -> crate::Metadata { + fn metadata(&self) -> subxt_core::metadata { unimplemented!("just a mock impl to satisfy trait bounds") } diff --git a/testing/no-std-tests/src/main.rs b/testing/no-std-tests/src/main.rs index 65f425028f..72d4f35152 100644 --- a/testing/no-std-tests/src/main.rs +++ b/testing/no-std-tests/src/main.rs @@ -49,5 +49,5 @@ fn subxt_metadata_test() { } fn subxt_core_test() { - let era = subxt_core::utils::era::Era::Immortal; + let era = subxt_core::utils::Era::Immortal; }