mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 04:01:10 +00:00
Introduce Backend trait to allow different RPC (or other) backends to be implemented (#1126)
* WIP backend trait * WIP converting higher level stuff to using Backend impl * more implementing new backend trait, mainly storage focused * Get core code compiling with new backend bits * subxt crate checks passing * fix tests * cargo fmt * clippy/fixes * merging and other fixes * fix test * fix lightclient code * Fix some broken doc links * another book link fix * fix broken test when moving default_rpc_client * fix dry_run test * fix more tests; lightclient and wasm * fix wasm tests * fix some doc examples * use next() instead of next_item() * missing next_item() -> next()s * move legacy RPc methods to LegacyRpcMethods type to host generic param instead of RpcClient * standardise on all RpcClient types prefixed with Rpc, and 'raw' trait types prefixed with RawRpc so it's less ocnfusing which is which * rename fixes * doc fixes * Add back system_dryRun RPC method and rename tx.dry_run() to tx.validate(), to signal that the calls are different * Add a test that we return the correct extrinsic hash from submit() * add TransactionValid details back, and protect against out of range bytes * add test for decoding transaction validation from empty bytes * fix clippy warning
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
// 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.
|
||||
|
||||
//! RPC types and client for interacting with a substrate node.
|
||||
//!
|
||||
//! These are used behind the scenes by Subxt backend implementations, for
|
||||
//! example [`crate::backend::legacy::LegacyBackend`]. If you need an RPC client,
|
||||
//! then you can manually instantiate one, and then hand it to Subxt if you'd like
|
||||
//! to re-use it for the Subxt connection.
|
||||
//!
|
||||
//! - [`RpcClientT`] is the underlying dynamic RPC implementation. This provides
|
||||
//! the low level [`RpcClientT::request_raw`] and [`RpcClientT::subscribe_raw`]
|
||||
//! methods.
|
||||
//! - [`RpcClient`] is the higher level wrapper around this, offering
|
||||
//! the [`RpcClient::request`] and [`RpcClient::subscribe`] methods.
|
||||
//!
|
||||
//! # Example
|
||||
//!
|
||||
//! Fetching the genesis hash.
|
||||
//!
|
||||
//! ```no_run
|
||||
//! # #[tokio::main]
|
||||
//! # async fn main() {
|
||||
//! use subxt::{
|
||||
//! client::OnlineClient,
|
||||
//! config::SubstrateConfig,
|
||||
//! backend::rpc::RpcClient,
|
||||
//! backend::legacy::LegacyRpcMethods,
|
||||
//! };
|
||||
//!
|
||||
//! // Instantiate a default RPC client pointing at some URL.
|
||||
//! let rpc_client = RpcClient::from_url("ws://localhost:9944")
|
||||
//! .await
|
||||
//! .unwrap();
|
||||
//!
|
||||
//! // Instantiate the legacy RPC interface, providing an appropriate
|
||||
//! // config so that it uses the correct types for your chain.
|
||||
//! let rpc_methods = LegacyRpcMethods::<SubstrateConfig>::new(rpc_client.clone());
|
||||
//!
|
||||
//! // Use it to make RPC calls, here using the legacy genesis_hash method.
|
||||
//! let genesis_hash = rpc_methods
|
||||
//! .genesis_hash()
|
||||
//! .await
|
||||
//! .unwrap();
|
||||
//!
|
||||
//! println!("{genesis_hash}");
|
||||
//!
|
||||
//! // Instantiate the Subxt interface using the same client and config if you
|
||||
//! // want to reuse the same connection:
|
||||
//! let client = OnlineClient::<SubstrateConfig>::from_rpc_client(rpc_client);
|
||||
//! # }
|
||||
//! ```
|
||||
|
||||
// Allow an `rpc.rs` file in the `rpc` folder to align better
|
||||
// with other file names for their types.
|
||||
#![allow(clippy::module_inception)]
|
||||
|
||||
#[cfg(feature = "jsonrpsee")]
|
||||
mod jsonrpsee_impl;
|
||||
|
||||
mod rpc_client;
|
||||
mod rpc_client_t;
|
||||
|
||||
pub use rpc_client_t::{RawRpcFuture, RawRpcSubscription, RawValue, RpcClientT};
|
||||
|
||||
pub use rpc_client::{rpc_params, RpcClient, RpcParams, RpcSubscription};
|
||||
Reference in New Issue
Block a user