From ab0f67f5e7f0fcfb15b18ea853a6f66ad5e75dbb Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Fri, 26 Jan 2024 15:05:37 +0200 Subject: [PATCH] lightclient: Add generic platform for AddedChain Signed-off-by: Alexandru Vasile --- lightclient/src/background.rs | 4 ++-- lightclient/src/client.rs | 6 +++--- subxt/src/client/light_client/builder.rs | 17 +++++++---------- subxt/src/client/light_client/mod.rs | 2 +- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/lightclient/src/background.rs b/lightclient/src/background.rs index 1e34596d9e..66cbcbc1c5 100644 --- a/lightclient/src/background.rs +++ b/lightclient/src/background.rs @@ -314,10 +314,10 @@ impl BackgroundTask { /// Perform the main background task: /// - receiving requests from subxt RPC method / subscriptions /// - provides the results from the light client back to users. - pub async fn start_task( + 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..db515c774d 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/subxt/src/client/light_client/builder.rs b/subxt/src/client/light_client/builder.rs index 2733fd4bb4..8553cedea4 100644 --- a/subxt/src/client/light_client/builder.rs +++ b/subxt/src/client/light_client/builder.rs @@ -186,19 +186,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() } @@ -206,7 +206,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, @@ -219,10 +219,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() }