Get workspace compiling via 'cargo check'

This commit is contained in:
James Wilson
2025-12-12 12:30:42 +00:00
parent 6215b15fdf
commit 37d4cf7524
35 changed files with 179 additions and 131 deletions
+12 -3
View File
@@ -14,12 +14,15 @@ use crate::view_functions::ViewFunctionsClient;
use core::marker::PhantomData;
use subxt_metadata::Metadata;
pub use offline_client::{OfflineClient, OfflineClientAtBlock, OfflineClientAtBlockT};
pub use offline_client::{OfflineClient, OfflineClientAtBlockImpl, OfflineClientAtBlockT};
pub use online_client::{
BlockNumberOrRef, OnlineClient, OnlineClientAtBlock, OnlineClientAtBlockT,
BlockNumberOrRef, OnlineClient, OnlineClientAtBlockImpl, OnlineClientAtBlockT,
};
/// This represents a client at a specific block number.
/// This represents a client at a specific block number. This wraps a client impl
/// which will either be [`OfflineClientAtBlockImpl`] or [`OnlineClientAtBlockImpl`].
/// Prefer to use the type aliases [`OfflineClientAtBlock`] and [`OnlineClientAtBlock`]
/// if you need to refer to the concrete instances of this.
#[derive(Clone, Debug)]
pub struct ClientAtBlock<T, Client> {
pub(crate) client: Client,
@@ -125,3 +128,9 @@ where
Ok(header)
}
}
/// An offline client at a specific block.
pub type OfflineClientAtBlock<T> = ClientAtBlock<T, OfflineClientAtBlockImpl<T>>;
/// An online client at a specific block.
pub type OnlineClientAtBlock<T> = ClientAtBlock<T, OnlineClientAtBlockImpl<T>>;
+7 -4
View File
@@ -20,7 +20,7 @@ impl<T: Config> OfflineClient<T> {
pub fn at_block(
&self,
block_number: impl Into<u64>,
) -> Result<ClientAtBlock<T, OfflineClientAtBlock<T>>, OfflineClientAtBlockError> {
) -> Result<ClientAtBlock<T, OfflineClientAtBlockImpl<T>>, OfflineClientAtBlockError> {
let block_number = block_number.into();
let (spec_version, transaction_version) = self
.config
@@ -36,7 +36,7 @@ impl<T: Config> OfflineClient<T> {
let hasher = <T::Hasher as Hasher>::new(&metadata);
let offline_client_at_block = OfflineClientAtBlock {
let offline_client_at_block = OfflineClientAtBlockImpl {
metadata,
block_number,
genesis_hash,
@@ -49,8 +49,11 @@ impl<T: Config> OfflineClient<T> {
}
}
/// An implementation of the [`OfflineClientAtBlockT`] trait, which is used in conjunction
/// with [`crate::client::ClientAtBlock`] to provide a working client. You won't tend to need this
/// type and instead should prefer to refer to [`crate::client::OfflineClientAtBlock`].
#[derive(Clone)]
pub struct OfflineClientAtBlock<T: Config> {
pub struct OfflineClientAtBlockImpl<T: Config> {
metadata: ArcMetadata,
block_number: u64,
genesis_hash: Option<HashFor<T>>,
@@ -81,7 +84,7 @@ pub trait OfflineClientAtBlockT<T: Config>: Clone {
fn transaction_version(&self) -> u32;
}
impl<T: Config> OfflineClientAtBlockT<T> for OfflineClientAtBlock<T> {
impl<T: Config> OfflineClientAtBlockT<T> for OfflineClientAtBlockImpl<T> {
fn metadata_ref(&self) -> &Metadata {
&self.metadata
}
+11 -22
View File
@@ -65,10 +65,7 @@ impl<T: Config> OnlineClient<T> {
url: impl AsRef<str>,
) -> Result<OnlineClient<T>, OnlineClientError> {
let url_str = url.as_ref();
let url = url::Url::parse(url_str).map_err(|_| OnlineClientError::InvalidUrl {
url: url_str.to_string(),
})?;
if !Self::is_url_secure(&url) {
if !subxt_rpcs::utils::url_is_secure(url_str).map_err(OnlineClientError::RpcError)? {
return Err(OnlineClientError::RpcError(subxt_rpcs::Error::InsecureUrl(
url_str.to_string(),
)));
@@ -88,16 +85,6 @@ impl<T: Config> OnlineClient<T> {
OnlineClient::from_rpc_client(config, rpc_client).await
}
fn is_url_secure(url: &url::Url) -> bool {
let secure_scheme = url.scheme() == "https" || url.scheme() == "wss";
let is_localhost = url.host().is_some_and(|e| match e {
url::Host::Domain(e) => e == "localhost",
url::Host::Ipv4(e) => e.is_loopback(),
url::Host::Ipv6(e) => e.is_loopback(),
});
secure_scheme || is_localhost
}
/// Construct a new [`OnlineClient`] by providing an [`RpcClient`] to drive the connection.
/// This will use the current default [`Backend`], which may change in future releases.
#[cfg(all(feature = "jsonrpsee", feature = "runtime"))]
@@ -210,7 +197,7 @@ impl<T: Config> OnlineClient<T> {
/// This does not track new blocks.
pub async fn at_current_block(
&self,
) -> Result<ClientAtBlock<T, OnlineClientAtBlock<T>>, OnlineClientAtBlockError> {
) -> Result<ClientAtBlock<T, OnlineClientAtBlockImpl<T>>, OnlineClientAtBlockError> {
let latest_block = self
.inner
.backend
@@ -225,7 +212,7 @@ impl<T: Config> OnlineClient<T> {
pub async fn at_block(
&self,
number_or_hash: impl Into<BlockNumberOrRef<T>>,
) -> Result<ClientAtBlock<T, OnlineClientAtBlock<T>>, OnlineClientAtBlockError> {
) -> Result<ClientAtBlock<T, OnlineClientAtBlockImpl<T>>, OnlineClientAtBlockError> {
let number_or_hash = number_or_hash.into();
// We are given either a block hash or number. We need both.
@@ -274,7 +261,7 @@ impl<T: Config> OnlineClient<T> {
&self,
block_ref: impl Into<BlockRef<HashFor<T>>>,
block_number: u64,
) -> Result<ClientAtBlock<T, OnlineClientAtBlock<T>>, OnlineClientAtBlockError> {
) -> Result<ClientAtBlock<T, OnlineClientAtBlockImpl<T>>, OnlineClientAtBlockError> {
let block_ref = block_ref.into();
let block_hash = block_ref.hash();
@@ -427,7 +414,7 @@ impl<T: Config> OnlineClient<T> {
}
};
let online_client_at_block = OnlineClientAtBlock {
let online_client_at_block = OnlineClientAtBlockImpl {
client: self.clone(),
hasher: <T::Hasher as Hasher>::new(&metadata),
metadata,
@@ -458,9 +445,11 @@ pub trait OnlineClientAtBlockT<T: Config>: OfflineClientAtBlockT<T> {
) -> impl Future<Output = Result<ClientAtBlock<T, Self>, OnlineClientAtBlockError>>;
}
/// The inner type providing the necessary data to work online at a specific block.
/// An implementation of the [`OnlineClientAtBlockImpl`] trait, which is used in conjunction
/// with [`crate::client::ClientAtBlock`] to provide a working client. You won't tend to need this
/// type and instead should prefer to refer to [`crate::client::OnlineClientAtBlock`].
#[derive(Clone)]
pub struct OnlineClientAtBlock<T: Config> {
pub struct OnlineClientAtBlockImpl<T: Config> {
client: OnlineClient<T>,
metadata: ArcMetadata,
hasher: T::Hasher,
@@ -470,7 +459,7 @@ pub struct OnlineClientAtBlock<T: Config> {
transaction_version: u32,
}
impl<T: Config> OnlineClientAtBlockT<T> for OnlineClientAtBlock<T> {
impl<T: Config> OnlineClientAtBlockT<T> for OnlineClientAtBlockImpl<T> {
fn backend(&self) -> &dyn Backend<T> {
&*self.client.inner.backend
}
@@ -485,7 +474,7 @@ impl<T: Config> OnlineClientAtBlockT<T> for OnlineClientAtBlock<T> {
}
}
impl<T: Config> OfflineClientAtBlockT<T> for OnlineClientAtBlock<T> {
impl<T: Config> OfflineClientAtBlockT<T> for OnlineClientAtBlockImpl<T> {
fn metadata_ref(&self) -> &Metadata {
&self.metadata
}
+2 -2
View File
@@ -1,5 +1,5 @@
use crate::backend::{BlockRef, StreamOfResults};
use crate::client::{ClientAtBlock, OnlineClient, OnlineClientAtBlock};
use crate::client::{ClientAtBlock, OnlineClient, OnlineClientAtBlockImpl};
use crate::config::{Config, HashFor, Header};
use crate::error::{BlocksError, OnlineClientAtBlockError};
use futures::{Stream, StreamExt};
@@ -70,7 +70,7 @@ impl<T: Config> Block<T> {
/// Instantiate a client at this block.
pub async fn client(
&self,
) -> Result<ClientAtBlock<T, OnlineClientAtBlock<T>>, OnlineClientAtBlockError> {
) -> Result<ClientAtBlock<T, OnlineClientAtBlockImpl<T>>, OnlineClientAtBlockError> {
self.client.at_block(self.block_ref.clone()).await
}
}
+2 -2
View File
@@ -35,7 +35,7 @@ impl PolkadotConfigBuilder {
/// Set the metadata to be used for decoding blocks at the given spec versions.
pub fn set_metadata_for_spec_versions(
mut self,
ranges: impl Iterator<Item = (u32, ArcMetadata)>,
ranges: impl IntoIterator<Item = (u32, ArcMetadata)>,
) -> Self {
self = Self(self.0.set_metadata_for_spec_versions(ranges));
self
@@ -45,7 +45,7 @@ impl PolkadotConfigBuilder {
/// to this configuration.
pub fn set_spec_version_for_block_ranges(
mut self,
ranges: impl Iterator<Item = SpecVersionForRange>,
ranges: impl IntoIterator<Item = SpecVersionForRange>,
) -> Self {
self = Self(self.0.set_spec_version_for_block_ranges(ranges));
self
+4 -4
View File
@@ -60,10 +60,10 @@ impl SubstrateConfigBuilder {
/// Set the metadata to be used for decoding blocks at the given spec versions.
pub fn set_metadata_for_spec_versions(
self,
ranges: impl Iterator<Item = (u32, ArcMetadata)>,
ranges: impl IntoIterator<Item = (u32, ArcMetadata)>,
) -> Self {
let mut map = self.metadata_for_spec_version.lock().unwrap();
for (spec_version, metadata) in ranges {
for (spec_version, metadata) in ranges.into_iter() {
map.insert(spec_version, metadata);
}
drop(map);
@@ -74,10 +74,10 @@ impl SubstrateConfigBuilder {
/// to this configuration.
pub fn set_spec_version_for_block_ranges(
mut self,
ranges: impl Iterator<Item = SpecVersionForRange>,
ranges: impl IntoIterator<Item = SpecVersionForRange>,
) -> Self {
let mut m = RangeMap::builder();
for version_for_range in ranges {
for version_for_range in ranges.into_iter() {
let start = version_for_range.block_range.start;
let end = version_for_range.block_range.end;
let spec_version = version_for_range.spec_version;
+3 -2
View File
@@ -1,12 +1,13 @@
mod address;
use crate::client::OfflineClientAtBlockT;
use crate::config::Config;
use crate::error::ConstantError;
use address::Address;
use frame_decode::constants::ConstantTypeInfo;
use scale_decode::IntoVisitor;
use std::marker::PhantomData;
pub mod address;
pub use address::{Address, DynamicAddress, StaticAddress, dynamic};
/// A client for working with storage entries.
#[derive(Clone)]
+3 -2
View File
@@ -1,13 +1,14 @@
mod address;
use crate::client::OfflineClientAtBlockT;
use crate::config::Config;
use crate::error::CustomValueError;
use crate::utils::Maybe;
use address::Address;
use derive_where::derive_where;
use frame_decode::custom_values::CustomValueTypeInfo;
use scale_decode::IntoVisitor;
pub mod address;
pub use address::{Address, DynamicAddress, StaticAddress, dynamic};
/// A client for accessing custom values stored in the metadata.
#[derive_where(Clone; Client)]
+1 -3
View File
@@ -4,13 +4,11 @@
//! Construct addresses to access custom values with.
use crate::utils::{Maybe, NoMaybe};
use derive_where::derive_where;
use scale_decode::DecodeAsType;
use std::borrow::Cow;
/// Use this with [`Address::IsDecodable`].
pub use crate::utils::{Maybe, No, NoMaybe};
/// This represents the address of a custom value in the metadata.
/// Anything that implements it can be used to fetch custom values from the metadata.
/// The trait is implemented by [`str`] for dynamic lookup and [`StaticAddress`] for static queries.
+7 -6
View File
@@ -7,19 +7,20 @@
pub use scale_value::{At, Value, value};
// Submit dynamic transactions.
pub use crate::transactions::payload::dynamic as transaction;
pub use crate::transactions::dynamic as transaction;
pub use crate::transactions::dynamic as tx;
// Lookup constants dynamically.
pub use crate::constants::address::dynamic as constant;
pub use crate::constants::dynamic as constant;
// Lookup storage values dynamically.
pub use crate::storage::address::dynamic as storage;
pub use crate::storage::dynamic as storage;
// Execute runtime API function call dynamically.
pub use crate::runtime_apis::payload::dynamic as runtime_api_call;
pub use crate::runtime_apis::dynamic as runtime_api_call;
// Execute View Function API function call dynamically.
pub use crate::view_functions::payload::dynamic as view_function_call;
pub use crate::view_functions::dynamic as view_function_call;
/// Obtain a custom value from the metadata.
pub use crate::custom_values::address::dynamic as custom_value;
pub use crate::custom_values::dynamic as custom_value;
+8 -2
View File
@@ -47,17 +47,23 @@ pub mod dynamic;
pub mod error;
pub mod events;
pub mod extrinsics;
pub mod metadata;
pub mod runtime_apis;
pub mod storage;
pub mod transactions;
pub mod utils;
pub mod view_functions;
// Re-export the [`subxt_metadata`] crate.
pub use subxt_metadata as metadata;
// A shorthand to match previous versions and the
// tx shorthand in other places.
pub use transactions as tx;
// Expose a few of the most common types at root,
// but leave most types behind their respective modules.
pub use crate::{
client::{OfflineClient, OnlineClient},
client::{OfflineClient, OfflineClientAtBlock, OnlineClient, OnlineClientAtBlock},
config::{Config, PolkadotConfig, SubstrateConfig},
error::Error,
metadata::{ArcMetadata, Metadata},
-7
View File
@@ -1,7 +0,0 @@
use std::sync::Arc;
// Re-export everything from subxt-metadata here.
pub use subxt_metadata::*;
/// A cheaply clonable version of our [`Metadata`].
pub type ArcMetadata = Arc<Metadata>;
+3 -2
View File
@@ -2,15 +2,16 @@
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.
mod payload;
use crate::client::{OfflineClientAtBlockT, OnlineClientAtBlockT};
use crate::config::Config;
use crate::error::RuntimeApiError;
use derive_where::derive_where;
use payload::Payload;
use scale_decode::IntoVisitor;
use std::marker::PhantomData;
pub mod payload;
pub use payload::{DynamicPayload, Payload, StaticPayload, dynamic};
/// Execute runtime API calls.
#[derive_where(Clone; Client)]
+2 -2
View File
@@ -1,3 +1,4 @@
mod address;
mod prefix_of;
mod storage_entry;
mod storage_key;
@@ -8,18 +9,17 @@ use crate::backend::BackendExt;
use crate::client::{OfflineClientAtBlockT, OnlineClientAtBlockT};
use crate::config::Config;
use crate::error::StorageError;
use address::Address;
use core::marker::PhantomData;
use frame_decode::helpers::Entry;
use frame_decode::storage::StorageEntryInfo;
use std::borrow::Cow;
pub use address::{Address, DynamicAddress, StaticAddress, dynamic};
pub use prefix_of::PrefixOf;
pub use storage_entry::StorageEntry;
pub use storage_key::{StorageKey, StorageKeyPart};
pub use storage_key_value::StorageKeyValue;
pub use storage_value::StorageValue;
pub mod address;
/// A client for working with storage entries.
#[derive(Clone)]
+2 -3
View File
@@ -1,11 +1,10 @@
mod account_nonce;
mod default_params;
mod payload;
mod signer;
mod transaction_progress;
mod validation_result;
pub mod payload;
use crate::backend::{BackendExt, TransactionStatus as BackendTransactionStatus};
use crate::client::{OfflineClientAtBlockT, OnlineClientAtBlockT};
use crate::config::extrinsic_params::Params;
@@ -20,7 +19,7 @@ use sp_crypto_hashing::blake2_256;
use std::borrow::Cow;
pub use default_params::DefaultParams;
pub use payload::Payload;
pub use payload::{DynamicPayload, Payload, StaticPayload, dynamic};
pub use signer::Signer;
pub use transaction_progress::{TransactionProgress, TransactionStatus};
pub use validation_result::{
+3 -2
View File
@@ -2,15 +2,16 @@
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.
mod payload;
use crate::client::{OfflineClientAtBlockT, OnlineClientAtBlockT};
use crate::config::Config;
use crate::error::ViewFunctionError;
use derive_where::derive_where;
use payload::Payload;
use scale_decode::IntoVisitor;
use std::marker::PhantomData;
pub mod payload;
pub use payload::{DynamicPayload, Payload, StaticPayload, dynamic};
/// The name of the Runtime API call which can execute
const CALL_NAME: &str = "RuntimeViewFunction_execute_view_function";