mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-20 22:05:42 +00:00
start porting dynamic value stuff
This commit is contained in:
+4
-4
@@ -71,9 +71,9 @@ frame-metadata = { version = "16.0.0", default-features = false }
|
|||||||
futures = { version = "0.3.30", default-features = false, features = ["std"] }
|
futures = { version = "0.3.30", default-features = false, features = ["std"] }
|
||||||
getrandom = { version = "0.2", default-features = false }
|
getrandom = { version = "0.2", default-features = false }
|
||||||
hashbrown = "0.14.3"
|
hashbrown = "0.14.3"
|
||||||
hex = "0.4.3"
|
hex = { version = "0.4.3", default-features = false }
|
||||||
heck = "0.4.1"
|
heck = "0.4.1"
|
||||||
impl-serde = { version = "0.4.0" }
|
impl-serde = { version = "0.4.0", default-features = false }
|
||||||
indoc = "2"
|
indoc = "2"
|
||||||
jsonrpsee = { version = "0.21" }
|
jsonrpsee = { version = "0.21" }
|
||||||
pretty_assertions = "1.4.0"
|
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-bits = { version = "0.4.0", default-features = false }
|
||||||
scale-decode = { version = "0.10.0", default-features = false }
|
scale-decode = { version = "0.10.0", default-features = false }
|
||||||
scale-encode = { version = "0.5.0", default-features = false }
|
scale-encode = { version = "0.5.0", default-features = false }
|
||||||
serde = { version = "1.0.196" }
|
serde = { version = "1.0.196", default-features = false, features = ["derive"] }
|
||||||
serde_json = { version = "1.0.113" }
|
serde_json = { version = "1.0.113", default-features = false }
|
||||||
syn = { version = "2.0.15", features = ["full", "extra-traits"] }
|
syn = { version = "2.0.15", features = ["full", "extra-traits"] }
|
||||||
thiserror = "1.0.53"
|
thiserror = "1.0.53"
|
||||||
tokio = { version = "1.35", default-features = false }
|
tokio = { version = "1.35", default-features = false }
|
||||||
|
|||||||
+4
-4
@@ -31,16 +31,16 @@ frame-metadata = { workspace = true, default-features = false }
|
|||||||
subxt-metadata = { workspace = true, default-features = false }
|
subxt-metadata = { workspace = true, default-features = false }
|
||||||
derivative = { workspace = true, features = ["use_core"] }
|
derivative = { workspace = true, features = ["use_core"] }
|
||||||
derive_more = { workspace = true }
|
derive_more = { workspace = true }
|
||||||
hex = { workspace = true }
|
hex = { workspace = true, default-features = false, features = ["alloc"] }
|
||||||
serde = { workspace = true, features = ["derive"] }
|
serde = { workspace = true, default-features = false, features = ["derive"] }
|
||||||
serde_json = { workspace = true, features = ["raw_value"] }
|
serde_json = { workspace = true, default-features = false, features = ["raw_value", "alloc"] }
|
||||||
|
|
||||||
# For ss58 encoding AccountId32 to serialize them properly:
|
# For ss58 encoding AccountId32 to serialize them properly:
|
||||||
base58 = { workspace = true }
|
base58 = { workspace = true }
|
||||||
blake2 = { workspace = true }
|
blake2 = { workspace = true }
|
||||||
|
|
||||||
# Provides some deserialization, types like U256/H256 and hashing impls like twox/blake256:
|
# 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"] }
|
primitive-types = { workspace = true, default-features = false, features = ["codec", "serde_no_std", "scale-info"] }
|
||||||
sp-core-hashing = { workspace = true }
|
sp-core-hashing = { workspace = true }
|
||||||
|
|
||||||
|
|||||||
+66
-65
@@ -1,20 +1,21 @@
|
|||||||
// // Copyright 2019-2023 Parity Technologies (UK) Ltd.
|
// Copyright 2019-2023 Parity Technologies (UK) Ltd.
|
||||||
// // This file is dual-licensed as Apache-2.0 or GPL-3.0.
|
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
|
||||||
// // see LICENSE for license details.
|
// see LICENSE for license details.
|
||||||
|
|
||||||
// //! This module provides the entry points to create dynamic
|
//! This module provides the entry points to create dynamic
|
||||||
// //! transactions, storage and constant lookups.
|
//! transactions, storage and constant lookups.
|
||||||
|
|
||||||
// use crate::metadata::{DecodeWithMetadata, Metadata};
|
use crate::metadata::{DecodeWithMetadata, Metadata};
|
||||||
// use scale_decode::DecodeAsType;
|
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
|
||||||
// /// A [`scale_value::Value`] type endowed with contextual information
|
/// [`subxt_core::metadata::DecodeWithMetadata`], and is used as a return type
|
||||||
// /// regarding what type was used to decode each part of it. This implements
|
/// for dynamic requests.
|
||||||
// /// [`crate::metadata::DecodeWithMetadata`], and is used as a return type
|
pub type DecodedValue = scale_value::Value<scale_value::scale::TypeId>;
|
||||||
// /// for dynamic requests.
|
|
||||||
// pub type DecodedValue = scale_value::Value<scale_value::scale::TypeId>;
|
|
||||||
|
|
||||||
// // Submit dynamic transactions.
|
// // Submit dynamic transactions.
|
||||||
// pub use crate::tx::dynamic as tx;
|
// pub use crate::tx::dynamic as tx;
|
||||||
@@ -28,56 +29,56 @@
|
|||||||
// // Execute runtime API function call dynamically.
|
// // Execute runtime API function call dynamically.
|
||||||
// pub use crate::runtime_api::dynamic as runtime_api_call;
|
// pub use crate::runtime_api::dynamic as runtime_api_call;
|
||||||
|
|
||||||
// /// This is the result of making a dynamic request to a node. From this,
|
/// 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
|
/// 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.
|
/// complete the decoding of the bytes into a [`DecodedValue`] type.
|
||||||
// pub struct DecodedValueThunk {
|
pub struct DecodedValueThunk {
|
||||||
// type_id: u32,
|
type_id: u32,
|
||||||
// metadata: Metadata,
|
metadata: Metadata,
|
||||||
// scale_bytes: Vec<u8>,
|
scale_bytes: Vec<u8>,
|
||||||
// }
|
}
|
||||||
|
|
||||||
// impl DecodeWithMetadata for DecodedValueThunk {
|
impl DecodeWithMetadata for DecodedValueThunk {
|
||||||
// fn decode_with_metadata(
|
fn decode_with_metadata(
|
||||||
// bytes: &mut &[u8],
|
bytes: &mut &[u8],
|
||||||
// type_id: u32,
|
type_id: u32,
|
||||||
// metadata: &Metadata,
|
metadata: &Metadata,
|
||||||
// ) -> Result<Self, Error> {
|
) -> Result<Self, scale_decode::Error> {
|
||||||
// let mut v = Vec::with_capacity(bytes.len());
|
let mut v = Vec::with_capacity(bytes.len());
|
||||||
// v.extend_from_slice(bytes);
|
v.extend_from_slice(bytes);
|
||||||
// *bytes = &[];
|
*bytes = &[];
|
||||||
// Ok(DecodedValueThunk {
|
Ok(DecodedValueThunk {
|
||||||
// type_id,
|
type_id,
|
||||||
// metadata: metadata.clone(),
|
metadata: metadata.clone(),
|
||||||
// scale_bytes: v,
|
scale_bytes: v,
|
||||||
// })
|
})
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// impl DecodedValueThunk {
|
impl DecodedValueThunk {
|
||||||
// /// Return the SCALE encoded bytes handed back from the node.
|
/// Return the SCALE encoded bytes handed back from the node.
|
||||||
// pub fn into_encoded(self) -> Vec<u8> {
|
pub fn into_encoded(self) -> Vec<u8> {
|
||||||
// self.scale_bytes
|
self.scale_bytes
|
||||||
// }
|
}
|
||||||
// /// Return the SCALE encoded bytes handed back from the node without taking ownership of them.
|
/// Return the SCALE encoded bytes handed back from the node without taking ownership of them.
|
||||||
// pub fn encoded(&self) -> &[u8] {
|
pub fn encoded(&self) -> &[u8] {
|
||||||
// &self.scale_bytes
|
&self.scale_bytes
|
||||||
// }
|
}
|
||||||
// /// Decode the SCALE encoded storage entry into a dynamic [`DecodedValue`] type.
|
/// Decode the SCALE encoded storage entry into a dynamic [`DecodedValue`] type.
|
||||||
// pub fn to_value(&self) -> Result<DecodedValue, Error> {
|
pub fn to_value(&self) -> Result<DecodedValue, scale_decode::Error> {
|
||||||
// let val = DecodedValue::decode_as_type(
|
let val = DecodedValue::decode_as_type(
|
||||||
// &mut &*self.scale_bytes,
|
&mut &*self.scale_bytes,
|
||||||
// self.type_id,
|
self.type_id,
|
||||||
// self.metadata.types(),
|
self.metadata.types(),
|
||||||
// )?;
|
)?;
|
||||||
// Ok(val)
|
Ok(val)
|
||||||
// }
|
}
|
||||||
// /// decode the `DecodedValueThunk` into a concrete type.
|
/// decode the `DecodedValueThunk` into a concrete type.
|
||||||
// pub fn as_type<T: DecodeAsType>(&self) -> Result<T, scale_decode::Error> {
|
pub fn as_type<T: DecodeAsType>(&self) -> Result<T, scale_decode::Error> {
|
||||||
// T::decode_as_type(
|
T::decode_as_type(
|
||||||
// &mut &self.scale_bytes[..],
|
&mut &self.scale_bytes[..],
|
||||||
// self.type_id,
|
self.type_id,
|
||||||
// self.metadata.types(),
|
self.metadata.types(),
|
||||||
// )
|
)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|||||||
@@ -21,5 +21,7 @@ pub use config::{
|
|||||||
PolkadotExtrinsicParams, SubstrateConfig, SubstrateExtrinsicParams,
|
PolkadotExtrinsicParams, SubstrateConfig, SubstrateExtrinsicParams,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub use metadata::Metadata;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod macros;
|
mod macros;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ impl core::ops::Deref for Metadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Metadata {
|
impl Metadata {
|
||||||
pub(crate) fn new(md: subxt_metadata::Metadata) -> Self {
|
pub fn new(md: subxt_metadata::Metadata) -> Self {
|
||||||
Metadata {
|
Metadata {
|
||||||
inner: Arc::new(md),
|
inner: Arc::new(md),
|
||||||
}
|
}
|
||||||
@@ -125,3 +125,6 @@ pub enum MetadataError {
|
|||||||
#[display(fmt = "Custom value with name {_0} not found")]
|
#[display(fmt = "Custom value with name {_0} not found")]
|
||||||
CustomValueNameNotFound(String),
|
CustomValueNameNotFound(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
impl std::error::Error for MetadataError {}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ mod decode_encode_traits;
|
|||||||
mod metadata_type;
|
mod metadata_type;
|
||||||
|
|
||||||
pub use decode_encode_traits::{DecodeWithMetadata, EncodeWithMetadata};
|
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:
|
// Expose metadata types under a sub module in case somebody needs to reference them:
|
||||||
pub use subxt_metadata as types;
|
pub use subxt_metadata as types;
|
||||||
|
|||||||
@@ -5,12 +5,12 @@
|
|||||||
//! An interface to call the raw legacy RPC methods.
|
//! An interface to call the raw legacy RPC methods.
|
||||||
|
|
||||||
use crate::backend::rpc::{rpc_params, RpcClient, RpcSubscription};
|
use crate::backend::rpc::{rpc_params, RpcClient, RpcSubscription};
|
||||||
use crate::metadata::Metadata;
|
|
||||||
use crate::{Config, Error};
|
use crate::{Config, Error};
|
||||||
use codec::Decode;
|
use codec::Decode;
|
||||||
use derivative::Derivative;
|
use derivative::Derivative;
|
||||||
use primitive_types::U256;
|
use primitive_types::U256;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use subxt_core::metadata::Metadata;
|
||||||
|
|
||||||
/// An interface to call the legacy RPC methods. This interface is instantiated with
|
/// 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
|
/// 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`].
|
/// Attempt to decode the error bytes into a [`DryRunResult`] using the provided [`Metadata`].
|
||||||
pub fn into_dry_run_result(
|
pub fn into_dry_run_result(
|
||||||
self,
|
self,
|
||||||
metadata: &crate::metadata::Metadata,
|
metadata: &subxt_core::metadata::Metadata,
|
||||||
) -> Result<DryRunResult, crate::Error> {
|
) -> Result<DryRunResult, crate::Error> {
|
||||||
// dryRun returns an ApplyExtrinsicResult, which is basically a
|
// dryRun returns an ApplyExtrinsicResult, which is basically a
|
||||||
// `Result<Result<(), DispatchError>, TransactionValidityError>`.
|
// `Result<Result<(), DispatchError>, TransactionValidityError>`.
|
||||||
|
|||||||
@@ -11,13 +11,13 @@ pub mod rpc;
|
|||||||
pub mod unstable;
|
pub mod unstable;
|
||||||
|
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::metadata::Metadata;
|
|
||||||
use crate::Config;
|
use crate::Config;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use codec::{Decode, Encode};
|
use codec::{Decode, Encode};
|
||||||
use futures::{Stream, StreamExt};
|
use futures::{Stream, StreamExt};
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use subxt_core::metadata::Metadata;
|
||||||
|
|
||||||
/// Prevent the backend trait being implemented externally.
|
/// Prevent the backend trait being implemented externally.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ use crate::{
|
|||||||
client::{OfflineClientT, OnlineClientT},
|
client::{OfflineClientT, OnlineClientT},
|
||||||
config::{Config, Hasher},
|
config::{Config, Hasher},
|
||||||
error::{BlockError, Error, MetadataError},
|
error::{BlockError, Error, MetadataError},
|
||||||
events,
|
events, Metadata,
|
||||||
metadata::types::PalletMetadata,
|
|
||||||
Metadata,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use subxt_core::metadata::types::PalletMetadata;
|
||||||
|
|
||||||
use crate::config::signed_extensions::{
|
use crate::config::signed_extensions::{
|
||||||
ChargeAssetTxPayment, ChargeTransactionPayment, CheckNonce,
|
ChargeAssetTxPayment, ChargeTransactionPayment, CheckNonce,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -117,8 +117,8 @@ impl<T: Config> LightClient<T> {
|
|||||||
// think about importing the OnlineClientT/OfflineClientT
|
// think about importing the OnlineClientT/OfflineClientT
|
||||||
// traits to use these things:
|
// traits to use these things:
|
||||||
|
|
||||||
/// Return the [`crate::Metadata`] used in this client.
|
/// Return the [`subxt_core::metadata`] used in this client.
|
||||||
fn metadata(&self) -> crate::Metadata {
|
fn metadata(&self) -> subxt_core::metadata {
|
||||||
self.client.metadata()
|
self.client.metadata()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,7 +180,7 @@ impl<T: Config> OnlineClientT<T> for LightClient<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Config> OfflineClientT<T> for LightClient<T> {
|
impl<T: Config> OfflineClientT<T> for LightClient<T> {
|
||||||
fn metadata(&self) -> crate::Metadata {
|
fn metadata(&self) -> subxt_core::metadata {
|
||||||
self.metadata()
|
self.metadata()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,10 @@
|
|||||||
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
|
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
|
||||||
// see LICENSE for license details.
|
// see LICENSE for license details.
|
||||||
|
|
||||||
use crate::{dynamic::DecodedValueThunk, metadata::DecodeWithMetadata};
|
use crate::dynamic::DecodedValueThunk;
|
||||||
use derivative::Derivative;
|
use derivative::Derivative;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
use subxt_core::metadata::DecodeWithMetadata;
|
||||||
|
|
||||||
/// This represents a constant address. Anything implementing this trait
|
/// This represents a constant address. Anything implementing this trait
|
||||||
/// can be used to fetch constants.
|
/// can be used to fetch constants.
|
||||||
|
|||||||
@@ -6,10 +6,11 @@ use super::ConstantAddress;
|
|||||||
use crate::{
|
use crate::{
|
||||||
client::OfflineClientT,
|
client::OfflineClientT,
|
||||||
error::{Error, MetadataError},
|
error::{Error, MetadataError},
|
||||||
metadata::DecodeWithMetadata,
|
|
||||||
Config,
|
Config,
|
||||||
};
|
};
|
||||||
|
|
||||||
use derivative::Derivative;
|
use derivative::Derivative;
|
||||||
|
use subxt_core::metadata::DecodeWithMetadata;
|
||||||
|
|
||||||
/// A client for accessing constants.
|
/// A client for accessing constants.
|
||||||
#[derive(Derivative)]
|
#[derive(Derivative)]
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use derivative::Derivative;
|
|||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
use crate::dynamic::DecodedValueThunk;
|
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.
|
/// This represents the address of a custom value in in the metadata.
|
||||||
/// Anything, that implements the [CustomValueAddress] trait can be used, to fetch
|
/// Anything, that implements the [CustomValueAddress] trait can be used, to fetch
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
use crate::client::OfflineClientT;
|
use crate::client::OfflineClientT;
|
||||||
use crate::custom_values::custom_value_address::{CustomValueAddress, Yes};
|
use crate::custom_values::custom_value_address::{CustomValueAddress, Yes};
|
||||||
use crate::error::MetadataError;
|
use crate::error::MetadataError;
|
||||||
use crate::metadata::DecodeWithMetadata;
|
|
||||||
use crate::{Config, Error};
|
use crate::{Config, Error};
|
||||||
use derivative::Derivative;
|
use derivative::Derivative;
|
||||||
|
use subxt_core::metadata::DecodeWithMetadata;
|
||||||
|
|
||||||
/// A client for accessing custom values stored in the metadata.
|
/// A client for accessing custom values stored in the metadata.
|
||||||
#[derive(Derivative)]
|
#[derive(Derivative)]
|
||||||
|
|||||||
+4
-59
@@ -5,17 +5,16 @@
|
|||||||
//! This module provides the entry points to create dynamic
|
//! This module provides the entry points to create dynamic
|
||||||
//! transactions, storage and constant lookups.
|
//! transactions, storage and constant lookups.
|
||||||
|
|
||||||
use crate::{
|
use crate::error::Error;
|
||||||
error::Error,
|
|
||||||
metadata::{DecodeWithMetadata, Metadata},
|
|
||||||
};
|
|
||||||
use scale_decode::DecodeAsType;
|
use scale_decode::DecodeAsType;
|
||||||
|
use subxt_core::metadata::{DecodeWithMetadata, Metadata};
|
||||||
|
|
||||||
pub use scale_value::{At, Value};
|
pub use scale_value::{At, Value};
|
||||||
|
|
||||||
/// A [`scale_value::Value`] type endowed with contextual information
|
/// A [`scale_value::Value`] type endowed with contextual information
|
||||||
/// regarding what type was used to decode each part of it. This implements
|
/// 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.
|
/// for dynamic requests.
|
||||||
pub type DecodedValue = scale_value::Value<scale_value::scale::TypeId>;
|
pub type DecodedValue = scale_value::Value<scale_value::scale::TypeId>;
|
||||||
|
|
||||||
@@ -30,57 +29,3 @@ pub use crate::storage::dynamic as storage;
|
|||||||
|
|
||||||
// Execute runtime API function call dynamically.
|
// Execute runtime API function call dynamically.
|
||||||
pub use crate::runtime_api::dynamic as runtime_api_call;
|
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<u8>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DecodeWithMetadata for DecodedValueThunk {
|
|
||||||
fn decode_with_metadata(
|
|
||||||
bytes: &mut &[u8],
|
|
||||||
type_id: u32,
|
|
||||||
metadata: &Metadata,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
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<u8> {
|
|
||||||
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<DecodedValue, Error> {
|
|
||||||
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<T: DecodeAsType>(&self) -> Result<T, scale_decode::Error> {
|
|
||||||
T::decode_as_type(
|
|
||||||
&mut &self.scale_bytes[..],
|
|
||||||
self.type_id,
|
|
||||||
self.metadata.types(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -5,10 +5,10 @@
|
|||||||
//! A representation of the dispatch error; an error returned when
|
//! A representation of the dispatch error; an error returned when
|
||||||
//! something fails in trying to submit/execute a transaction.
|
//! something fails in trying to submit/execute a transaction.
|
||||||
|
|
||||||
use crate::metadata::{DecodeWithMetadata, Metadata};
|
|
||||||
use core::fmt::Debug;
|
use core::fmt::Debug;
|
||||||
use scale_decode::{visitor::DecodeAsTypeResult, DecodeAsType};
|
use scale_decode::{visitor::DecodeAsTypeResult, DecodeAsType};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
use subxt_core::metadata::{DecodeWithMetadata, Metadata};
|
||||||
|
|
||||||
use super::{Error, MetadataError};
|
use super::{Error, MetadataError};
|
||||||
|
|
||||||
@@ -214,7 +214,7 @@ impl ModuleError {
|
|||||||
/// Details about the module error.
|
/// Details about the module error.
|
||||||
pub struct ModuleErrorDetails<'a> {
|
pub struct ModuleErrorDetails<'a> {
|
||||||
/// The pallet that the error is in
|
/// 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
|
/// The variant representing the error
|
||||||
pub variant: &'a scale_info::Variant<scale_info::form::PortableForm>,
|
pub variant: &'a scale_info::Variant<scale_info::form::PortableForm>,
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-52
@@ -17,11 +17,13 @@ pub use dispatch_error::{
|
|||||||
ArithmeticError, DispatchError, ModuleError, TokenError, TransactionalError,
|
ArithmeticError, DispatchError, ModuleError, TokenError, TransactionalError,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub use subxt_core::metadata::MetadataError;
|
||||||
|
|
||||||
// Re-expose the errors we use from other crates here:
|
// Re-expose the errors we use from other crates here:
|
||||||
pub use crate::config::ExtrinsicParamsError;
|
pub use crate::config::ExtrinsicParamsError;
|
||||||
pub use crate::metadata::Metadata;
|
|
||||||
pub use scale_decode::Error as DecodeError;
|
pub use scale_decode::Error as DecodeError;
|
||||||
pub use scale_encode::Error as EncodeError;
|
pub use scale_encode::Error as EncodeError;
|
||||||
|
pub use subxt_core::metadata::Metadata;
|
||||||
pub use subxt_metadata::TryFromError as MetadataTryFromError;
|
pub use subxt_metadata::TryFromError as MetadataTryFromError;
|
||||||
|
|
||||||
/// The underlying error enum, generic over the type held by the `Runtime`
|
/// The underlying error enum, generic over the type held by the `Runtime`
|
||||||
@@ -199,54 +201,3 @@ pub enum StorageAddressError {
|
|||||||
fields: usize,
|
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),
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -9,13 +9,13 @@ use crate::{
|
|||||||
client::OnlineClientT,
|
client::OnlineClientT,
|
||||||
error::{Error, MetadataError},
|
error::{Error, MetadataError},
|
||||||
events::events_client::get_event_bytes,
|
events::events_client::get_event_bytes,
|
||||||
metadata::types::PalletMetadata,
|
|
||||||
Config, Metadata,
|
Config, Metadata,
|
||||||
};
|
};
|
||||||
use codec::{Compact, Decode};
|
use codec::{Compact, Decode};
|
||||||
use derivative::Derivative;
|
use derivative::Derivative;
|
||||||
use scale_decode::DecodeAsType;
|
use scale_decode::DecodeAsType;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use subxt_core::metadata::types::PalletMetadata;
|
||||||
|
|
||||||
/// A collection of events obtained from a block, bundled with the necessary
|
/// A collection of events obtained from a block, bundled with the necessary
|
||||||
/// information needed to decode and iterate over them.
|
/// information needed to decode and iterate over them.
|
||||||
|
|||||||
+2
-2
@@ -51,7 +51,6 @@ pub mod custom_values;
|
|||||||
pub mod dynamic;
|
pub mod dynamic;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod events;
|
pub mod events;
|
||||||
pub mod metadata;
|
|
||||||
pub mod runtime_api;
|
pub mod runtime_api;
|
||||||
pub mod storage;
|
pub mod storage;
|
||||||
pub mod tx;
|
pub mod tx;
|
||||||
@@ -67,9 +66,10 @@ pub use crate::{
|
|||||||
client::{OfflineClient, OnlineClient},
|
client::{OfflineClient, OnlineClient},
|
||||||
config::{Config, PolkadotConfig, SubstrateConfig},
|
config::{Config, PolkadotConfig, SubstrateConfig},
|
||||||
error::Error,
|
error::Error,
|
||||||
metadata::Metadata,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use subxt_core::metadata::Metadata;
|
||||||
|
|
||||||
/// Re-export external crates that are made use of in the subxt API.
|
/// Re-export external crates that are made use of in the subxt API.
|
||||||
pub mod ext {
|
pub mod ext {
|
||||||
pub use codec;
|
pub use codec;
|
||||||
|
|||||||
@@ -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<Self, Error>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: scale_decode::DecodeAsType> DecodeWithMetadata for T {
|
|
||||||
fn decode_with_metadata(
|
|
||||||
bytes: &mut &[u8],
|
|
||||||
type_id: u32,
|
|
||||||
metadata: &Metadata,
|
|
||||||
) -> Result<T, Error> {
|
|
||||||
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<u8>,
|
|
||||||
) -> Result<(), Error>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: scale_encode::EncodeAsType> 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<u8>,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
self.encode_as_type_to(type_id, metadata.types(), bytes)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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<subxt_metadata::Metadata>,
|
|
||||||
}
|
|
||||||
|
|
||||||
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<subxt_metadata::PalletMetadata, MetadataError> {
|
|
||||||
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<subxt_metadata::PalletMetadata, MetadataError> {
|
|
||||||
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<subxt_metadata::RuntimeApiMetadata, MetadataError> {
|
|
||||||
self.runtime_api_trait_by_name(name)
|
|
||||||
.ok_or_else(|| MetadataError::RuntimeTraitNotFound(name.to_owned()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<subxt_metadata::Metadata> for Metadata {
|
|
||||||
fn from(md: subxt_metadata::Metadata) -> Self {
|
|
||||||
Metadata::new(md)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<frame_metadata::RuntimeMetadataPrefixed> for Metadata {
|
|
||||||
type Error = subxt_metadata::TryFromError;
|
|
||||||
fn try_from(value: frame_metadata::RuntimeMetadataPrefixed) -> Result<Self, Self::Error> {
|
|
||||||
subxt_metadata::Metadata::try_from(value).map(Metadata::from)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl codec::Decode for Metadata {
|
|
||||||
fn decode<I: codec::Input>(input: &mut I) -> Result<Self, codec::Error> {
|
|
||||||
subxt_metadata::Metadata::decode(input).map(Metadata::new)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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;
|
|
||||||
@@ -10,7 +10,9 @@ use std::borrow::Cow;
|
|||||||
|
|
||||||
use crate::dynamic::DecodedValueThunk;
|
use crate::dynamic::DecodedValueThunk;
|
||||||
use crate::error::MetadataError;
|
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.
|
/// This represents a runtime API payload that can call into the runtime of node.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ use crate::{
|
|||||||
backend::{BackendExt, BlockRef},
|
backend::{BackendExt, BlockRef},
|
||||||
client::OnlineClientT,
|
client::OnlineClientT,
|
||||||
error::{Error, MetadataError},
|
error::{Error, MetadataError},
|
||||||
metadata::DecodeWithMetadata,
|
|
||||||
Config,
|
Config,
|
||||||
};
|
};
|
||||||
use codec::Decode;
|
use codec::Decode;
|
||||||
use derivative::Derivative;
|
use derivative::Derivative;
|
||||||
use std::{future::Future, marker::PhantomData};
|
use std::{future::Future, marker::PhantomData};
|
||||||
|
use subxt_core::metadata::DecodeWithMetadata;
|
||||||
|
|
||||||
use super::RuntimeApiPayload;
|
use super::RuntimeApiPayload;
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,11 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
dynamic::DecodedValueThunk,
|
dynamic::DecodedValueThunk,
|
||||||
error::{Error, MetadataError, StorageAddressError},
|
error::{Error, MetadataError, StorageAddressError},
|
||||||
metadata::{DecodeWithMetadata, EncodeWithMetadata, Metadata},
|
|
||||||
utils::{Encoded, Static},
|
utils::{Encoded, Static},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use subxt_core::metadata::{DecodeWithMetadata, EncodeWithMetadata, Metadata};
|
||||||
|
|
||||||
use derivative::Derivative;
|
use derivative::Derivative;
|
||||||
use scale_info::TypeDef;
|
use scale_info::TypeDef;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|||||||
@@ -8,13 +8,13 @@ use crate::{
|
|||||||
backend::{BackendExt, BlockRef},
|
backend::{BackendExt, BlockRef},
|
||||||
client::OnlineClientT,
|
client::OnlineClientT,
|
||||||
error::{Error, MetadataError},
|
error::{Error, MetadataError},
|
||||||
metadata::{DecodeWithMetadata, Metadata},
|
|
||||||
Config,
|
Config,
|
||||||
};
|
};
|
||||||
use codec::Decode;
|
use codec::Decode;
|
||||||
use derivative::Derivative;
|
use derivative::Derivative;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use std::{future::Future, marker::PhantomData};
|
use std::{future::Future, marker::PhantomData};
|
||||||
|
use subxt_core::metadata::{DecodeWithMetadata, Metadata};
|
||||||
use subxt_metadata::{PalletMetadata, StorageEntryMetadata, StorageEntryType};
|
use subxt_metadata::{PalletMetadata, StorageEntryMetadata, StorageEntryType};
|
||||||
|
|
||||||
/// This is returned from a couple of storage functions.
|
/// This is returned from a couple of storage functions.
|
||||||
|
|||||||
@@ -7,7 +7,9 @@
|
|||||||
//! the trait itself.
|
//! the trait itself.
|
||||||
|
|
||||||
use super::StorageAddress;
|
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
|
/// Return the root of a given [`StorageAddress`]: hash the pallet name and entry name
|
||||||
/// and append those bytes to the output.
|
/// and append those bytes to the output.
|
||||||
|
|||||||
@@ -8,12 +8,12 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
dynamic::Value,
|
dynamic::Value,
|
||||||
error::{Error, MetadataError},
|
error::{Error, MetadataError},
|
||||||
metadata::Metadata,
|
|
||||||
};
|
};
|
||||||
use codec::Encode;
|
use codec::Encode;
|
||||||
use scale_encode::EncodeAsFields;
|
use scale_encode::EncodeAsFields;
|
||||||
use scale_value::{Composite, ValueDef, Variant};
|
use scale_value::{Composite, ValueDef, Variant};
|
||||||
use std::{borrow::Cow, sync::Arc};
|
use std::{borrow::Cow, sync::Arc};
|
||||||
|
use subxt_core::metadata::Metadata;
|
||||||
|
|
||||||
/// This represents a transaction payload that can be submitted
|
/// This represents a transaction payload that can be submitted
|
||||||
/// to a node.
|
/// to a node.
|
||||||
|
|||||||
@@ -337,7 +337,7 @@ mod test {
|
|||||||
struct MockClient;
|
struct MockClient;
|
||||||
|
|
||||||
impl OfflineClientT<SubstrateConfig> for MockClient {
|
impl OfflineClientT<SubstrateConfig> for MockClient {
|
||||||
fn metadata(&self) -> crate::Metadata {
|
fn metadata(&self) -> subxt_core::metadata {
|
||||||
unimplemented!("just a mock impl to satisfy trait bounds")
|
unimplemented!("just a mock impl to satisfy trait bounds")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,5 +49,5 @@ fn subxt_metadata_test() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn subxt_core_test() {
|
fn subxt_core_test() {
|
||||||
let era = subxt_core::utils::era::Era::Immortal;
|
let era = subxt_core::utils::Era::Immortal;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user