From 0a471e20398b4af1873d49338139e783471e5f5c Mon Sep 17 00:00:00 2001 From: Tadeo hepperle Date: Fri, 16 Feb 2024 17:36:14 +0100 Subject: [PATCH] remove capability based approach --- subxt/src/blocks/block_types.rs | 2 - subxt/src/client/client_capabilities.rs | 72 ------------------------- subxt/src/client/mod.rs | 1 - subxt/src/config/extrinsic_params.rs | 3 +- 4 files changed, 2 insertions(+), 76 deletions(-) delete mode 100644 subxt/src/client/client_capabilities.rs diff --git a/subxt/src/blocks/block_types.rs b/subxt/src/blocks/block_types.rs index b7158025b4..a1cb01ec25 100644 --- a/subxt/src/blocks/block_types.rs +++ b/subxt/src/blocks/block_types.rs @@ -167,5 +167,3 @@ where }; Ok(account_nonce) } - -pub struct LatestBlockHeader {} diff --git a/subxt/src/client/client_capabilities.rs b/subxt/src/client/client_capabilities.rs deleted file mode 100644 index a9e9706481..0000000000 --- a/subxt/src/client/client_capabilities.rs +++ /dev/null @@ -1,72 +0,0 @@ -// use crate::{backend::Backend, Config}; - -// use super::OfflineClientT; -use crate::{Config, Error, OfflineClient, OnlineClient}; -use core::future::Future; - -use super::OfflineClientT; - -pub type FetchBlockHeader
= - Box> + Send + 'static>; - -/// An object-safe trait abstracting over capabilities of offline and online-clients. -/// -/// Implemented by [`subxt::OfflineClient`], [`subxt::OnlineClient`] and [`subxt::LightClient`] the like. -pub trait ClientCapabilities { - fn latest_block_header(&self) -> Option> - where - T::Header: Clone; -} - -impl ClientCapabilities for OfflineClient { - fn latest_block_header(&self) -> Option> - where - T::Header: Clone, - { - None - } -} - -impl ClientCapabilities for OnlineClient { - fn latest_block_header(&self) -> Option> - where - T::Header: Clone, - { - let client = self.clone(); - Some(Box::new(async move { - let block = client.blocks().at_latest().await?; - let header: T::Header = block.header().clone(); - Ok(header) - })) - } -} - -crate::macros::cfg_unstable_light_client! { - use super::LightClient; - - impl ClientCapabilities for LightClient { - fn latest_block_header(&self) -> Option> - where - T::Header: Clone, - { - let client = self.clone(); - Some(Box::new(async move { - let block = client.blocks().at_latest().await?; - let header: T::Header = block.header().clone(); - Ok(header) - })) - } - } -} - -#[cfg(test)] -mod tests { - use super::ClientCapabilities; - use crate::PolkadotConfig; - use core::panic; - - fn is_object_safe(client: Box>) { - _ = client.latest_block_header(); - unreachable!("Do not call this function, it just needs to compile.") - } -} diff --git a/subxt/src/client/mod.rs b/subxt/src/client/mod.rs index e3a35dc87a..c764af4b59 100644 --- a/subxt/src/client/mod.rs +++ b/subxt/src/client/mod.rs @@ -8,7 +8,6 @@ //! require network access. The [`OnlineClient`] requires network //! access. -mod client_capabilities; mod offline_client; mod online_client; diff --git a/subxt/src/config/extrinsic_params.rs b/subxt/src/config/extrinsic_params.rs index f8d48c97d7..1d64caedf3 100644 --- a/subxt/src/config/extrinsic_params.rs +++ b/subxt/src/config/extrinsic_params.rs @@ -88,7 +88,7 @@ pub trait DefaultOrFrom { } impl DefaultOrFrom for () { - fn default_or_from(_value: Option<&T>) -> () {} + fn default_or_from(_value: Option<&T>) {} } macro_rules! impl_default_from_tuples { @@ -109,6 +109,7 @@ macro_rules! impl_default_from_tuples { } } +// Note: these implementations are necessary for AnyOf to work properly where arbitrary tuples are the `OtherParams`. #[rustfmt::skip] const _: () = { impl_default_from_tuples!(A);