From 2efdef1995ea2aebc4d3380a8526b8806a45653e Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 18 May 2023 20:05:42 +0300 Subject: [PATCH] subxt: Expose light client under experimental feature-flag Signed-off-by: Alexandru Vasile --- Cargo.toml | 5 +++++ subxt/Cargo.toml | 16 ++++++++++++++++ subxt/src/rpc/mod.rs | 6 ++++++ 3 files changed, 27 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 11b454baa3..4a1523cc9b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -73,6 +73,11 @@ wabt = "0.10.0" wasm-bindgen-test = "0.3.24" which = "4.4.0" +# Light client support: +smoldot-light = { git = "https://github.com/smol-dot/smoldot.git", default-features = false } +tokio-stream = "0.1.14" +futures-util = "0.3.28" + # Substrate crates: sp-core = { version = "20.0.0", default-features = false } sp-core-hashing = "8.0.0" diff --git a/subxt/Cargo.toml b/subxt/Cargo.toml index f32ce34947..a85a52b681 100644 --- a/subxt/Cargo.toml +++ b/subxt/Cargo.toml @@ -40,6 +40,16 @@ jsonrpsee-web = ["jsonrpsee/async-wasm-client", "jsonrpsee/client-web-transport" # latest features exposed by the metadata. unstable-metadata = [] +# Activate this to expose the Light Client functionality. +# Note that this feature is experimental and things may break or not work as expected. +experimental-light-client = [ + "smoldot-light/std", + "tokio-stream", + "tokio/sync", + "tokio/rt", + "futures-util", +] + [dependencies] codec = { package = "parity-scale-codec", workspace = true, features = ["derive"] } scale-info = { workspace = true } @@ -78,6 +88,12 @@ sp-runtime = { workspace = true, optional = true } subxt-macro = { workspace = true } subxt-metadata = { workspace = true } +# Light client support: +smoldot-light = { workspace = true, optional = true } +tokio = { workspace = true, optional = true } +tokio-stream = { workspace = true, optional = true } +futures-util = { workspace = true, optional = true } + [target.wasm32-unknown-unknown.dependencies] getrandom = { workspace = true, features = ["js"] } diff --git a/subxt/src/rpc/mod.rs b/subxt/src/rpc/mod.rs index 2254db313c..b520bd2eb8 100644 --- a/subxt/src/rpc/mod.rs +++ b/subxt/src/rpc/mod.rs @@ -47,6 +47,9 @@ #[cfg(feature = "jsonrpsee")] mod jsonrpsee_impl; +#[cfg(feature = "experimental-light-client")] +mod lightclient; + mod rpc; mod rpc_client; mod rpc_client_t; @@ -62,3 +65,6 @@ pub use rpc_client_t::{ }; pub use rpc_client::{rpc_params, RpcClient, RpcParams, Subscription}; + +#[cfg(feature = "experimental-light-client")] +pub use lightclient::{LightClient, LightClientError};