From b27b7c8bd9674b2e3ab4539317ba82035f87b6e7 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 10 Jan 2024 19:27:00 +0200 Subject: [PATCH] lightclient: Make `AddedChain` generic over the `PlatformRef` Signed-off-by: Alexandru Vasile --- lightclient/src/background.rs | 2 +- lightclient/src/client.rs | 6 +++--- lightclient/src/platform/mod.rs | 2 +- subxt/src/client/light_client/builder.rs | 17 +++++++---------- subxt/src/client/light_client/mod.rs | 2 +- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/lightclient/src/background.rs b/lightclient/src/background.rs index 1e34596d9e..246368abac 100644 --- a/lightclient/src/background.rs +++ b/lightclient/src/background.rs @@ -317,7 +317,7 @@ impl BackgroundTask { pub async fn start_task( &mut self, from_subxt: mpsc::UnboundedReceiver, - from_node: Vec, + from_node: Vec>, ) { let from_subxt_event = tokio_stream::wrappers::UnboundedReceiverStream::new(from_subxt); diff --git a/lightclient/src/client.rs b/lightclient/src/client.rs index 0269986384..b3f452efdd 100644 --- a/lightclient/src/client.rs +++ b/lightclient/src/client.rs @@ -123,7 +123,7 @@ impl LightClientRpc { /// https://docs.rs/wasm-bindgen-futures/latest/wasm_bindgen_futures/fn.future_to_promise.html. pub fn new_from_client( client: smoldot_light::Client, - chains: impl IntoIterator, + chains: impl IntoIterator>, ) -> RawLightClientRpc where TPlat: smoldot_light::platform::PlatformRef + Clone, @@ -202,9 +202,9 @@ impl LightClientRpc { } /// The added chain of the light-client. -pub struct AddedChain { +pub struct AddedChain { /// The id of the chain. pub chain_id: smoldot_light::ChainId, /// Producer of RPC responses for the chain. - pub rpc_responses: smoldot_light::JsonRpcResponses, + pub rpc_responses: smoldot_light::JsonRpcResponses, } diff --git a/lightclient/src/platform/mod.rs b/lightclient/src/platform/mod.rs index 7a1182da66..bfba17c029 100644 --- a/lightclient/src/platform/mod.rs +++ b/lightclient/src/platform/mod.rs @@ -11,7 +11,7 @@ mod wasm_platform; #[cfg(feature = "web")] mod wasm_socket; -pub use helpers::build_platform; +pub use helpers::{build_platform, PlatformType}; #[cfg(feature = "native")] mod helpers { diff --git a/subxt/src/client/light_client/builder.rs b/subxt/src/client/light_client/builder.rs index cc576a2d96..3099e13f31 100644 --- a/subxt/src/client/light_client/builder.rs +++ b/subxt/src/client/light_client/builder.rs @@ -185,19 +185,19 @@ impl LightClientBuilder { } /// Raw builder for [`RawLightClient`]. -pub struct RawLightClientBuilder { - chains: Vec, +pub struct RawLightClientBuilder { + chains: Vec>, } -impl Default for RawLightClientBuilder { +impl Default for RawLightClientBuilder { fn default() -> Self { Self { chains: Vec::new() } } } -impl RawLightClientBuilder { +impl RawLightClientBuilder { /// Create a new [`RawLightClientBuilder`]. - pub fn new() -> RawLightClientBuilder { + pub fn new() -> RawLightClientBuilder { RawLightClientBuilder::default() } @@ -205,7 +205,7 @@ impl RawLightClientBuilder { pub fn add_chain( mut self, chain_id: smoldot::ChainId, - rpc_responses: smoldot::JsonRpcResponses, + rpc_responses: smoldot::JsonRpcResponses, ) -> Self { self.chains.push(AddedChain { chain_id, @@ -218,10 +218,7 @@ impl RawLightClientBuilder { /// /// The provided `chain_id` is the chain with which the current instance of light client will interact. /// To target a different chain call the [`LightClient::target_chain`] method. - pub async fn build( - self, - client: smoldot::Client, - ) -> Result { + pub async fn build(self, client: smoldot::Client) -> Result { // The raw subxt light client that spawns the smoldot background task. let raw_rpc: subxt_lightclient::RawLightClientRpc = subxt_lightclient::LightClientRpc::new_from_client(client, self.chains.into_iter()); diff --git a/subxt/src/client/light_client/mod.rs b/subxt/src/client/light_client/mod.rs index a4b116652e..76264e93f0 100644 --- a/subxt/src/client/light_client/mod.rs +++ b/subxt/src/client/light_client/mod.rs @@ -75,7 +75,7 @@ impl RawLightClient { /// # Note /// /// If you are unsure, please use [`LightClient::builder`] instead. - pub fn builder() -> RawLightClientBuilder { + pub fn builder() -> RawLightClientBuilder { RawLightClientBuilder::default() }