fix examples with core crate

This commit is contained in:
Tadeo hepperle
2024-02-15 17:38:26 +01:00
parent fda9a5fd0c
commit ac3c7d7467
27 changed files with 89 additions and 83 deletions
Generated
+2 -2
View File
@@ -793,9 +793,9 @@ dependencies = [
[[package]] [[package]]
name = "chrono" name = "chrono"
version = "0.4.33" version = "0.4.34"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f13690e35a5e4ace198e7beea2895d29f3a9cc55015fcebe6336bd2010af9eb" checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b"
dependencies = [ dependencies = [
"android-tzdata", "android-tzdata",
"iana-time-zone", "iana-time-zone",
+1 -1
View File
@@ -154,7 +154,7 @@ fn mocked_offline_client(metadata: Metadata) -> OfflineClient<SubstrateConfig> {
H256::from_str("91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3") H256::from_str("91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3")
.expect("Valid hash; qed"); .expect("Valid hash; qed");
let runtime_version = subxt::backend::RuntimeVersion { let runtime_version = subxt::RuntimeVersion {
spec_version: 9370, spec_version: 9370,
transaction_version: 20, transaction_version: 20,
}; };
+10 -6
View File
@@ -15,7 +15,7 @@ pub mod config;
pub mod constants; pub mod constants;
pub mod custom_values; pub mod custom_values;
pub mod dynamic; pub mod dynamic;
mod error; pub mod error;
pub mod metadata; pub mod metadata;
pub mod runtime_api; pub mod runtime_api;
pub mod signer; pub mod signer;
@@ -23,17 +23,21 @@ pub mod storage;
pub mod tx; pub mod tx;
pub mod utils; pub mod utils;
pub use error::{Error, ExtrinsicParamsError, MetadataError, StorageAddressError};
pub use client::{ClientBase, RuntimeVersion}; pub use client::{ClientBase, RuntimeVersion};
pub use config::{ pub use config::{
BlockHash, Config, ExtrinsicParams, ExtrinsicParamsEncoder, PolkadotConfig, signed_extensions, BlockHash, Config, ExtrinsicParams, ExtrinsicParamsEncoder, Hasher, Header,
PolkadotExtrinsicParams, SubstrateConfig, SubstrateExtrinsicParams, PolkadotConfig, PolkadotExtrinsicParams, SignedExtension, SubstrateConfig,
SubstrateExtrinsicParams,
}; };
pub use dynamic::{DecodedValue, DecodedValueThunk};
pub use error::{Error, ExtrinsicParamsError, MetadataError, StorageAddressError};
pub use metadata::Metadata; pub use metadata::Metadata;
pub use signer::Signer; pub use signer::Signer;
pub use storage::StorageAddress; pub use storage::StorageAddress;
pub use utils::{to_hex, AccountId32, MultiAddress, MultiSignature, Yes, H160, H256, H512}; pub use utils::{
strip_compact_prefix, to_hex, AccountId32, KeyedVec, MultiAddress, MultiSignature, Yes, H160,
H256, H512,
};
#[macro_use] #[macro_use]
mod macros; mod macros;
+14
View File
@@ -38,6 +38,20 @@ pub trait TxPayload {
fn validation_details(&self) -> Option<ValidationDetails<'_>> { fn validation_details(&self) -> Option<ValidationDetails<'_>> {
None None
} }
fn validate(&self, metadata: &Metadata) -> Result<(), Error> {
if let Some(details) = self.validation_details() {
let expected_hash = metadata
.pallet_by_name_err(details.pallet_name)?
.call_hash(details.call_name)
.ok_or_else(|| MetadataError::CallNameNotFound(details.call_name.to_owned()))?;
if details.hash != expected_hash {
return Err(MetadataError::IncompatibleCodegen.into());
}
}
Ok(())
}
} }
pub struct ValidationDetails<'a> { pub struct ValidationDetails<'a> {
+3 -15
View File
@@ -24,23 +24,11 @@ default = ["jsonrpsee", "native"]
# Enable this for native (ie non web/wasm builds). # Enable this for native (ie non web/wasm builds).
# Exactly 1 of "web" and "native" is expected. # Exactly 1 of "web" and "native" is expected.
native = [ native = ["jsonrpsee?/async-client", "jsonrpsee?/client-ws-transport-native-tls", "subxt-lightclient?/native", "tokio-util"]
"jsonrpsee?/async-client",
"jsonrpsee?/client-ws-transport-native-tls",
"subxt-lightclient?/native",
"tokio-util"
]
# Enable this for web/wasm builds. # Enable this for web/wasm builds.
# Exactly 1 of "web" and "native" is expected. # Exactly 1 of "web" and "native" is expected.
web = [ web = ["jsonrpsee?/async-wasm-client", "jsonrpsee?/client-web-transport", "getrandom/js", "subxt-lightclient?/web", "subxt-macro/web", "instant/wasm-bindgen"]
"jsonrpsee?/async-wasm-client",
"jsonrpsee?/client-web-transport",
"getrandom/js",
"subxt-lightclient?/web",
"subxt-macro/web",
"instant/wasm-bindgen"
]
# Enable this to use the reconnecting rpc client # Enable this to use the reconnecting rpc client
unstable-reconnecting-rpc-client = ["dep:reconnecting-jsonrpsee-ws-client"] unstable-reconnecting-rpc-client = ["dep:reconnecting-jsonrpsee-ws-client"]
@@ -51,7 +39,7 @@ jsonrpsee = ["dep:jsonrpsee"]
# Enable this to pull in extra Substrate dependencies which make it possible to # Enable this to pull in extra Substrate dependencies which make it possible to
# use the `sp_core::crypto::Pair` Signer implementation, as well as adding some # use the `sp_core::crypto::Pair` Signer implementation, as well as adding some
# `From` impls for types like `AccountId32`. Cannot be used with "web". # `From` impls for types like `AccountId32`. Cannot be used with "web".
substrate-compat = ["sp-core", "sp-runtime"] substrate-compat = ["sp-core", "sp-runtime", "subxt-core/substrate-compat"]
# Enable this to fetch and utilize the latest unstable metadata from a node. # Enable this to fetch and utilize the latest unstable metadata from a node.
# The unstable metadata is subject to breaking changes and the subxt might # The unstable metadata is subject to breaking changes and the subxt might
+3 -3
View File
@@ -1,6 +1,6 @@
#![allow(missing_docs)] #![allow(missing_docs)]
use codec::Encode; use codec::Encode;
use subxt::client::OfflineClientT; use subxt::client::{ClientBase};
use subxt::config::{Config, ExtrinsicParams, ExtrinsicParamsEncoder}; use subxt::config::{Config, ExtrinsicParams, ExtrinsicParamsEncoder};
use subxt_core::ExtrinsicParamsError; use subxt_core::ExtrinsicParamsError;
use subxt_signer::sr25519::dev; use subxt_signer::sr25519::dev;
@@ -57,9 +57,9 @@ impl<T: Config> ExtrinsicParams<T> for CustomExtrinsicParams<T> {
type OtherParams = CustomExtrinsicParamsBuilder; type OtherParams = CustomExtrinsicParamsBuilder;
// Gather together all of the params we will need to encode: // Gather together all of the params we will need to encode:
fn new<Client: OfflineClientT<T>>( fn new(
_nonce: u64, _nonce: u64,
client: Client, client: ClientBase<T>,
other_params: Self::OtherParams, other_params: Self::OtherParams,
) -> Result<Self, ExtrinsicParamsError> { ) -> Result<Self, ExtrinsicParamsError> {
Ok(Self { Ok(Self {
@@ -2,7 +2,6 @@
use codec::Encode; use codec::Encode;
use scale_encode::EncodeAsType; use scale_encode::EncodeAsType;
use scale_info::PortableRegistry; use scale_info::PortableRegistry;
use subxt::client::OfflineClientT;
use subxt::config::{ use subxt::config::{
Config, DefaultExtrinsicParamsBuilder, ExtrinsicParams, ExtrinsicParamsEncoder, Config, DefaultExtrinsicParamsBuilder, ExtrinsicParams, ExtrinsicParamsEncoder,
}; };
@@ -62,7 +61,7 @@ impl<T: Config> ExtrinsicParams<T> for CustomSignedExtension {
fn new( fn new(
_nonce: u64, _nonce: u64,
_client: subxt_core::ClientBase, _client: subxt_core::ClientBase<T>,
_other_params: Self::OtherParams, _other_params: Self::OtherParams,
) -> Result<Self, ExtrinsicParamsError> { ) -> Result<Self, ExtrinsicParamsError> {
Ok(CustomSignedExtension) Ok(CustomSignedExtension)
+2 -1
View File
@@ -12,12 +12,13 @@ use crate::backend::{
rpc::RpcClient, Backend, BlockRef, RuntimeVersion, StorageResponse, StreamOf, StreamOfResults, rpc::RpcClient, Backend, BlockRef, RuntimeVersion, StorageResponse, StreamOf, StreamOfResults,
TransactionStatus, TransactionStatus,
}; };
use crate::{config::Header, Config, Error}; use crate::Error;
use async_trait::async_trait; use async_trait::async_trait;
use futures::{future, future::Either, stream, Future, FutureExt, Stream, StreamExt}; use futures::{future, future::Either, stream, Future, FutureExt, Stream, StreamExt};
use std::collections::VecDeque; use std::collections::VecDeque;
use std::pin::Pin; use std::pin::Pin;
use std::task::{Context, Poll}; use std::task::{Context, Poll};
use subxt_core::{config::Header, Config};
// Expose the RPC methods. // Expose the RPC methods.
pub use rpc_methods::LegacyRpcMethods; pub use rpc_methods::LegacyRpcMethods;
+2 -2
View File
@@ -3,12 +3,12 @@
// see LICENSE for license details. // see LICENSE for license details.
use super::rpc_methods::{FollowEvent, UnstableRpcMethods}; use super::rpc_methods::{FollowEvent, UnstableRpcMethods};
use crate::config::Config;
use crate::error::Error; use crate::error::Error;
use futures::{FutureExt, Stream, StreamExt}; use futures::{FutureExt, Stream, StreamExt};
use std::future::Future; use std::future::Future;
use std::pin::Pin; use std::pin::Pin;
use std::task::{Context, Poll}; use std::task::{Context, Poll};
use subxt_core::config::Config;
/// A `Stream` whose goal is to remain subscribed to `chainHead_follow`. It will re-subscribe if the subscription /// A `Stream` whose goal is to remain subscribed to `chainHead_follow`. It will re-subscribe if the subscription
/// is ended for any reason, and it will return the current `subscription_id` as an event, along with the other /// is ended for any reason, and it will return the current `subscription_id` as an event, along with the other
@@ -206,9 +206,9 @@ pub(super) mod test_utils {
use crate::backend::unstable::rpc_methods::{ use crate::backend::unstable::rpc_methods::{
BestBlockChanged, Finalized, Initialized, NewBlock, BestBlockChanged, Finalized, Initialized, NewBlock,
}; };
use crate::config::substrate::H256;
use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc; use std::sync::Arc;
use subxt_core::config::substrate::H256;
/// Given some events, returns a follow stream getter that we can use in /// Given some events, returns a follow stream getter that we can use in
/// place of the usual RPC method. /// place of the usual RPC method.
@@ -4,7 +4,6 @@
use super::follow_stream_unpin::{BlockRef, FollowStreamMsg, FollowStreamUnpin}; use super::follow_stream_unpin::{BlockRef, FollowStreamMsg, FollowStreamUnpin};
use crate::backend::unstable::rpc_methods::{FollowEvent, Initialized, RuntimeEvent}; use crate::backend::unstable::rpc_methods::{FollowEvent, Initialized, RuntimeEvent};
use crate::config::BlockHash;
use crate::error::Error; use crate::error::Error;
use futures::stream::{Stream, StreamExt}; use futures::stream::{Stream, StreamExt};
use std::collections::{HashMap, HashSet, VecDeque}; use std::collections::{HashMap, HashSet, VecDeque};
@@ -12,6 +11,7 @@ use std::ops::DerefMut;
use std::pin::Pin; use std::pin::Pin;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::task::{Context, Poll, Waker}; use std::task::{Context, Poll, Waker};
use subxt_core::config::BlockHash;
/// A `Stream` which builds on `FollowStreamDriver`, and allows multiple subscribers to obtain events /// A `Stream` which builds on `FollowStreamDriver`, and allows multiple subscribers to obtain events
/// from the single underlying subscription (each being provided an `Initialized` message and all new /// from the single underlying subscription (each being provided an `Initialized` message and all new
@@ -7,7 +7,6 @@ use super::UnstableRpcMethods;
use crate::backend::unstable::rpc_methods::{ use crate::backend::unstable::rpc_methods::{
BestBlockChanged, Finalized, FollowEvent, Initialized, NewBlock, BestBlockChanged, Finalized, FollowEvent, Initialized, NewBlock,
}; };
use crate::config::{BlockHash, Config};
use crate::error::Error; use crate::error::Error;
use futures::stream::{FuturesUnordered, Stream, StreamExt}; use futures::stream::{FuturesUnordered, Stream, StreamExt};
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
@@ -15,6 +14,7 @@ use std::future::Future;
use std::pin::Pin; use std::pin::Pin;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::task::{Context, Poll, Waker}; use std::task::{Context, Poll, Waker};
use subxt_core::config::{BlockHash, Config};
/// The type of stream item. /// The type of stream item.
pub use super::follow_stream::FollowStreamMsg; pub use super::follow_stream::FollowStreamMsg;
@@ -455,7 +455,7 @@ impl<Hash: BlockHash> Drop for BlockRef<Hash> {
pub(super) mod test_utils { pub(super) mod test_utils {
use super::super::follow_stream::{test_utils::test_stream_getter, FollowStream}; use super::super::follow_stream::{test_utils::test_stream_getter, FollowStream};
use super::*; use super::*;
use crate::config::substrate::H256; use subxt_core::config::substrate::H256;
pub type UnpinRx<Hash> = std::sync::mpsc::Receiver<(Hash, Arc<str>)>; pub type UnpinRx<Hash> = std::sync::mpsc::Receiver<(Hash, Arc<str>)>;
@@ -542,7 +542,7 @@ mod test {
}; };
use super::test_utils::{assert_from_unpin_rx, ev_new_block_ref, test_unpin_stream_getter}; use super::test_utils::{assert_from_unpin_rx, ev_new_block_ref, test_unpin_stream_getter};
use super::*; use super::*;
use crate::config::substrate::H256; use subxt_core::config::substrate::H256;
#[tokio::test] #[tokio::test]
async fn hands_back_blocks() { async fn hands_back_blocks() {
+1 -1
View File
@@ -25,7 +25,6 @@ use crate::backend::{
rpc::RpcClient, Backend, BlockRef, BlockRefT, RuntimeVersion, StorageResponse, StreamOf, rpc::RpcClient, Backend, BlockRef, BlockRefT, RuntimeVersion, StorageResponse, StreamOf,
StreamOfResults, TransactionStatus, StreamOfResults, TransactionStatus,
}; };
use crate::config::BlockHash;
use crate::error::{Error, RpcError}; use crate::error::{Error, RpcError};
use crate::Config; use crate::Config;
use async_trait::async_trait; use async_trait::async_trait;
@@ -35,6 +34,7 @@ use std::collections::HashMap;
use std::sync::Arc; use std::sync::Arc;
use std::task::Poll; use std::task::Poll;
use storage_items::StorageItems; use storage_items::StorageItems;
use subxt_core::config::BlockHash;
// Expose the RPC methods. // Expose the RPC methods.
pub use rpc_methods::UnstableRpcMethods; pub use rpc_methods::UnstableRpcMethods;
+1 -1
View File
@@ -7,13 +7,13 @@
//! methods exposed here. //! methods exposed here.
use crate::backend::rpc::{rpc_params, RpcClient, RpcSubscription}; use crate::backend::rpc::{rpc_params, RpcClient, RpcSubscription};
use crate::config::BlockHash;
use crate::{Config, Error}; use crate::{Config, Error};
use derivative::Derivative; use derivative::Derivative;
use futures::{Stream, StreamExt}; use futures::{Stream, StreamExt};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::{HashMap, VecDeque}; use std::collections::{HashMap, VecDeque};
use std::task::Poll; use std::task::Poll;
use subxt_core::config::BlockHash;
use subxt_core::to_hex; use subxt_core::to_hex;
/// An interface to call the unstable RPC methods. This interface is instantiated with /// An interface to call the unstable RPC methods. This interface is instantiated with
+1 -1
View File
@@ -7,7 +7,6 @@ use super::follow_stream_unpin::BlockRef;
use super::rpc_methods::{ use super::rpc_methods::{
FollowEvent, MethodResponse, StorageQuery, StorageResult, UnstableRpcMethods, FollowEvent, MethodResponse, StorageQuery, StorageResult, UnstableRpcMethods,
}; };
use crate::config::Config;
use crate::error::{Error, RpcError}; use crate::error::{Error, RpcError};
use futures::{FutureExt, Stream, StreamExt}; use futures::{FutureExt, Stream, StreamExt};
use std::collections::VecDeque; use std::collections::VecDeque;
@@ -15,6 +14,7 @@ use std::future::Future;
use std::pin::Pin; use std::pin::Pin;
use std::sync::Arc; use std::sync::Arc;
use std::task::{Context, Poll}; use std::task::{Context, Poll};
use subxt_core::config::Config;
/// Obtain a stream of storage items given some query. this handles continuing /// Obtain a stream of storage items given some query. this handles continuing
/// and stopping under the hood, and returns a stream of `StorageResult`s. /// and stopping under the hood, and returns a stream of `StorageResult`s.
+2 -3
View File
@@ -6,16 +6,15 @@ use crate::{
backend::BlockRef, backend::BlockRef,
blocks::{extrinsic_types::ExtrinsicPartTypeIds, Extrinsics}, blocks::{extrinsic_types::ExtrinsicPartTypeIds, Extrinsics},
client::{OfflineClientT, OnlineClientT}, client::{OfflineClientT, OnlineClientT},
config::{Config, Header},
error::{BlockError, DecodeError, Error}, error::{BlockError, DecodeError, Error},
events, events,
runtime_api::RuntimeApi, runtime_api::RuntimeApi,
storage::Storage, storage::Storage,
}; };
use codec::{Decode, Encode}; use codec::{Decode, Encode};
use futures::lock::Mutex as AsyncMutex; use futures::lock::Mutex as AsyncMutex;
use std::sync::Arc; use std::sync::Arc;
use subxt_core::{Config, Header};
/// A representation of a block. /// A representation of a block.
pub struct Block<T: Config, C> { pub struct Block<T: Config, C> {
@@ -57,7 +56,7 @@ where
} }
/// Return the block number. /// Return the block number.
pub fn number(&self) -> <T::Header as crate::config::Header>::Number { pub fn number(&self) -> <T::Header as subxt_core::Header>::Number {
self.header().number() self.header().number()
} }
+2 -2
View File
@@ -6,13 +6,13 @@ use super::Block;
use crate::{ use crate::{
backend::{BlockRef, StreamOfResults}, backend::{BlockRef, StreamOfResults},
client::OnlineClientT, client::OnlineClientT,
config::Config,
error::{BlockError, Error}, error::{BlockError, Error},
utils::PhantomDataSendSync,
}; };
use derivative::Derivative; use derivative::Derivative;
use futures::StreamExt; use futures::StreamExt;
use std::future::Future; use std::future::Future;
use subxt_core::utils::PhantomDataSendSync;
use subxt_core::Config;
type BlockStream<T> = StreamOfResults<T>; type BlockStream<T> = StreamOfResults<T>;
type BlockStreamRes<T> = Result<BlockStream<T>, Error>; type BlockStreamRes<T> = Result<BlockStream<T>, Error>;
+8 -10
View File
@@ -5,22 +5,20 @@
use crate::{ use crate::{
blocks::block_types::{get_events, CachedEvents}, blocks::block_types::{get_events, CachedEvents},
client::{OfflineClientT, OnlineClientT}, client::{OfflineClientT, OnlineClientT},
config::{Config, Hasher},
error::{BlockError, Error, MetadataError}, error::{BlockError, Error, MetadataError},
events, Metadata, events,
};
use subxt_core::{
metadata::MetadatExt,
signed_extensions::{ChargeAssetTxPayment, ChargeTransactionPayment, CheckNonce},
strip_compact_prefix, Config, Hasher, Metadata,
}; };
use subxt_core::metadata::{types::PalletMetadata, MetadatExt};
use crate::config::signed_extensions::{
ChargeAssetTxPayment, ChargeTransactionPayment, CheckNonce,
};
use crate::config::SignedExtension;
use crate::dynamic::DecodedValue;
use crate::utils::strip_compact_prefix;
use codec::Decode; use codec::Decode;
use derivative::Derivative; use derivative::Derivative;
use scale_decode::{DecodeAsFields, DecodeAsType}; use scale_decode::{DecodeAsFields, DecodeAsType};
use subxt_core::{DecodedValue, SignedExtension};
use subxt_metadata::PalletMetadata;
use std::sync::Arc; use std::sync::Arc;
+1
View File
@@ -23,3 +23,4 @@ pub use offline_client::{OfflineClient, OfflineClientT};
pub use online_client::{ pub use online_client::{
ClientRuntimeUpdater, OnlineClient, OnlineClientT, RuntimeUpdaterStream, Update, UpgradeError, ClientRuntimeUpdater, OnlineClient, OnlineClientT, RuntimeUpdaterStream, Update, UpgradeError,
}; };
pub use subxt_core::ClientBase;
+10 -1
View File
@@ -66,7 +66,15 @@ pub use crate::{
}; };
// We replace this by proper exports, once the API of subxt_core is aggreed upon. // We replace this by proper exports, once the API of subxt_core is aggreed upon.
pub use subxt_core::*; // pub use subxt_core::*;
pub use subxt_core::{
dynamic, signed_extensions, AccountId32, BlockHash, ClientBase, Config, DecodedValue,
DecodedValueThunk, ExtrinsicParams, ExtrinsicParamsEncoder, Hasher, Header, Metadata,
MultiAddress, PolkadotConfig, PolkadotExtrinsicParams, RuntimeVersion, Signer, StorageAddress,
SubstrateConfig, SubstrateExtrinsicParams,
config, 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 {
@@ -77,6 +85,7 @@ pub mod ext {
pub use scale_decode; pub use scale_decode;
pub use scale_encode; pub use scale_encode;
pub use scale_value; pub use scale_value;
pub use subxt_core;
cfg_substrate_compat! { cfg_substrate_compat! {
pub use sp_runtime; pub use sp_runtime;
+1 -1
View File
@@ -64,7 +64,7 @@ macro_rules! cfg_reconnecting_rpc_client {
} }
pub(crate) use { pub(crate) use {
cfg_feature, cfg_jsonrpsee, cfg_reconnecting_rpc_client, cfg_substrate_compat, cfg_feature, cfg_jsonrpsee, cfg_reconnecting_rpc_client,
cfg_unstable_light_client, cfg_unstable_light_client,
}; };
+2 -1
View File
@@ -4,9 +4,10 @@
use super::runtime_types::RuntimeApi; use super::runtime_types::RuntimeApi;
use crate::{backend::BlockRef, client::OnlineClientT, error::Error, Config}; use crate::{backend::BlockRef, client::OnlineClientT, error::Error};
use derivative::Derivative; use derivative::Derivative;
use std::{future::Future, marker::PhantomData}; use std::{future::Future, marker::PhantomData};
use subxt_core::Config;
/// Execute runtime API calls. /// Execute runtime API calls.
#[derive(Derivative)] #[derive(Derivative)]
+1 -1
View File
@@ -6,12 +6,12 @@ use crate::{
backend::{BackendExt, BlockRef}, backend::{BackendExt, BlockRef},
client::OnlineClientT, client::OnlineClientT,
error::{Error, MetadataError}, error::{Error, MetadataError},
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, MetadatExt}; use subxt_core::metadata::{DecodeWithMetadata, MetadatExt};
use subxt_core::Config;
use super::RuntimeApiPayload; use super::RuntimeApiPayload;
+1 -1
View File
@@ -7,10 +7,10 @@ use crate::{
backend::BlockRef, backend::BlockRef,
client::{OfflineClientT, OnlineClientT}, client::{OfflineClientT, OnlineClientT},
error::Error, error::Error,
Config,
}; };
use derivative::Derivative; use derivative::Derivative;
use std::{future::Future, marker::PhantomData}; use std::{future::Future, marker::PhantomData};
use subxt_core::Config;
use subxt_core::{ use subxt_core::{
metadata::MetadatExt, metadata::MetadatExt,
storage::utils::{storage_address_bytes, storage_address_root_bytes, validate_storage_address}, storage::utils::{storage_address_bytes, storage_address_root_bytes, validate_storage_address},
+1 -1
View File
@@ -14,13 +14,13 @@ use crate::{
backend::{BackendExt, BlockRef}, backend::{BackendExt, BlockRef},
client::OnlineClientT, client::OnlineClientT,
error::{Error, MetadataError}, error::{Error, MetadataError},
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; use subxt_core::metadata::DecodeWithMetadata;
use subxt_core::Config;
/// This is returned from a couple of storage functions. /// This is returned from a couple of storage functions.
pub use crate::backend::StreamOfResults; pub use crate::backend::StreamOfResults;
+8 -18
View File
@@ -4,19 +4,20 @@
use std::borrow::Cow; use std::borrow::Cow;
use super::TxProgress;
use crate::{ use crate::{
backend::{BackendExt, BlockRef, TransactionStatus}, backend::{BackendExt, BlockRef, TransactionStatus},
client::{OfflineClientT, OnlineClientT}, client::{OfflineClientT, OnlineClientT},
config::{Config, ExtrinsicParams, ExtrinsicParamsEncoder, Hasher}, error::Error,
error::{Error, MetadataError},
utils::{Encoded, PhantomDataSendSync},
}; };
use codec::{Compact, Decode, Encode}; use codec::{Compact, Decode, Encode};
use derivative::Derivative; use derivative::Derivative;
use sp_core_hashing::blake2_256; use sp_core_hashing::blake2_256;
use subxt_core::{metadata::MetadatExt, tx::TxPayload, Signer as SignerT}; use subxt_core::{
tx::TxPayload,
use super::TxProgress; utils::{Encoded, PhantomDataSendSync},
Config, ExtrinsicParams, ExtrinsicParamsEncoder, Hasher, Signer as SignerT,
};
/// A client for working with transactions. /// A client for working with transactions.
#[derive(Derivative)] #[derive(Derivative)]
@@ -45,18 +46,7 @@ impl<T: Config, C: OfflineClientT<T>> TxClient<T, C> {
where where
Call: TxPayload, Call: TxPayload,
{ {
if let Some(details) = call.validation_details() { call.validate(&self.client.metadata())?;
let expected_hash = self
.client
.metadata()
.pallet_by_name_err(details.pallet_name)?
.call_hash(details.call_name)
.ok_or_else(|| MetadataError::CallNameNotFound(details.call_name.to_owned()))?;
if details.hash != expected_hash {
return Err(MetadataError::IncompatibleCodegen.into());
}
}
Ok(()) Ok(())
} }
+6 -4
View File
@@ -6,16 +6,16 @@
use std::task::Poll; use std::task::Poll;
use crate::utils::strip_compact_prefix;
use crate::{ use crate::{
backend::{BlockRef, StreamOfResults, TransactionStatus as BackendTxStatus}, backend::{BlockRef, StreamOfResults, TransactionStatus as BackendTxStatus},
client::OnlineClientT, client::OnlineClientT,
error::{DispatchError, Error, RpcError, TransactionError}, error::{DispatchError, Error, RpcError, TransactionError},
events::EventsClient, events::EventsClient,
Config,
}; };
use derivative::Derivative; use derivative::Derivative;
use futures::{Stream, StreamExt}; use futures::{Stream, StreamExt};
use subxt_core::utils::strip_compact_prefix;
use subxt_core::Config;
/// This struct represents a subscription to the progress of some transaction. /// This struct represents a subscription to the progress of some transaction.
pub struct TxProgress<T: Config, C> { pub struct TxProgress<T: Config, C> {
@@ -296,7 +296,7 @@ impl<T: Config, C: OnlineClientT<T>> TxInBlock<T, C> {
let extrinsic_idx = block_body let extrinsic_idx = block_body
.iter() .iter()
.position(|ext| { .position(|ext| {
use crate::config::Hasher; use subxt_core::Hasher;
let Ok((_, stripped)) = strip_compact_prefix(ext) else { let Ok((_, stripped)) = strip_compact_prefix(ext) else {
return false; return false;
}; };
@@ -325,9 +325,11 @@ mod test {
backend::{StreamOfResults, TransactionStatus}, backend::{StreamOfResults, TransactionStatus},
client::{OfflineClientT, OnlineClientT}, client::{OfflineClientT, OnlineClientT},
tx::TxProgress, tx::TxProgress,
Config, Error, SubstrateConfig, Error,
}; };
use subxt_core::{Config, SubstrateConfig};
type MockTxProgress = TxProgress<SubstrateConfig, MockClient>; type MockTxProgress = TxProgress<SubstrateConfig, MockClient>;
type MockHash = <SubstrateConfig as Config>::Hash; type MockHash = <SubstrateConfig as Config>::Hash;
type MockSubstrateTxStatus = TransactionStatus<MockHash>; type MockSubstrateTxStatus = TransactionStatus<MockHash>;
+1 -1
View File
@@ -4,7 +4,7 @@
//! Utility functions used in subxt. Reexports all elements from [`subxt_core::utils`]; //! Utility functions used in subxt. Reexports all elements from [`subxt_core::utils`];
pub use subxt_core::utils::*; pub use subxt_core::utils::{strip_compact_prefix, to_hex,UncheckedExtrinsic, AccountId32, MultiAddress, MultiSignature, KeyedVec, Yes, H160, H256, H512, bits };
use url::Url; use url::Url;