diff --git a/new/src/client.rs b/new/src/client.rs index 11e01e3897..cfcc2eade0 100644 --- a/new/src/client.rs +++ b/new/src/client.rs @@ -6,13 +6,8 @@ use crate::transactions::Transactions; use core::marker::PhantomData; use subxt_metadata::Metadata; -// We keep these traits internal, so that we can mess with them later if needed, -// and instead only the concrete types are public which wrap these trait impls. -pub(crate) use offline_client::OfflineClientAtBlockT; -pub(crate) use online_client::OnlineClientAtBlockT; - -pub use offline_client::{OfflineClient, OfflineClientAtBlock}; -pub use online_client::{OnlineClient, OnlineClientAtBlock}; +pub use offline_client::{OfflineClient, OfflineClientAtBlock, OfflineClientAtBlockT}; +pub use online_client::{OnlineClient, OnlineClientAtBlock, OnlineClientAtBlockT}; /// This represents a client at a specific block number. #[derive(Clone, Debug)] diff --git a/new/src/client/online_client.rs b/new/src/client/online_client.rs index 394aa75cbc..57156460f9 100644 --- a/new/src/client/online_client.rs +++ b/new/src/client/online_client.rs @@ -9,8 +9,8 @@ use crate::error::{BlocksError, OnlineClientAtBlockError}; use blocks::Blocks; use codec::{Compact, Decode, Encode}; use core::marker::PhantomData; -use frame_metadata::{RuntimeMetadata, RuntimeMetadataPrefixed}; use frame_decode::helpers::ToTypeRegistry; +use frame_metadata::{RuntimeMetadata, RuntimeMetadataPrefixed}; use scale_info_legacy::TypeRegistrySet; use std::sync::Arc; use subxt_metadata::Metadata; @@ -260,6 +260,22 @@ impl OnlineClient { (block_ref, block_number) } }; + + self.at_block_hash_and_number(block_ref, block_number).await + } + + /// Instantiate a client for working at a specific block. This takes a block hash/ref _and_ the + /// corresponding block number. When both are available, this saves an RPC call to obtain one from + /// the other. + /// + /// **Warning:** If the block hash and number do not align, then things will go wrong. Prefer to + /// use [`Self::at_block`] if in any doubt. + pub async fn at_block_hash_and_number( + &self, + block_ref: impl Into>>, + block_number: u64, + ) -> Result, T>, OnlineClientAtBlockError> { + let block_ref = block_ref.into(); let block_hash = block_ref.hash(); // Obtain the spec version so that we know which metadata to use at this block. diff --git a/new/src/error.rs b/new/src/error.rs index df3d273d20..9fd8d3d484 100644 --- a/new/src/error.rs +++ b/new/src/error.rs @@ -362,7 +362,7 @@ pub enum OnlineClientAtBlockError { metadata_version: u32, /// Reason the conversion failed. reason: subxt_metadata::TryFromError, - }, + }, #[error( "Cannot construct OnlineClientAtBlock: cannot inject types from metadata: failure to parse a type found in the metadata: {parse_error}" )]