Files
pezkuwi-subxt/subxt/src/rpc/mod.rs
T
Alexandru Vasile 463e2aa93f rpc: Expose the subscription ID for RpcClientT (#733)
* rpc: Extend `RpcClientT` to return the subscription ID

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

* rpc: Return `RpcSubscriptionId` for jsonrpsee clients

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

* rpc: Expose subscription ID via subxt subscription

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

* examples: Adjust example to return subscription ID

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

* rpc: Add structure for subscription stream and subscription id

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

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
2022-11-25 17:07:26 +02:00

80 lines
2.1 KiB
Rust

// Copyright 2019-2022 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 is used behind the scenes by various `subxt` APIs, but can
//! also be used directly.
//!
//! - [`Rpc`] is the highest level wrapper, and the one you will run into
//! first. It contains the higher level methods for interacting with a node.
//! - [`RpcClient`] is what [`Rpc`] uses to actually talk to a node, offering
//! a [`RpcClient::request`] and [`RpcClient::subscribe`] method to do so.
//! - [`RpcClientT`] is the underlying dynamic RPC implementation. This provides
//! the low level [`RpcClientT::request_raw`] and [`RpcClientT::subscribe_raw`]
//! methods. This can be swapped out for a custom implementation, but by default
//! we'll rely on `jsonrpsee` for this.
//!
//! # Example
//!
//! Fetching storage keys
//!
//! ```no_run
//! use subxt::{ PolkadotConfig, OnlineClient, storage::StorageKey };
//!
//! #[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
//! pub mod polkadot {}
//!
//! # #[tokio::main]
//! # async fn main() {
//! let api = OnlineClient::<PolkadotConfig>::new().await.unwrap();
//!
//! let key = polkadot::storage()
//! .xcm_pallet()
//! .version_notifiers_root()
//! .to_bytes();
//!
//! // Fetch up to 10 keys.
//! let keys = api
//! .rpc()
//! .storage_keys_paged(&key, 10, None, None)
//! .await
//! .unwrap();
//!
//! for key in keys.iter() {
//! println!("Key: 0x{}", hex::encode(&key));
//! }
//! # }
//! ```
// 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;
mod rpc_client;
mod rpc_client_t;
// Expose the `Rpc` struct and any associated types.
pub use rpc::*;
pub use rpc_client_t::{
RawValue,
RpcClientT,
RpcFuture,
RpcSubscription,
RpcSubscriptionId,
RpcSubscriptionStream,
};
pub use rpc_client::{
rpc_params,
RpcClient,
RpcParams,
Subscription,
};