Files
pezkuwi-subxt/lightclient/src/shared_client.rs
T
Alexandru Vasile 1cf206f671 chore(deps): Update smoldot to the latest version (#1400)
* Update smoldot to 0.17 and smoldot-light to 0.15

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update cargo lock

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* lightclient: Add generic platform for AddedChain

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* debug: Finalized heads

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* lightclient: Use generic TPlat for chainSuccess

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* lightclient: Trim response for logs

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Backup

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* tests/lightclient: Switch to localnode for testing

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* cargo: Point smoldot to crates.io

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Solve merge conflicts

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Add subxt macro for tests

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* lightclient/wasm: Impl log of the PlatformRef

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Use git dep

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Revert "tests/lightclient: Switch to localnode for testing" + max log
size

This reverts commit 74dd9d7cff.

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* tests: Comment chainspec

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* lightclient/wasm: Import IpAddr from core::net

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* tests: Enable all tests again

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* tests/wasm: Update cargo lock

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* tests: Add trace logs to easily reproduce problems

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* cargo: Use released smoldot version

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* lightclient: Use chainspec and optionally make use of unstable backend

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* lightclient: Fix clippy

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* lightclient: Better trimming for log messages

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* lightclient: Remove max log size

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* lightclient: Use both backends for testing

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update Cargo.toml

Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>

* Update Cargo.toml

Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>

* Update testing/integration-tests/src/light_client/mod.rs

* Update testing/integration-tests/src/light_client/mod.rs

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
2024-09-09 10:30:51 +03:00

48 lines
1.5 KiB
Rust

// Copyright 2019-2023 Parity Technologies (UK) Ltd.
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.
use smoldot_light as sl;
use std::sync::{Arc, Mutex};
/// This wraps [`smoldot_light::Client`] so that it can be cloned and shared.
#[derive(Clone)]
pub struct SharedClient<TPlat: sl::platform::PlatformRef, TChain = ()> {
client: Arc<Mutex<sl::Client<TPlat, TChain>>>,
}
impl<TPlat: sl::platform::PlatformRef, TChain> From<sl::Client<TPlat, TChain>>
for SharedClient<TPlat, TChain>
{
fn from(client: sl::Client<TPlat, TChain>) -> Self {
SharedClient {
client: Arc::new(Mutex::new(client)),
}
}
}
impl<TPlat: sl::platform::PlatformRef, TChain> SharedClient<TPlat, TChain> {
/// Delegates to [`smoldot_light::Client::json_rpc_request()`].
pub(crate) fn json_rpc_request(
&self,
json_rpc_request: impl Into<String>,
chain_id: sl::ChainId,
) -> Result<(), sl::HandleRpcError> {
self.client
.lock()
.expect("mutex should not be poisoned")
.json_rpc_request(json_rpc_request, chain_id)
}
/// Delegates to [`smoldot_light::Client::add_chain()`].
pub(crate) fn add_chain(
&self,
config: sl::AddChainConfig<'_, TChain, impl Iterator<Item = sl::ChainId>>,
) -> Result<sl::AddChainSuccess<TPlat>, sl::AddChainError> {
self.client
.lock()
.expect("mutex should not be poisoned")
.add_chain(config)
}
}