mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 16:51:03 +00:00
lightclient: Add generic platform for AddedChain
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
@@ -314,10 +314,10 @@ impl<TPlatform: PlatformRef, TChain> BackgroundTask<TPlatform, TChain> {
|
|||||||
/// Perform the main background task:
|
/// Perform the main background task:
|
||||||
/// - receiving requests from subxt RPC method / subscriptions
|
/// - receiving requests from subxt RPC method / subscriptions
|
||||||
/// - provides the results from the light client back to users.
|
/// - provides the results from the light client back to users.
|
||||||
pub async fn start_task(
|
pub async fn start_task<TPlat: smoldot_light::platform::PlatformRef>(
|
||||||
&mut self,
|
&mut self,
|
||||||
from_subxt: mpsc::UnboundedReceiver<FromSubxt>,
|
from_subxt: mpsc::UnboundedReceiver<FromSubxt>,
|
||||||
from_node: Vec<AddedChain>,
|
from_node: Vec<AddedChain<TPlat>>,
|
||||||
) {
|
) {
|
||||||
let from_subxt_event = tokio_stream::wrappers::UnboundedReceiverStream::new(from_subxt);
|
let from_subxt_event = tokio_stream::wrappers::UnboundedReceiverStream::new(from_subxt);
|
||||||
|
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ impl LightClientRpc {
|
|||||||
/// https://docs.rs/wasm-bindgen-futures/latest/wasm_bindgen_futures/fn.future_to_promise.html.
|
/// https://docs.rs/wasm-bindgen-futures/latest/wasm_bindgen_futures/fn.future_to_promise.html.
|
||||||
pub fn new_from_client<TPlat>(
|
pub fn new_from_client<TPlat>(
|
||||||
client: smoldot_light::Client<TPlat>,
|
client: smoldot_light::Client<TPlat>,
|
||||||
chains: impl IntoIterator<Item = AddedChain>,
|
chains: impl IntoIterator<Item = AddedChain<TPlat>>,
|
||||||
) -> RawLightClientRpc
|
) -> RawLightClientRpc
|
||||||
where
|
where
|
||||||
TPlat: smoldot_light::platform::PlatformRef + Clone,
|
TPlat: smoldot_light::platform::PlatformRef + Clone,
|
||||||
@@ -202,9 +202,9 @@ impl LightClientRpc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The added chain of the light-client.
|
/// The added chain of the light-client.
|
||||||
pub struct AddedChain {
|
pub struct AddedChain<TPlat: smoldot_light::platform::PlatformRef> {
|
||||||
/// The id of the chain.
|
/// The id of the chain.
|
||||||
pub chain_id: smoldot_light::ChainId,
|
pub chain_id: smoldot_light::ChainId,
|
||||||
/// Producer of RPC responses for the chain.
|
/// Producer of RPC responses for the chain.
|
||||||
pub rpc_responses: smoldot_light::JsonRpcResponses,
|
pub rpc_responses: smoldot_light::JsonRpcResponses<TPlat>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -186,19 +186,19 @@ impl<T: Config> LightClientBuilder<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Raw builder for [`RawLightClient`].
|
/// Raw builder for [`RawLightClient`].
|
||||||
pub struct RawLightClientBuilder {
|
pub struct RawLightClientBuilder<TPlatform: smoldot::PlatformRef> {
|
||||||
chains: Vec<AddedChain>,
|
chains: Vec<AddedChain<TPlatform>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for RawLightClientBuilder {
|
impl<TPlatform: smoldot::PlatformRef> Default for RawLightClientBuilder<TPlatform> {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self { chains: Vec::new() }
|
Self { chains: Vec::new() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RawLightClientBuilder {
|
impl<TPlatform: smoldot::PlatformRef> RawLightClientBuilder<TPlatform> {
|
||||||
/// Create a new [`RawLightClientBuilder`].
|
/// Create a new [`RawLightClientBuilder`].
|
||||||
pub fn new() -> RawLightClientBuilder {
|
pub fn new() -> RawLightClientBuilder<TPlatform> {
|
||||||
RawLightClientBuilder::default()
|
RawLightClientBuilder::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,7 +206,7 @@ impl RawLightClientBuilder {
|
|||||||
pub fn add_chain(
|
pub fn add_chain(
|
||||||
mut self,
|
mut self,
|
||||||
chain_id: smoldot::ChainId,
|
chain_id: smoldot::ChainId,
|
||||||
rpc_responses: smoldot::JsonRpcResponses,
|
rpc_responses: smoldot::JsonRpcResponses<TPlatform>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.chains.push(AddedChain {
|
self.chains.push(AddedChain {
|
||||||
chain_id,
|
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.
|
/// 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.
|
/// To target a different chain call the [`LightClient::target_chain`] method.
|
||||||
pub async fn build<TPlatform: smoldot::PlatformRef>(
|
pub async fn build(self, client: smoldot::Client<TPlatform>) -> Result<RawLightClient, Error> {
|
||||||
self,
|
|
||||||
client: smoldot::Client<TPlatform>,
|
|
||||||
) -> Result<RawLightClient, Error> {
|
|
||||||
// The raw subxt light client that spawns the smoldot background task.
|
// The raw subxt light client that spawns the smoldot background task.
|
||||||
let raw_rpc: subxt_lightclient::RawLightClientRpc =
|
let raw_rpc: subxt_lightclient::RawLightClientRpc =
|
||||||
subxt_lightclient::LightClientRpc::new_from_client(client, self.chains.into_iter());
|
subxt_lightclient::LightClientRpc::new_from_client(client, self.chains.into_iter());
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ impl RawLightClient {
|
|||||||
/// # Note
|
/// # Note
|
||||||
///
|
///
|
||||||
/// If you are unsure, please use [`LightClient::builder`] instead.
|
/// If you are unsure, please use [`LightClient::builder`] instead.
|
||||||
pub fn builder() -> RawLightClientBuilder {
|
pub fn builder<TPlatform: smoldot::PlatformRef>() -> RawLightClientBuilder<TPlatform> {
|
||||||
RawLightClientBuilder::default()
|
RawLightClientBuilder::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user