From 451d37b35f014aac214c833fad54293c8962832e Mon Sep 17 00:00:00 2001 From: Tadeo hepperle Date: Tue, 20 Feb 2024 19:39:59 +0100 Subject: [PATCH] minor corrections --- subxt/Cargo.toml | 16 +++++- .../examples/setup_config_signed_extension.rs | 6 +-- subxt/src/blocks/block_types.rs | 2 +- subxt/src/book/setup/config.rs | 6 ++- subxt/src/client/mod.rs | 3 +- subxt/src/config/extrinsic_params.rs | 50 ++++++++++--------- 6 files changed, 50 insertions(+), 33 deletions(-) diff --git a/subxt/Cargo.toml b/subxt/Cargo.toml index 9d0f2afd56..e722bd146b 100644 --- a/subxt/Cargo.toml +++ b/subxt/Cargo.toml @@ -24,11 +24,23 @@ default = ["jsonrpsee", "native"] # Enable this for native (ie non web/wasm builds). # Exactly 1 of "web" and "native" is expected. -native = ["jsonrpsee?/async-client", "jsonrpsee?/client-ws-transport-native-tls", "subxt-lightclient?/native", "tokio-util"] +native = [ + "jsonrpsee?/async-client", + "jsonrpsee?/client-ws-transport-native-tls", + "subxt-lightclient?/native", + "tokio-util" +] # Enable this for web/wasm builds. # Exactly 1 of "web" and "native" is expected. -web = ["jsonrpsee?/async-wasm-client", "jsonrpsee?/client-web-transport", "getrandom/js", "subxt-lightclient?/web", "subxt-macro/web", "instant/wasm-bindgen"] +web = [ + "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 unstable-reconnecting-rpc-client = ["dep:reconnecting-jsonrpsee-ws-client"] diff --git a/subxt/examples/setup_config_signed_extension.rs b/subxt/examples/setup_config_signed_extension.rs index 9012eb67f8..cbc1ba7cd0 100644 --- a/subxt/examples/setup_config_signed_extension.rs +++ b/subxt/examples/setup_config_signed_extension.rs @@ -78,10 +78,10 @@ impl ExtrinsicParamsEncoder for CustomSignedExtension { } // When composing a tuple of signed extensions, the user parameters we need must -// be able to convert `Into` a tuple of corresponding `OtherParams`. Here, we just -// "hijack" the default param builder, but add the `OtherParams` (`()`) for our +// be able to convert `Into` a tuple of corresponding `Params`. Here, we just +// "hijack" the default param builder, but add the `Params` (`()`) for our // new signed extension at the end, to make the types line up. IN reality you may wish -// to construct an entirely new interface to provide the relevant `OtherParams`. +// to construct an entirely new interface to provide the relevant `Params`. pub fn custom( params: DefaultExtrinsicParamsBuilder, ) -> <::ExtrinsicParams as ExtrinsicParams>::Params { diff --git a/subxt/src/blocks/block_types.rs b/subxt/src/blocks/block_types.rs index 9908ca1eee..ad8027c018 100644 --- a/subxt/src/blocks/block_types.rs +++ b/subxt/src/blocks/block_types.rs @@ -66,7 +66,7 @@ where &self.header } - /// Return the entire block header. Consumes the block itself + /// Return the entire block header. Consumes the block. pub fn into_header(self) -> T::Header { self.header } diff --git a/subxt/src/book/setup/config.rs b/subxt/src/book/setup/config.rs index 6e6e811a55..def452214c 100644 --- a/subxt/src/book/setup/config.rs +++ b/subxt/src/book/setup/config.rs @@ -71,8 +71,10 @@ //! //! The `ExtrinsicParams` config type expects to be given an implementation of the [`crate::config::ExtrinsicParams`] trait. //! Implementations of the [`crate::config::ExtrinsicParams`] trait are handed some parameters from Subxt itself, and can -//! accept arbitrary `OtherParams` from users, and are then expected to provide this "extra" and "additional" data when asked -//! via the required [`crate::config::ExtrinsicParamsEncoder`] impl. +//! accept arbitrary `Params` from users, and are then expected to provide this "extra" and "additional" data when asked +//! via the required [`crate::config::ExtrinsicParamsEncoder`] impl. These arbitrary `Params` params must also be constructable by a +//! client with sensible defaults, in case they are not directly provided by a user. They have to implement the [`crate::config::FromBaseParams`] +//! trait to fulfill this requirement. //! //! **In most cases, the default [crate::config::DefaultExtrinsicParams] type will work**: it understands the "standard" //! signed extensions that are in use, and allows the user to provide things like a tip, and set the extrinsic mortality via diff --git a/subxt/src/client/mod.rs b/subxt/src/client/mod.rs index a139fcf2d2..6c14b960b6 100644 --- a/subxt/src/client/mod.rs +++ b/subxt/src/client/mod.rs @@ -27,7 +27,8 @@ pub use online_client::{ use crate::{backend::RuntimeVersion, Config, Metadata}; -/// The inner values, any client should contain. +/// Some inner values any client should contain. +/// In a [`crate::OfflineClient`] these are fixed, while in a [`crate::OnlineClient`] they might get updated over time. #[derive(Derivative)] #[derivative(Debug(bound = ""), Clone(bound = ""))] pub struct BaseClient { diff --git a/subxt/src/config/extrinsic_params.rs b/subxt/src/config/extrinsic_params.rs index 73a8a1ed80..f4bafdb291 100644 --- a/subxt/src/config/extrinsic_params.rs +++ b/subxt/src/config/extrinsic_params.rs @@ -87,8 +87,10 @@ pub struct BaseParams { pub nonce: u64, } -/// Types implementing this trait can be constructed from a minimal set of data provided by the client. +/// Types implementing this trait can be constructed from some minimal data ([`BaseParams`]) provided by the client. /// Implementing this trait is similar to implementing Default, only that we pass in some prior information here. +/// We use this trait to provide defaults for the `Params` associated type of ExtrinsicParams for cases where the `Params` +/// are not specified by the user. pub trait FromBaseParams { /// Constructs the value from the given mandatory params. fn from_base_params(params: &BaseParams) -> Self; @@ -98,7 +100,7 @@ impl FromBaseParams for () { fn from_base_params(_params: &BaseParams) {} } -macro_rules! impl_default_from_tuples { +macro_rules! impl_tuples { ($($ident:ident),+) => { impl FromBaseParams for ($($ident,)+) where @@ -113,28 +115,28 @@ macro_rules! impl_default_from_tuples { } } -// Note: these implementations are necessary, such that `DefaultOrFrom` works with `AnyOf` where arbitrary tuples are the `OtherParams`. +// Note: these implementations are necessary, such that `FromBaseParams` works with `AnyOf` where arbitrary tuples are the `Params`. #[rustfmt::skip] const _: () = { - impl_default_from_tuples!(A); - impl_default_from_tuples!(A, B); - impl_default_from_tuples!(A, B, C); - impl_default_from_tuples!(A, B, C, D); - impl_default_from_tuples!(A, B, C, D, E); - impl_default_from_tuples!(A, B, C, D, E, F); - impl_default_from_tuples!(A, B, C, D, E, F, G); - impl_default_from_tuples!(A, B, C, D, E, F, G, H); - impl_default_from_tuples!(A, B, C, D, E, F, G, H, I); - impl_default_from_tuples!(A, B, C, D, E, F, G, H, I, J); - impl_default_from_tuples!(A, B, C, D, E, F, G, H, I, J, K); - impl_default_from_tuples!(A, B, C, D, E, F, G, H, I, J, K, L); - impl_default_from_tuples!(A, B, C, D, E, F, G, H, I, J, K, L, M); - impl_default_from_tuples!(A, B, C, D, E, F, G, H, I, J, K, L, M, N); - impl_default_from_tuples!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O); - impl_default_from_tuples!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P); - impl_default_from_tuples!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q); - impl_default_from_tuples!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R); - impl_default_from_tuples!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S); - impl_default_from_tuples!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, U); - impl_default_from_tuples!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, U, V); + impl_tuples!(A); + impl_tuples!(A, B); + impl_tuples!(A, B, C); + impl_tuples!(A, B, C, D); + impl_tuples!(A, B, C, D, E); + impl_tuples!(A, B, C, D, E, F); + impl_tuples!(A, B, C, D, E, F, G); + impl_tuples!(A, B, C, D, E, F, G, H); + impl_tuples!(A, B, C, D, E, F, G, H, I); + impl_tuples!(A, B, C, D, E, F, G, H, I, J); + impl_tuples!(A, B, C, D, E, F, G, H, I, J, K); + impl_tuples!(A, B, C, D, E, F, G, H, I, J, K, L); + impl_tuples!(A, B, C, D, E, F, G, H, I, J, K, L, M); + impl_tuples!(A, B, C, D, E, F, G, H, I, J, K, L, M, N); + impl_tuples!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O); + impl_tuples!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P); + impl_tuples!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q); + impl_tuples!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R); + impl_tuples!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S); + impl_tuples!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, U); + impl_tuples!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, U, V); };