mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-21 01:41:03 +00:00
Extract RPC definitions from RPC crate. (#3502)
* Extract author API from the substrate-rpc crate. * Split out API from RPC. * Clean up naming. * Fix tests. * Shorten error translations. * Update Cargo.lock
This commit is contained in:
committed by
Svyatoslav Nikolsky
parent
4ff97bd856
commit
98f64b6b93
Generated
+29
-12
@@ -4972,31 +4972,48 @@ name = "substrate-rpc"
|
|||||||
version = "2.0.0"
|
version = "2.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"assert_matches 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"assert_matches 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"derive_more 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)",
|
"futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"futures-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
"futures-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"jsonrpc-core 13.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"jsonrpc-core 13.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"jsonrpc-pubsub 13.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"parity-scale-codec 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"sr-io 2.0.0",
|
||||||
|
"sr-primitives 2.0.0",
|
||||||
|
"sr-version 2.0.0",
|
||||||
|
"substrate-client 2.0.0",
|
||||||
|
"substrate-executor 2.0.0",
|
||||||
|
"substrate-keystore 2.0.0",
|
||||||
|
"substrate-network 2.0.0",
|
||||||
|
"substrate-primitives 2.0.0",
|
||||||
|
"substrate-rpc-api 2.0.0",
|
||||||
|
"substrate-session 2.0.0",
|
||||||
|
"substrate-state-machine 2.0.0",
|
||||||
|
"substrate-test-runtime-client 2.0.0",
|
||||||
|
"substrate-transaction-pool 2.0.0",
|
||||||
|
"tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "substrate-rpc-api"
|
||||||
|
version = "2.0.0"
|
||||||
|
dependencies = [
|
||||||
|
"derive_more 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"futures-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"jsonrpc-core 13.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"jsonrpc-core-client 13.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"jsonrpc-core-client 13.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"jsonrpc-derive 13.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"jsonrpc-derive 13.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"jsonrpc-pubsub 13.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"jsonrpc-pubsub 13.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"parity-scale-codec 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"parity-scale-codec 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"sr-io 2.0.0",
|
|
||||||
"sr-primitives 2.0.0",
|
|
||||||
"sr-version 2.0.0",
|
"sr-version 2.0.0",
|
||||||
"substrate-client 2.0.0",
|
|
||||||
"substrate-keystore 2.0.0",
|
|
||||||
"substrate-network 2.0.0",
|
|
||||||
"substrate-primitives 2.0.0",
|
"substrate-primitives 2.0.0",
|
||||||
"substrate-session 2.0.0",
|
"substrate-transaction-graph 2.0.0",
|
||||||
"substrate-state-machine 2.0.0",
|
|
||||||
"substrate-test-runtime-client 2.0.0",
|
|
||||||
"substrate-transaction-pool 2.0.0",
|
|
||||||
"tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -5,32 +5,28 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
|||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
derive_more = "0.14.0"
|
api = { package = "substrate-rpc-api", path = "./api" }
|
||||||
futures = "0.1"
|
|
||||||
futures03 = { package = "futures-preview", version = "0.3.0-alpha.17", features = ["compat"] }
|
|
||||||
jsonrpc-core = "13.1.0"
|
|
||||||
jsonrpc-core-client = "13.1.0"
|
|
||||||
jsonrpc-pubsub = "13.1.0"
|
|
||||||
jsonrpc-derive = "13.1.0"
|
|
||||||
log = "0.4"
|
|
||||||
parking_lot = "0.9.0"
|
|
||||||
codec = { package = "parity-scale-codec", version = "1.0.0" }
|
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
|
||||||
serde_json = "1.0"
|
|
||||||
client = { package = "substrate-client", path = "../client" }
|
client = { package = "substrate-client", path = "../client" }
|
||||||
network = { package = "substrate-network", path = "../network" }
|
codec = { package = "parity-scale-codec", version = "1.0.0" }
|
||||||
|
futures03 = { package = "futures-preview", version = "0.3.0-alpha.17", features = ["compat"] }
|
||||||
|
jsonrpc-pubsub = "13.1.0"
|
||||||
|
log = "0.4"
|
||||||
primitives = { package = "substrate-primitives", path = "../primitives" }
|
primitives = { package = "substrate-primitives", path = "../primitives" }
|
||||||
session = { package = "substrate-session", path = "../session" }
|
rpc = { package = "jsonrpc-core", version = "13.0.0" }
|
||||||
state_machine = { package = "substrate-state-machine", path = "../state-machine" }
|
|
||||||
transaction_pool = { package = "substrate-transaction-pool", path = "../transaction-pool" }
|
|
||||||
sr-primitives = { path = "../sr-primitives" }
|
|
||||||
runtime_version = { package = "sr-version", path = "../sr-version" }
|
runtime_version = { package = "sr-version", path = "../sr-version" }
|
||||||
|
serde_json = "1.0"
|
||||||
|
session = { package = "substrate-session", path = "../session" }
|
||||||
|
sr-primitives = { path = "../sr-primitives" }
|
||||||
|
state_machine = { package = "substrate-state-machine", path = "../state-machine" }
|
||||||
|
substrate-executor = { path = "../executor" }
|
||||||
substrate-keystore = { path = "../keystore" }
|
substrate-keystore = { path = "../keystore" }
|
||||||
|
transaction_pool = { package = "substrate-transaction-pool", path = "../transaction-pool" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
assert_matches = "1.1"
|
assert_matches = "1.1"
|
||||||
futures = "0.1.17"
|
futures = "0.1.17"
|
||||||
|
network = { package = "substrate-network", path = "../network" }
|
||||||
|
rustc-hex = "2.0"
|
||||||
sr-io = { path = "../sr-io" }
|
sr-io = { path = "../sr-io" }
|
||||||
test-client = { package = "substrate-test-runtime-client", path = "../test-runtime/client" }
|
test-client = { package = "substrate-test-runtime-client", path = "../test-runtime/client" }
|
||||||
rustc-hex = "2.0"
|
|
||||||
tokio = "0.1.17"
|
tokio = "0.1.17"
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
[package]
|
||||||
|
name = "substrate-rpc-api"
|
||||||
|
version = "2.0.0"
|
||||||
|
authors = ["Parity Technologies <admin@parity.io>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
codec = { package = "parity-scale-codec", version = "1.0.0" }
|
||||||
|
derive_more = "0.14.0"
|
||||||
|
futures03 = { package = "futures-preview", version = "0.3.0-alpha.17", features = ["compat"] }
|
||||||
|
jsonrpc-core = "13.0.0"
|
||||||
|
jsonrpc-core-client = "13.0.0"
|
||||||
|
jsonrpc-derive = "13.0.0"
|
||||||
|
jsonrpc-pubsub = "13.0.0"
|
||||||
|
log = "0.4"
|
||||||
|
parking_lot = "0.9.0"
|
||||||
|
primitives = { package = "substrate-primitives", path = "../../primitives" }
|
||||||
|
runtime_version = { package = "sr-version", path = "../../sr-version" }
|
||||||
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
serde_json = "1.0"
|
||||||
|
txpool = { package = "substrate-transaction-graph", path = "../../transaction-pool/graph" }
|
||||||
@@ -16,10 +16,8 @@
|
|||||||
|
|
||||||
//! Authoring RPC module errors.
|
//! Authoring RPC module errors.
|
||||||
|
|
||||||
use client;
|
|
||||||
use transaction_pool::txpool;
|
|
||||||
use crate::rpc;
|
|
||||||
use crate::errors;
|
use crate::errors;
|
||||||
|
use jsonrpc_core as rpc;
|
||||||
|
|
||||||
/// Author RPC Result type.
|
/// Author RPC Result type.
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
@@ -28,8 +26,10 @@ pub type Result<T> = std::result::Result<T, Error>;
|
|||||||
#[derive(Debug, derive_more::Display, derive_more::From)]
|
#[derive(Debug, derive_more::Display, derive_more::From)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Client error.
|
/// Client error.
|
||||||
Client(client::error::Error),
|
#[display(fmt="Client error: {}", _0)]
|
||||||
|
Client(Box<dyn std::error::Error + Send>),
|
||||||
/// Transaction pool error,
|
/// Transaction pool error,
|
||||||
|
#[display(fmt="Transaction pool error: {}", _0)]
|
||||||
Pool(txpool::error::Error),
|
Pool(txpool::error::Error),
|
||||||
/// Verification error
|
/// Verification error
|
||||||
#[display(fmt="Extrinsic verification error: {}", _0)]
|
#[display(fmt="Extrinsic verification error: {}", _0)]
|
||||||
@@ -54,7 +54,7 @@ pub enum Error {
|
|||||||
impl std::error::Error for Error {
|
impl std::error::Error for Error {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
match self {
|
match self {
|
||||||
Error::Client(ref err) => Some(err),
|
Error::Client(ref err) => Some(&**err),
|
||||||
Error::Pool(ref err) => Some(err),
|
Error::Pool(ref err) => Some(err),
|
||||||
Error::Verification(ref err) => Some(&**err),
|
Error::Verification(ref err) => Some(&**err),
|
||||||
_ => None,
|
_ => None,
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
// Copyright 2017-2019 Parity Technologies (UK) Ltd.
|
||||||
|
// This file is part of Substrate.
|
||||||
|
|
||||||
|
// Substrate is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
|
||||||
|
// Substrate is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
//! Substrate block-author/full-node API.
|
||||||
|
|
||||||
|
pub mod error;
|
||||||
|
pub mod hash;
|
||||||
|
|
||||||
|
use jsonrpc_derive::rpc;
|
||||||
|
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId};
|
||||||
|
use primitives::{
|
||||||
|
Bytes
|
||||||
|
};
|
||||||
|
use self::error::Result;
|
||||||
|
use txpool::watcher::Status;
|
||||||
|
|
||||||
|
pub use self::gen_client::Client as AuthorClient;
|
||||||
|
|
||||||
|
/// Substrate authoring RPC API
|
||||||
|
#[rpc]
|
||||||
|
pub trait AuthorApi<Hash, BlockHash> {
|
||||||
|
/// RPC metadata
|
||||||
|
type Metadata;
|
||||||
|
|
||||||
|
/// Submit hex-encoded extrinsic for inclusion in block.
|
||||||
|
#[rpc(name = "author_submitExtrinsic")]
|
||||||
|
fn submit_extrinsic(&self, extrinsic: Bytes) -> Result<Hash>;
|
||||||
|
|
||||||
|
/// Insert a key into the keystore.
|
||||||
|
#[rpc(name = "author_insertKey")]
|
||||||
|
fn insert_key(&self,
|
||||||
|
key_type: String,
|
||||||
|
suri: String,
|
||||||
|
maybe_public: Option<Bytes>
|
||||||
|
) -> Result<Bytes>;
|
||||||
|
|
||||||
|
/// Generate new session keys and returns the corresponding public keys.
|
||||||
|
#[rpc(name = "author_rotateKeys")]
|
||||||
|
fn rotate_keys(&self) -> Result<Bytes>;
|
||||||
|
|
||||||
|
/// Returns all pending extrinsics, potentially grouped by sender.
|
||||||
|
#[rpc(name = "author_pendingExtrinsics")]
|
||||||
|
fn pending_extrinsics(&self) -> Result<Vec<Bytes>>;
|
||||||
|
|
||||||
|
/// Remove given extrinsic from the pool and temporarily ban it to prevent reimporting.
|
||||||
|
#[rpc(name = "author_removeExtrinsic")]
|
||||||
|
fn remove_extrinsic(&self,
|
||||||
|
bytes_or_hash: Vec<hash::ExtrinsicOrHash<Hash>>
|
||||||
|
) -> Result<Vec<Hash>>;
|
||||||
|
|
||||||
|
/// Submit an extrinsic to watch.
|
||||||
|
#[pubsub(
|
||||||
|
subscription = "author_extrinsicUpdate",
|
||||||
|
subscribe,
|
||||||
|
name = "author_submitAndWatchExtrinsic"
|
||||||
|
)]
|
||||||
|
fn watch_extrinsic(&self,
|
||||||
|
metadata: Self::Metadata,
|
||||||
|
subscriber: Subscriber<Status<Hash, BlockHash>>,
|
||||||
|
bytes: Bytes
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Unsubscribe from extrinsic watching.
|
||||||
|
#[pubsub(
|
||||||
|
subscription = "author_extrinsicUpdate",
|
||||||
|
unsubscribe,
|
||||||
|
name = "author_unwatchExtrinsic"
|
||||||
|
)]
|
||||||
|
fn unwatch_extrinsic(&self,
|
||||||
|
metadata: Option<Self::Metadata>,
|
||||||
|
id: SubscriptionId
|
||||||
|
) -> Result<bool>;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -17,9 +17,8 @@
|
|||||||
|
|
||||||
//! Error helpers for Chain RPC module.
|
//! Error helpers for Chain RPC module.
|
||||||
|
|
||||||
use client;
|
|
||||||
use crate::rpc;
|
|
||||||
use crate::errors;
|
use crate::errors;
|
||||||
|
use jsonrpc_core as rpc;
|
||||||
|
|
||||||
/// Chain RPC Result type.
|
/// Chain RPC Result type.
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
@@ -28,7 +27,8 @@ pub type Result<T> = std::result::Result<T, Error>;
|
|||||||
#[derive(Debug, derive_more::Display, derive_more::From)]
|
#[derive(Debug, derive_more::Display, derive_more::From)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Client error.
|
/// Client error.
|
||||||
Client(client::error::Error),
|
#[display(fmt="Client error: {}", _0)]
|
||||||
|
Client(Box<dyn std::error::Error + Send>),
|
||||||
/// Other error type.
|
/// Other error type.
|
||||||
Other(String),
|
Other(String),
|
||||||
}
|
}
|
||||||
@@ -36,7 +36,7 @@ pub enum Error {
|
|||||||
impl std::error::Error for Error {
|
impl std::error::Error for Error {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
match self {
|
match self {
|
||||||
Error::Client(ref err) => Some(err),
|
Error::Client(ref err) => Some(&**err),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
// Copyright 2017-2019 Parity Technologies (UK) Ltd.
|
||||||
|
// This file is part of Substrate.
|
||||||
|
|
||||||
|
// Substrate is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
|
||||||
|
// Substrate is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
//! Substrate blockchain API.
|
||||||
|
|
||||||
|
pub mod error;
|
||||||
|
pub mod number;
|
||||||
|
|
||||||
|
use jsonrpc_core::Result as RpcResult;
|
||||||
|
use jsonrpc_core::futures::Future;
|
||||||
|
use jsonrpc_derive::rpc;
|
||||||
|
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId};
|
||||||
|
use self::error::Result;
|
||||||
|
|
||||||
|
pub use self::gen_client::Client as ChainClient;
|
||||||
|
|
||||||
|
/// Substrate blockchain API
|
||||||
|
#[rpc]
|
||||||
|
pub trait ChainApi<Number, Hash, Header, SignedBlock> {
|
||||||
|
/// RPC metadata
|
||||||
|
type Metadata;
|
||||||
|
|
||||||
|
/// Get header of a relay chain block.
|
||||||
|
#[rpc(name = "chain_getHeader")]
|
||||||
|
fn header(&self, hash: Option<Hash>) -> Result<Option<Header>>;
|
||||||
|
|
||||||
|
/// Get header and body of a relay chain block.
|
||||||
|
#[rpc(name = "chain_getBlock")]
|
||||||
|
fn block(&self, hash: Option<Hash>) -> Result<Option<SignedBlock>>;
|
||||||
|
|
||||||
|
/// Get hash of the n-th block in the canon chain.
|
||||||
|
///
|
||||||
|
/// By default returns latest block hash.
|
||||||
|
#[rpc(name = "chain_getBlockHash", alias("chain_getHead"))]
|
||||||
|
fn block_hash(&self, hash: Option<number::NumberOrHex<Number>>) -> Result<Option<Hash>>;
|
||||||
|
|
||||||
|
/// Get hash of the last finalized block in the canon chain.
|
||||||
|
#[rpc(name = "chain_getFinalizedHead", alias("chain_getFinalisedHead"))]
|
||||||
|
fn finalized_head(&self) -> Result<Hash>;
|
||||||
|
|
||||||
|
/// New head subscription
|
||||||
|
#[pubsub(
|
||||||
|
subscription = "chain_newHead",
|
||||||
|
subscribe,
|
||||||
|
name = "chain_subscribeNewHeads",
|
||||||
|
alias("subscribe_newHead", "chain_subscribeNewHead")
|
||||||
|
)]
|
||||||
|
fn subscribe_new_heads(&self, metadata: Self::Metadata, subscriber: Subscriber<Header>);
|
||||||
|
|
||||||
|
/// Unsubscribe from new head subscription.
|
||||||
|
#[pubsub(
|
||||||
|
subscription = "chain_newHead",
|
||||||
|
unsubscribe,
|
||||||
|
name = "chain_unsubscribeNewHeads",
|
||||||
|
alias("unsubscribe_newHead", "chain_unsubscribeNewHead")
|
||||||
|
)]
|
||||||
|
fn unsubscribe_new_heads(&self, metadata: Option<Self::Metadata>, id: SubscriptionId) -> RpcResult<bool>;
|
||||||
|
|
||||||
|
/// New head subscription
|
||||||
|
#[pubsub(
|
||||||
|
subscription = "chain_finalizedHead",
|
||||||
|
subscribe,
|
||||||
|
name = "chain_subscribeFinalizedHeads",
|
||||||
|
alias("chain_subscribeFinalisedHeads")
|
||||||
|
)]
|
||||||
|
fn subscribe_finalized_heads(&self, metadata: Self::Metadata, subscriber: Subscriber<Header>);
|
||||||
|
|
||||||
|
/// Unsubscribe from new head subscription.
|
||||||
|
#[pubsub(
|
||||||
|
subscription = "chain_finalizedHead",
|
||||||
|
unsubscribe,
|
||||||
|
name = "chain_unsubscribeFinalizedHeads",
|
||||||
|
alias("chain_unsubscribeFinalisedHeads")
|
||||||
|
)]
|
||||||
|
fn unsubscribe_finalized_heads(&self, metadata: Option<Self::Metadata>, id: SubscriptionId) -> RpcResult<bool>;
|
||||||
|
}
|
||||||
@@ -61,14 +61,12 @@ impl<Number: TryFrom<u64> + From<u32> + Debug + PartialOrd> NumberOrHex<Number>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
impl From<u64> for NumberOrHex<u64> {
|
impl From<u64> for NumberOrHex<u64> {
|
||||||
fn from(n: u64) -> Self {
|
fn from(n: u64) -> Self {
|
||||||
NumberOrHex::Number(n)
|
NumberOrHex::Number(n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
impl<Number> From<U256> for NumberOrHex<Number> {
|
impl<Number> From<U256> for NumberOrHex<Number> {
|
||||||
fn from(n: U256) -> Self {
|
fn from(n: U256) -> Self {
|
||||||
NumberOrHex::Hex(n)
|
NumberOrHex::Hex(n)
|
||||||
@@ -14,13 +14,12 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::rpc;
|
|
||||||
use log::warn;
|
use log::warn;
|
||||||
|
|
||||||
pub fn internal<E: ::std::fmt::Debug>(e: E) -> rpc::Error {
|
pub fn internal<E: ::std::fmt::Debug>(e: E) -> jsonrpc_core::Error {
|
||||||
warn!("Unknown error: {:?}", e);
|
warn!("Unknown error: {:?}", e);
|
||||||
rpc::Error {
|
jsonrpc_core::Error {
|
||||||
code: rpc::ErrorCode::InternalError,
|
code: jsonrpc_core::ErrorCode::InternalError,
|
||||||
message: "Unknown error occured".into(),
|
message: "Unknown error occured".into(),
|
||||||
data: Some(format!("{:?}", e).into()),
|
data: Some(format!("{:?}", e).into()),
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
// Copyright 2018-2019 Parity Technologies (UK) Ltd.
|
||||||
|
// This file is part of Substrate.
|
||||||
|
|
||||||
|
// Substrate is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
|
||||||
|
// Substrate is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
use jsonrpc_core::futures::prelude::*;
|
||||||
|
use futures03::{channel::oneshot, compat::Compat};
|
||||||
|
|
||||||
|
/// Wraps around `oneshot::Receiver` and adjusts the error type to produce an internal error if the
|
||||||
|
/// sender gets dropped.
|
||||||
|
pub struct Receiver<T>(pub Compat<oneshot::Receiver<T>>);
|
||||||
|
|
||||||
|
impl<T> Future for Receiver<T> {
|
||||||
|
type Item = T;
|
||||||
|
type Error = jsonrpc_core::Error;
|
||||||
|
|
||||||
|
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
||||||
|
self.0.poll().map_err(|_| jsonrpc_core::Error::internal_error())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
// Copyright 2019 Parity Technologies (UK) Ltd.
|
||||||
|
// This file is part of Substrate.
|
||||||
|
|
||||||
|
// Substrate is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
|
||||||
|
// Substrate is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
//! Substrate RPC interfaces.
|
||||||
|
//!
|
||||||
|
//! A collection of RPC methods and subscriptions supported by all substrate clients.
|
||||||
|
|
||||||
|
#![warn(missing_docs)]
|
||||||
|
|
||||||
|
mod errors;
|
||||||
|
mod helpers;
|
||||||
|
mod subscriptions;
|
||||||
|
|
||||||
|
pub use jsonrpc_core::IoHandlerExtension as RpcExtension;
|
||||||
|
pub use subscriptions::Subscriptions;
|
||||||
|
pub use helpers::Receiver;
|
||||||
|
|
||||||
|
pub mod author;
|
||||||
|
pub mod chain;
|
||||||
|
pub mod state;
|
||||||
|
pub mod system;
|
||||||
@@ -16,9 +16,8 @@
|
|||||||
|
|
||||||
//! State RPC errors.
|
//! State RPC errors.
|
||||||
|
|
||||||
use client;
|
|
||||||
use crate::rpc;
|
|
||||||
use crate::errors;
|
use crate::errors;
|
||||||
|
use jsonrpc_core as rpc;
|
||||||
|
|
||||||
/// State RPC Result type.
|
/// State RPC Result type.
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
@@ -27,7 +26,8 @@ pub type Result<T> = std::result::Result<T, Error>;
|
|||||||
#[derive(Debug, derive_more::Display, derive_more::From)]
|
#[derive(Debug, derive_more::Display, derive_more::From)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Client error.
|
/// Client error.
|
||||||
Client(client::error::Error),
|
#[display(fmt="Client error: {}", _0)]
|
||||||
|
Client(Box<dyn std::error::Error + Send>),
|
||||||
/// Provided block range couldn't be resolved to a list of blocks.
|
/// Provided block range couldn't be resolved to a list of blocks.
|
||||||
#[display(fmt = "Cannot resolve a block range ['{:?}' ... '{:?}]. {}", from, to, details)]
|
#[display(fmt = "Cannot resolve a block range ['{:?}' ... '{:?}]. {}", from, to, details)]
|
||||||
InvalidBlockRange {
|
InvalidBlockRange {
|
||||||
@@ -43,7 +43,7 @@ pub enum Error {
|
|||||||
impl std::error::Error for Error {
|
impl std::error::Error for Error {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
match self {
|
match self {
|
||||||
Error::Client(ref err) => Some(err),
|
Error::Client(ref err) => Some(&**err),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,143 @@
|
|||||||
|
// Copyright 2017-2019 Parity Technologies (UK) Ltd.
|
||||||
|
// This file is part of Substrate.
|
||||||
|
|
||||||
|
// Substrate is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
|
||||||
|
// Substrate is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
//! Substrate state API.
|
||||||
|
|
||||||
|
pub mod error;
|
||||||
|
|
||||||
|
use jsonrpc_core::Result as RpcResult;
|
||||||
|
use jsonrpc_core::futures::Future;
|
||||||
|
use jsonrpc_derive::rpc;
|
||||||
|
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId};
|
||||||
|
use primitives::Bytes;
|
||||||
|
use primitives::storage::{StorageKey, StorageData, StorageChangeSet};
|
||||||
|
use runtime_version::RuntimeVersion;
|
||||||
|
use self::error::Result;
|
||||||
|
|
||||||
|
pub use self::gen_client::Client as StateClient;
|
||||||
|
|
||||||
|
/// Substrate state API
|
||||||
|
#[rpc]
|
||||||
|
pub trait StateApi<Hash> {
|
||||||
|
/// RPC Metadata
|
||||||
|
type Metadata;
|
||||||
|
|
||||||
|
/// Call a contract at a block's state.
|
||||||
|
#[rpc(name = "state_call", alias("state_callAt"))]
|
||||||
|
fn call(&self, name: String, bytes: Bytes, hash: Option<Hash>) -> Result<Bytes>;
|
||||||
|
|
||||||
|
/// Returns the keys with prefix, leave empty to get all the keys
|
||||||
|
#[rpc(name = "state_getKeys")]
|
||||||
|
fn storage_keys(&self, prefix: StorageKey, hash: Option<Hash>) -> Result<Vec<StorageKey>>;
|
||||||
|
|
||||||
|
/// Returns a storage entry at a specific block's state.
|
||||||
|
#[rpc(name = "state_getStorage", alias("state_getStorageAt"))]
|
||||||
|
fn storage(&self, key: StorageKey, hash: Option<Hash>) -> Result<Option<StorageData>>;
|
||||||
|
|
||||||
|
/// Returns the hash of a storage entry at a block's state.
|
||||||
|
#[rpc(name = "state_getStorageHash", alias("state_getStorageHashAt"))]
|
||||||
|
fn storage_hash(&self, key: StorageKey, hash: Option<Hash>) -> Result<Option<Hash>>;
|
||||||
|
|
||||||
|
/// Returns the size of a storage entry at a block's state.
|
||||||
|
#[rpc(name = "state_getStorageSize", alias("state_getStorageSizeAt"))]
|
||||||
|
fn storage_size(&self, key: StorageKey, hash: Option<Hash>) -> Result<Option<u64>>;
|
||||||
|
|
||||||
|
/// Returns the keys with prefix from a child storage, leave empty to get all the keys
|
||||||
|
#[rpc(name = "state_getChildKeys")]
|
||||||
|
fn child_storage_keys(
|
||||||
|
&self,
|
||||||
|
child_storage_key: StorageKey,
|
||||||
|
prefix: StorageKey,
|
||||||
|
hash: Option<Hash>
|
||||||
|
) -> Result<Vec<StorageKey>>;
|
||||||
|
|
||||||
|
/// Returns a child storage entry at a specific block's state.
|
||||||
|
#[rpc(name = "state_getChildStorage")]
|
||||||
|
fn child_storage(
|
||||||
|
&self,
|
||||||
|
child_storage_key: StorageKey,
|
||||||
|
key: StorageKey,
|
||||||
|
hash: Option<Hash>
|
||||||
|
) -> Result<Option<StorageData>>;
|
||||||
|
|
||||||
|
/// Returns the hash of a child storage entry at a block's state.
|
||||||
|
#[rpc(name = "state_getChildStorageHash")]
|
||||||
|
fn child_storage_hash(
|
||||||
|
&self,
|
||||||
|
child_storage_key: StorageKey,
|
||||||
|
key: StorageKey,
|
||||||
|
hash: Option<Hash>
|
||||||
|
) -> Result<Option<Hash>>;
|
||||||
|
|
||||||
|
/// Returns the size of a child storage entry at a block's state.
|
||||||
|
#[rpc(name = "state_getChildStorageSize")]
|
||||||
|
fn child_storage_size(
|
||||||
|
&self,
|
||||||
|
child_storage_key: StorageKey,
|
||||||
|
key: StorageKey,
|
||||||
|
hash: Option<Hash>
|
||||||
|
) -> Result<Option<u64>>;
|
||||||
|
|
||||||
|
/// Returns the runtime metadata as an opaque blob.
|
||||||
|
#[rpc(name = "state_getMetadata")]
|
||||||
|
fn metadata(&self, hash: Option<Hash>) -> Result<Bytes>;
|
||||||
|
|
||||||
|
/// Get the runtime version.
|
||||||
|
#[rpc(name = "state_getRuntimeVersion", alias("chain_getRuntimeVersion"))]
|
||||||
|
fn runtime_version(&self, hash: Option<Hash>) -> Result<RuntimeVersion>;
|
||||||
|
|
||||||
|
/// Query historical storage entries (by key) starting from a block given as the second parameter.
|
||||||
|
///
|
||||||
|
/// NOTE This first returned result contains the initial state of storage for all keys.
|
||||||
|
/// Subsequent values in the vector represent changes to the previous state (diffs).
|
||||||
|
#[rpc(name = "state_queryStorage")]
|
||||||
|
fn query_storage(
|
||||||
|
&self,
|
||||||
|
keys: Vec<StorageKey>,
|
||||||
|
block: Hash,
|
||||||
|
hash: Option<Hash>
|
||||||
|
) -> Result<Vec<StorageChangeSet<Hash>>>;
|
||||||
|
|
||||||
|
/// New runtime version subscription
|
||||||
|
#[pubsub(
|
||||||
|
subscription = "state_runtimeVersion",
|
||||||
|
subscribe,
|
||||||
|
name = "state_subscribeRuntimeVersion",
|
||||||
|
alias("chain_subscribeRuntimeVersion")
|
||||||
|
)]
|
||||||
|
fn subscribe_runtime_version(&self, metadata: Self::Metadata, subscriber: Subscriber<RuntimeVersion>);
|
||||||
|
|
||||||
|
/// Unsubscribe from runtime version subscription
|
||||||
|
#[pubsub(
|
||||||
|
subscription = "state_runtimeVersion",
|
||||||
|
unsubscribe,
|
||||||
|
name = "state_unsubscribeRuntimeVersion",
|
||||||
|
alias("chain_unsubscribeRuntimeVersion")
|
||||||
|
)]
|
||||||
|
fn unsubscribe_runtime_version(&self, metadata: Option<Self::Metadata>, id: SubscriptionId) -> RpcResult<bool>;
|
||||||
|
|
||||||
|
/// New storage subscription
|
||||||
|
#[pubsub(subscription = "state_storage", subscribe, name = "state_subscribeStorage")]
|
||||||
|
fn subscribe_storage(
|
||||||
|
&self, metadata: Self::Metadata, subscriber: Subscriber<StorageChangeSet<Hash>>, keys: Option<Vec<StorageKey>>
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Unsubscribe from storage subscription
|
||||||
|
#[pubsub(subscription = "state_storage", unsubscribe, name = "state_unsubscribeStorage")]
|
||||||
|
fn unsubscribe_storage(
|
||||||
|
&self, metadata: Option<Self::Metadata>, id: SubscriptionId
|
||||||
|
) -> RpcResult<bool>;
|
||||||
|
}
|
||||||
+2
-2
@@ -20,8 +20,8 @@ use std::sync::{Arc, atomic::{self, AtomicUsize}};
|
|||||||
use log::{error, warn};
|
use log::{error, warn};
|
||||||
use jsonrpc_pubsub::{SubscriptionId, typed::{Sink, Subscriber}};
|
use jsonrpc_pubsub::{SubscriptionId, typed::{Sink, Subscriber}};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use crate::rpc::futures::sync::oneshot;
|
use jsonrpc_core::futures::sync::oneshot;
|
||||||
use crate::rpc::futures::{Future, future};
|
use jsonrpc_core::futures::{Future, future};
|
||||||
|
|
||||||
type Id = u64;
|
type Id = u64;
|
||||||
|
|
||||||
@@ -16,8 +16,8 @@
|
|||||||
|
|
||||||
//! System RPC module errors.
|
//! System RPC module errors.
|
||||||
|
|
||||||
use crate::rpc;
|
|
||||||
use crate::system::helpers::Health;
|
use crate::system::helpers::Health;
|
||||||
|
use jsonrpc_core as rpc;
|
||||||
|
|
||||||
/// System RPC Result type.
|
/// System RPC Result type.
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
// Copyright 2017-2019 Parity Technologies (UK) Ltd.
|
||||||
|
// This file is part of Substrate.
|
||||||
|
|
||||||
|
// Substrate is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
|
||||||
|
// Substrate is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
//! Substrate system API.
|
||||||
|
|
||||||
|
pub mod error;
|
||||||
|
pub mod helpers;
|
||||||
|
|
||||||
|
use crate::helpers::Receiver;
|
||||||
|
use jsonrpc_derive::rpc;
|
||||||
|
|
||||||
|
use self::error::Result;
|
||||||
|
|
||||||
|
pub use self::helpers::{Properties, SystemInfo, Health, PeerInfo};
|
||||||
|
pub use self::gen_client::Client as SystemClient;
|
||||||
|
|
||||||
|
/// Substrate system RPC API
|
||||||
|
#[rpc]
|
||||||
|
pub trait SystemApi<Hash, Number> {
|
||||||
|
/// Get the node's implementation name. Plain old string.
|
||||||
|
#[rpc(name = "system_name")]
|
||||||
|
fn system_name(&self) -> Result<String>;
|
||||||
|
|
||||||
|
/// Get the node implementation's version. Should be a semver string.
|
||||||
|
#[rpc(name = "system_version")]
|
||||||
|
fn system_version(&self) -> Result<String>;
|
||||||
|
|
||||||
|
/// Get the chain's type. Given as a string identifier.
|
||||||
|
#[rpc(name = "system_chain")]
|
||||||
|
fn system_chain(&self) -> Result<String>;
|
||||||
|
|
||||||
|
/// Get a custom set of properties as a JSON object, defined in the chain spec.
|
||||||
|
#[rpc(name = "system_properties")]
|
||||||
|
fn system_properties(&self) -> Result<Properties>;
|
||||||
|
|
||||||
|
/// Return health status of the node.
|
||||||
|
///
|
||||||
|
/// Node is considered healthy if it is:
|
||||||
|
/// - connected to some peers (unless running in dev mode)
|
||||||
|
/// - not performing a major sync
|
||||||
|
#[rpc(name = "system_health", returns = "Health")]
|
||||||
|
fn system_health(&self) -> Receiver<Health>;
|
||||||
|
|
||||||
|
/// Returns currently connected peers
|
||||||
|
#[rpc(name = "system_peers", returns = "Vec<PeerInfo<Hash, Number>>")]
|
||||||
|
fn system_peers(&self) -> Receiver<Vec<PeerInfo<Hash, Number>>>;
|
||||||
|
|
||||||
|
/// Returns current state of the network.
|
||||||
|
///
|
||||||
|
/// **Warning**: This API is not stable.
|
||||||
|
// TODO: make this stable and move structs https://github.com/paritytech/substrate/issues/1890
|
||||||
|
#[rpc(name = "system_networkState", returns = "jsonrpc_core::Value")]
|
||||||
|
fn system_network_state(&self) -> Receiver<jsonrpc_core::Value>;
|
||||||
|
}
|
||||||
@@ -16,19 +16,15 @@
|
|||||||
|
|
||||||
//! Substrate block-author/full-node API.
|
//! Substrate block-author/full-node API.
|
||||||
|
|
||||||
pub mod error;
|
|
||||||
pub mod hash;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
use std::{sync::Arc, convert::TryInto};
|
use std::{sync::Arc, convert::TryInto};
|
||||||
|
|
||||||
use client::{self, Client};
|
use client::{self, Client};
|
||||||
use crate::rpc::futures::{Sink, Future};
|
use rpc::futures::{Sink, Future};
|
||||||
use crate::subscriptions::Subscriptions;
|
|
||||||
use futures03::{StreamExt as _, compat::Compat};
|
use futures03::{StreamExt as _, compat::Compat};
|
||||||
use jsonrpc_derive::rpc;
|
use api::Subscriptions;
|
||||||
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId};
|
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId};
|
||||||
use log::warn;
|
use log::warn;
|
||||||
use codec::{Encode, Decode};
|
use codec::{Encode, Decode};
|
||||||
@@ -37,7 +33,6 @@ use primitives::{
|
|||||||
traits::BareCryptoStorePtr,
|
traits::BareCryptoStorePtr,
|
||||||
};
|
};
|
||||||
use sr_primitives::{generic, traits::{self, ProvideRuntimeApi}};
|
use sr_primitives::{generic, traits::{self, ProvideRuntimeApi}};
|
||||||
use self::error::{Error, Result};
|
|
||||||
use transaction_pool::{
|
use transaction_pool::{
|
||||||
txpool::{
|
txpool::{
|
||||||
ChainApi as PoolChainApi,
|
ChainApi as PoolChainApi,
|
||||||
@@ -50,63 +45,9 @@ use transaction_pool::{
|
|||||||
};
|
};
|
||||||
use session::SessionKeys;
|
use session::SessionKeys;
|
||||||
|
|
||||||
pub use self::gen_client::Client as AuthorClient;
|
/// Re-export the API for backward compatibility.
|
||||||
|
pub use api::author::*;
|
||||||
/// Substrate authoring RPC API
|
use self::error::{Error, Result};
|
||||||
#[rpc]
|
|
||||||
pub trait AuthorApi<Hash, BlockHash> {
|
|
||||||
/// RPC metadata
|
|
||||||
type Metadata;
|
|
||||||
|
|
||||||
/// Submit hex-encoded extrinsic for inclusion in block.
|
|
||||||
#[rpc(name = "author_submitExtrinsic")]
|
|
||||||
fn submit_extrinsic(&self, extrinsic: Bytes) -> Result<Hash>;
|
|
||||||
|
|
||||||
/// Insert a key into the keystore.
|
|
||||||
#[rpc(name = "author_insertKey")]
|
|
||||||
fn insert_key(&self,
|
|
||||||
key_type: String,
|
|
||||||
suri: String,
|
|
||||||
maybe_public: Option<Bytes>
|
|
||||||
) -> Result<Bytes>;
|
|
||||||
|
|
||||||
/// Generate new session keys and returns the corresponding public keys.
|
|
||||||
#[rpc(name = "author_rotateKeys")]
|
|
||||||
fn rotate_keys(&self) -> Result<Bytes>;
|
|
||||||
|
|
||||||
/// Returns all pending extrinsics, potentially grouped by sender.
|
|
||||||
#[rpc(name = "author_pendingExtrinsics")]
|
|
||||||
fn pending_extrinsics(&self) -> Result<Vec<Bytes>>;
|
|
||||||
|
|
||||||
/// Remove given extrinsic from the pool and temporarily ban it to prevent reimporting.
|
|
||||||
#[rpc(name = "author_removeExtrinsic")]
|
|
||||||
fn remove_extrinsic(&self,
|
|
||||||
bytes_or_hash: Vec<hash::ExtrinsicOrHash<Hash>>
|
|
||||||
) -> Result<Vec<Hash>>;
|
|
||||||
|
|
||||||
/// Submit an extrinsic to watch.
|
|
||||||
#[pubsub(
|
|
||||||
subscription = "author_extrinsicUpdate",
|
|
||||||
subscribe,
|
|
||||||
name = "author_submitAndWatchExtrinsic"
|
|
||||||
)]
|
|
||||||
fn watch_extrinsic(&self,
|
|
||||||
metadata: Self::Metadata,
|
|
||||||
subscriber: Subscriber<Status<Hash, BlockHash>>,
|
|
||||||
bytes: Bytes
|
|
||||||
);
|
|
||||||
|
|
||||||
/// Unsubscribe from extrinsic watching.
|
|
||||||
#[pubsub(
|
|
||||||
subscription = "author_extrinsicUpdate",
|
|
||||||
unsubscribe,
|
|
||||||
name = "author_unwatchExtrinsic"
|
|
||||||
)]
|
|
||||||
fn unwatch_extrinsic(&self,
|
|
||||||
metadata: Option<Self::Metadata>,
|
|
||||||
id: SubscriptionId
|
|
||||||
) -> Result<bool>;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Authoring API
|
/// Authoring API
|
||||||
pub struct Author<B, E, P, RA> where P: PoolChainApi + Sync + Send + 'static {
|
pub struct Author<B, E, P, RA> where P: PoolChainApi + Sync + Send + 'static {
|
||||||
@@ -183,7 +124,7 @@ impl<B, E, P, RA> AuthorApi<ExHash<P>, BlockHash<P>> for Author<B, E, P, RA> whe
|
|||||||
self.client.runtime_api().generate_session_keys(
|
self.client.runtime_api().generate_session_keys(
|
||||||
&generic::BlockId::Hash(best_block_hash),
|
&generic::BlockId::Hash(best_block_hash),
|
||||||
None,
|
None,
|
||||||
).map(Into::into).map_err(Into::into)
|
).map(Into::into).map_err(|e| Error::Client(Box::new(e)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn submit_extrinsic(&self, ext: Bytes) -> Result<ExHash<P>> {
|
fn submit_extrinsic(&self, ext: Bytes) -> Result<ExHash<P>> {
|
||||||
|
|||||||
@@ -16,9 +16,6 @@
|
|||||||
|
|
||||||
//! Substrate blockchain API.
|
//! Substrate blockchain API.
|
||||||
|
|
||||||
pub mod error;
|
|
||||||
pub mod number;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
@@ -26,79 +23,17 @@ use std::sync::Arc;
|
|||||||
use futures03::{future, StreamExt as _, TryStreamExt as _};
|
use futures03::{future, StreamExt as _, TryStreamExt as _};
|
||||||
|
|
||||||
use client::{self, Client, BlockchainEvents};
|
use client::{self, Client, BlockchainEvents};
|
||||||
use crate::rpc::Result as RpcResult;
|
use rpc::Result as RpcResult;
|
||||||
use crate::rpc::futures::{stream, Future, Sink, Stream};
|
use rpc::futures::{stream, Future, Sink, Stream};
|
||||||
use crate::subscriptions::Subscriptions;
|
use api::Subscriptions;
|
||||||
use jsonrpc_derive::rpc;
|
|
||||||
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId};
|
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId};
|
||||||
use log::warn;
|
use log::warn;
|
||||||
use primitives::{H256, Blake2Hasher};
|
use primitives::{H256, Blake2Hasher};
|
||||||
use sr_primitives::generic::{BlockId, SignedBlock};
|
use sr_primitives::generic::{BlockId, SignedBlock};
|
||||||
use sr_primitives::traits::{Block as BlockT, Header, NumberFor};
|
use sr_primitives::traits::{Block as BlockT, Header, NumberFor};
|
||||||
use self::error::Result;
|
use self::error::{Error, Result};
|
||||||
|
|
||||||
pub use self::gen_client::Client as ChainClient;
|
pub use api::chain::*;
|
||||||
|
|
||||||
/// Substrate blockchain API
|
|
||||||
#[rpc]
|
|
||||||
pub trait ChainApi<Number, Hash, Header, SignedBlock> {
|
|
||||||
/// RPC metadata
|
|
||||||
type Metadata;
|
|
||||||
|
|
||||||
/// Get header of a relay chain block.
|
|
||||||
#[rpc(name = "chain_getHeader")]
|
|
||||||
fn header(&self, hash: Option<Hash>) -> Result<Option<Header>>;
|
|
||||||
|
|
||||||
/// Get header and body of a relay chain block.
|
|
||||||
#[rpc(name = "chain_getBlock")]
|
|
||||||
fn block(&self, hash: Option<Hash>) -> Result<Option<SignedBlock>>;
|
|
||||||
|
|
||||||
/// Get hash of the n-th block in the canon chain.
|
|
||||||
///
|
|
||||||
/// By default returns latest block hash.
|
|
||||||
#[rpc(name = "chain_getBlockHash", alias("chain_getHead"))]
|
|
||||||
fn block_hash(&self, hash: Option<number::NumberOrHex<Number>>) -> Result<Option<Hash>>;
|
|
||||||
|
|
||||||
/// Get hash of the last finalized block in the canon chain.
|
|
||||||
#[rpc(name = "chain_getFinalizedHead", alias("chain_getFinalisedHead"))]
|
|
||||||
fn finalized_head(&self) -> Result<Hash>;
|
|
||||||
|
|
||||||
/// New head subscription
|
|
||||||
#[pubsub(
|
|
||||||
subscription = "chain_newHead",
|
|
||||||
subscribe,
|
|
||||||
name = "chain_subscribeNewHeads",
|
|
||||||
alias("subscribe_newHead", "chain_subscribeNewHead")
|
|
||||||
)]
|
|
||||||
fn subscribe_new_heads(&self, metadata: Self::Metadata, subscriber: Subscriber<Header>);
|
|
||||||
|
|
||||||
/// Unsubscribe from new head subscription.
|
|
||||||
#[pubsub(
|
|
||||||
subscription = "chain_newHead",
|
|
||||||
unsubscribe,
|
|
||||||
name = "chain_unsubscribeNewHeads",
|
|
||||||
alias("unsubscribe_newHead", "chain_unsubscribeNewHead")
|
|
||||||
)]
|
|
||||||
fn unsubscribe_new_heads(&self, metadata: Option<Self::Metadata>, id: SubscriptionId) -> RpcResult<bool>;
|
|
||||||
|
|
||||||
/// New head subscription
|
|
||||||
#[pubsub(
|
|
||||||
subscription = "chain_finalizedHead",
|
|
||||||
subscribe,
|
|
||||||
name = "chain_subscribeFinalizedHeads",
|
|
||||||
alias("chain_subscribeFinalisedHeads")
|
|
||||||
)]
|
|
||||||
fn subscribe_finalized_heads(&self, metadata: Self::Metadata, subscriber: Subscriber<Header>);
|
|
||||||
|
|
||||||
/// Unsubscribe from new head subscription.
|
|
||||||
#[pubsub(
|
|
||||||
subscription = "chain_finalizedHead",
|
|
||||||
unsubscribe,
|
|
||||||
name = "chain_unsubscribeFinalizedHeads",
|
|
||||||
alias("chain_unsubscribeFinalisedHeads")
|
|
||||||
)]
|
|
||||||
fn unsubscribe_finalized_heads(&self, metadata: Option<Self::Metadata>, id: SubscriptionId) -> RpcResult<bool>;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Chain API with subscriptions support.
|
/// Chain API with subscriptions support.
|
||||||
pub struct Chain<B, E, Block: BlockT, RA> {
|
pub struct Chain<B, E, Block: BlockT, RA> {
|
||||||
@@ -168,6 +103,10 @@ impl<B, E, Block, RA> Chain<B, E, Block, RA> where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn client_error(err: client::error::Error) -> Error {
|
||||||
|
Error::Client(Box::new(err))
|
||||||
|
}
|
||||||
|
|
||||||
impl<B, E, Block, RA> ChainApi<NumberFor<Block>, Block::Hash, Block::Header, SignedBlock<Block>> for Chain<B, E, Block, RA> where
|
impl<B, E, Block, RA> ChainApi<NumberFor<Block>, Block::Hash, Block::Header, SignedBlock<Block>> for Chain<B, E, Block, RA> where
|
||||||
Block: BlockT<Hash=H256> + 'static,
|
Block: BlockT<Hash=H256> + 'static,
|
||||||
B: client::backend::Backend<Block, Blake2Hasher> + Send + Sync + 'static,
|
B: client::backend::Backend<Block, Blake2Hasher> + Send + Sync + 'static,
|
||||||
@@ -178,20 +117,23 @@ impl<B, E, Block, RA> ChainApi<NumberFor<Block>, Block::Hash, Block::Header, Sig
|
|||||||
|
|
||||||
fn header(&self, hash: Option<Block::Hash>) -> Result<Option<Block::Header>> {
|
fn header(&self, hash: Option<Block::Hash>) -> Result<Option<Block::Header>> {
|
||||||
let hash = self.unwrap_or_best(hash)?;
|
let hash = self.unwrap_or_best(hash)?;
|
||||||
Ok(self.client.header(&BlockId::Hash(hash))?)
|
Ok(self.client.header(&BlockId::Hash(hash)).map_err(client_error)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block(&self, hash: Option<Block::Hash>)
|
fn block(&self, hash: Option<Block::Hash>)
|
||||||
-> Result<Option<SignedBlock<Block>>>
|
-> Result<Option<SignedBlock<Block>>>
|
||||||
{
|
{
|
||||||
let hash = self.unwrap_or_best(hash)?;
|
let hash = self.unwrap_or_best(hash)?;
|
||||||
Ok(self.client.block(&BlockId::Hash(hash))?)
|
Ok(self.client.block(&BlockId::Hash(hash)).map_err(client_error)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block_hash(&self, number: Option<number::NumberOrHex<NumberFor<Block>>>) -> Result<Option<Block::Hash>> {
|
fn block_hash(&self, number: Option<number::NumberOrHex<NumberFor<Block>>>) -> Result<Option<Block::Hash>> {
|
||||||
Ok(match number {
|
Ok(match number {
|
||||||
None => Some(self.client.info().chain.best_hash),
|
None => Some(self.client.info().chain.best_hash),
|
||||||
Some(num_or_hex) => self.client.header(&BlockId::number(num_or_hex.to_number()?))?.map(|h| h.hash()),
|
Some(num_or_hex) => self.client
|
||||||
|
.header(&BlockId::number(num_or_hex.to_number()?))
|
||||||
|
.map_err(client_error)?
|
||||||
|
.map(|h| h.hash()),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,22 +14,6 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use futures::prelude::*;
|
|
||||||
use futures03::{channel::oneshot, compat::Compat};
|
|
||||||
|
|
||||||
/// Wraps around `oneshot::Receiver` and adjusts the error type to produce an internal error if the
|
|
||||||
/// sender gets dropped.
|
|
||||||
pub struct Receiver<T>(pub Compat<oneshot::Receiver<T>>);
|
|
||||||
|
|
||||||
impl<T> Future for Receiver<T> {
|
|
||||||
type Item = T;
|
|
||||||
type Error = jsonrpc_core::Error;
|
|
||||||
|
|
||||||
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
|
||||||
self.0.poll().map_err(|_| jsonrpc_core::Error::internal_error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Unwraps the trailing parameter or falls back with the closure result.
|
/// Unwraps the trailing parameter or falls back with the closure result.
|
||||||
pub fn unwrap_or_else<F, H, E>(or_else: F, optional: Option<H>) -> Result<H, E> where
|
pub fn unwrap_or_else<F, H, E>(or_else: F, optional: Option<H>) -> Result<H, E> where
|
||||||
F: FnOnce() -> Result<H, E>,
|
F: FnOnce() -> Result<H, E>,
|
||||||
|
|||||||
@@ -14,22 +14,18 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
//! Substrate RPC interfaces.
|
//! Substrate RPC implementation.
|
||||||
//!
|
//!
|
||||||
//! A collection of RPC methods and subscriptions supported by all substrate clients.
|
//! A core implementation of Substrate RPC interfaces.
|
||||||
|
|
||||||
#![warn(missing_docs)]
|
#![warn(missing_docs)]
|
||||||
|
|
||||||
mod errors;
|
|
||||||
mod helpers;
|
mod helpers;
|
||||||
mod metadata;
|
mod metadata;
|
||||||
mod subscriptions;
|
|
||||||
|
|
||||||
use jsonrpc_core as rpc;
|
pub use api::Subscriptions;
|
||||||
|
pub use self::metadata::Metadata;
|
||||||
pub use metadata::Metadata;
|
|
||||||
pub use rpc::IoHandlerExtension as RpcExtension;
|
pub use rpc::IoHandlerExtension as RpcExtension;
|
||||||
pub use subscriptions::Subscriptions;
|
|
||||||
|
|
||||||
pub mod author;
|
pub mod author;
|
||||||
pub mod chain;
|
pub mod chain;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use jsonrpc_pubsub::{Session, PubSubMetadata};
|
use jsonrpc_pubsub::{Session, PubSubMetadata};
|
||||||
use crate::rpc::futures::sync::mpsc;
|
use rpc::futures::sync::mpsc;
|
||||||
|
|
||||||
/// RPC Metadata.
|
/// RPC Metadata.
|
||||||
///
|
///
|
||||||
@@ -30,7 +30,7 @@ pub struct Metadata {
|
|||||||
session: Option<Arc<Session>>,
|
session: Option<Arc<Session>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl crate::rpc::Metadata for Metadata {}
|
impl rpc::Metadata for Metadata {}
|
||||||
impl PubSubMetadata for Metadata {
|
impl PubSubMetadata for Metadata {
|
||||||
fn session(&self) -> Option<Arc<Session>> {
|
fn session(&self) -> Option<Arc<Session>> {
|
||||||
self.session.clone()
|
self.session.clone()
|
||||||
|
|||||||
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
//! Substrate state API.
|
//! Substrate state API.
|
||||||
|
|
||||||
pub mod error;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
@@ -29,10 +27,9 @@ use std::{
|
|||||||
use futures03::{future, StreamExt as _, TryStreamExt as _};
|
use futures03::{future, StreamExt as _, TryStreamExt as _};
|
||||||
|
|
||||||
use client::{self, Client, CallExecutor, BlockchainEvents, runtime_api::Metadata};
|
use client::{self, Client, CallExecutor, BlockchainEvents, runtime_api::Metadata};
|
||||||
use crate::rpc::Result as RpcResult;
|
use rpc::Result as RpcResult;
|
||||||
use crate::rpc::futures::{stream, Future, Sink, Stream};
|
use rpc::futures::{stream, Future, Sink, Stream};
|
||||||
use crate::subscriptions::Subscriptions;
|
use api::Subscriptions;
|
||||||
use jsonrpc_derive::rpc;
|
|
||||||
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId};
|
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId};
|
||||||
use log::{warn, trace};
|
use log::{warn, trace};
|
||||||
use primitives::hexdisplay::HexDisplay;
|
use primitives::hexdisplay::HexDisplay;
|
||||||
@@ -44,123 +41,10 @@ use sr_primitives::traits::{
|
|||||||
SaturatedConversion
|
SaturatedConversion
|
||||||
};
|
};
|
||||||
use runtime_version::RuntimeVersion;
|
use runtime_version::RuntimeVersion;
|
||||||
use self::error::Result;
|
use self::error::{Error, Result};
|
||||||
use state_machine::{self, ExecutionStrategy};
|
use state_machine::{self, ExecutionStrategy};
|
||||||
|
|
||||||
pub use self::gen_client::Client as StateClient;
|
pub use api::state::*;
|
||||||
|
|
||||||
/// Substrate state API
|
|
||||||
#[rpc]
|
|
||||||
pub trait StateApi<Hash> {
|
|
||||||
/// RPC Metadata
|
|
||||||
type Metadata;
|
|
||||||
|
|
||||||
/// Call a contract at a block's state.
|
|
||||||
#[rpc(name = "state_call", alias("state_callAt"))]
|
|
||||||
fn call(&self, name: String, bytes: Bytes, hash: Option<Hash>) -> Result<Bytes>;
|
|
||||||
|
|
||||||
/// Returns the keys with prefix, leave empty to get all the keys
|
|
||||||
#[rpc(name = "state_getKeys")]
|
|
||||||
fn storage_keys(&self, prefix: StorageKey, hash: Option<Hash>) -> Result<Vec<StorageKey>>;
|
|
||||||
|
|
||||||
/// Returns a storage entry at a specific block's state.
|
|
||||||
#[rpc(name = "state_getStorage", alias("state_getStorageAt"))]
|
|
||||||
fn storage(&self, key: StorageKey, hash: Option<Hash>) -> Result<Option<StorageData>>;
|
|
||||||
|
|
||||||
/// Returns the hash of a storage entry at a block's state.
|
|
||||||
#[rpc(name = "state_getStorageHash", alias("state_getStorageHashAt"))]
|
|
||||||
fn storage_hash(&self, key: StorageKey, hash: Option<Hash>) -> Result<Option<Hash>>;
|
|
||||||
|
|
||||||
/// Returns the size of a storage entry at a block's state.
|
|
||||||
#[rpc(name = "state_getStorageSize", alias("state_getStorageSizeAt"))]
|
|
||||||
fn storage_size(&self, key: StorageKey, hash: Option<Hash>) -> Result<Option<u64>>;
|
|
||||||
|
|
||||||
/// Returns the keys with prefix from a child storage, leave empty to get all the keys
|
|
||||||
#[rpc(name = "state_getChildKeys")]
|
|
||||||
fn child_storage_keys(
|
|
||||||
&self,
|
|
||||||
child_storage_key: StorageKey,
|
|
||||||
prefix: StorageKey,
|
|
||||||
hash: Option<Hash>
|
|
||||||
) -> Result<Vec<StorageKey>>;
|
|
||||||
|
|
||||||
/// Returns a child storage entry at a specific block's state.
|
|
||||||
#[rpc(name = "state_getChildStorage")]
|
|
||||||
fn child_storage(
|
|
||||||
&self,
|
|
||||||
child_storage_key: StorageKey,
|
|
||||||
key: StorageKey,
|
|
||||||
hash: Option<Hash>
|
|
||||||
) -> Result<Option<StorageData>>;
|
|
||||||
|
|
||||||
/// Returns the hash of a child storage entry at a block's state.
|
|
||||||
#[rpc(name = "state_getChildStorageHash")]
|
|
||||||
fn child_storage_hash(
|
|
||||||
&self,
|
|
||||||
child_storage_key: StorageKey,
|
|
||||||
key: StorageKey,
|
|
||||||
hash: Option<Hash>
|
|
||||||
) -> Result<Option<Hash>>;
|
|
||||||
|
|
||||||
/// Returns the size of a child storage entry at a block's state.
|
|
||||||
#[rpc(name = "state_getChildStorageSize")]
|
|
||||||
fn child_storage_size(
|
|
||||||
&self,
|
|
||||||
child_storage_key: StorageKey,
|
|
||||||
key: StorageKey,
|
|
||||||
hash: Option<Hash>
|
|
||||||
) -> Result<Option<u64>>;
|
|
||||||
|
|
||||||
/// Returns the runtime metadata as an opaque blob.
|
|
||||||
#[rpc(name = "state_getMetadata")]
|
|
||||||
fn metadata(&self, hash: Option<Hash>) -> Result<Bytes>;
|
|
||||||
|
|
||||||
/// Get the runtime version.
|
|
||||||
#[rpc(name = "state_getRuntimeVersion", alias("chain_getRuntimeVersion"))]
|
|
||||||
fn runtime_version(&self, hash: Option<Hash>) -> Result<RuntimeVersion>;
|
|
||||||
|
|
||||||
/// Query historical storage entries (by key) starting from a block given as the second parameter.
|
|
||||||
///
|
|
||||||
/// NOTE This first returned result contains the initial state of storage for all keys.
|
|
||||||
/// Subsequent values in the vector represent changes to the previous state (diffs).
|
|
||||||
#[rpc(name = "state_queryStorage")]
|
|
||||||
fn query_storage(
|
|
||||||
&self,
|
|
||||||
keys: Vec<StorageKey>,
|
|
||||||
block: Hash,
|
|
||||||
hash: Option<Hash>
|
|
||||||
) -> Result<Vec<StorageChangeSet<Hash>>>;
|
|
||||||
|
|
||||||
/// New runtime version subscription
|
|
||||||
#[pubsub(
|
|
||||||
subscription = "state_runtimeVersion",
|
|
||||||
subscribe,
|
|
||||||
name = "state_subscribeRuntimeVersion",
|
|
||||||
alias("chain_subscribeRuntimeVersion")
|
|
||||||
)]
|
|
||||||
fn subscribe_runtime_version(&self, metadata: Self::Metadata, subscriber: Subscriber<RuntimeVersion>);
|
|
||||||
|
|
||||||
/// Unsubscribe from runtime version subscription
|
|
||||||
#[pubsub(
|
|
||||||
subscription = "state_runtimeVersion",
|
|
||||||
unsubscribe,
|
|
||||||
name = "state_unsubscribeRuntimeVersion",
|
|
||||||
alias("chain_unsubscribeRuntimeVersion")
|
|
||||||
)]
|
|
||||||
fn unsubscribe_runtime_version(&self, metadata: Option<Self::Metadata>, id: SubscriptionId) -> RpcResult<bool>;
|
|
||||||
|
|
||||||
/// New storage subscription
|
|
||||||
#[pubsub(subscription = "state_storage", subscribe, name = "state_subscribeStorage")]
|
|
||||||
fn subscribe_storage(
|
|
||||||
&self, metadata: Self::Metadata, subscriber: Subscriber<StorageChangeSet<Hash>>, keys: Option<Vec<StorageKey>>
|
|
||||||
);
|
|
||||||
|
|
||||||
/// Unsubscribe from storage subscription
|
|
||||||
#[pubsub(subscription = "state_storage", unsubscribe, name = "state_unsubscribeStorage")]
|
|
||||||
fn unsubscribe_storage(
|
|
||||||
&self, metadata: Option<Self::Metadata>, id: SubscriptionId
|
|
||||||
) -> RpcResult<bool>;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// State API with subscriptions support.
|
/// State API with subscriptions support.
|
||||||
pub struct State<B, E, Block: BlockT, RA> {
|
pub struct State<B, E, Block: BlockT, RA> {
|
||||||
@@ -184,6 +68,10 @@ struct QueryStorageRange<Block: BlockT> {
|
|||||||
pub filtered_range: Option<Range<usize>>,
|
pub filtered_range: Option<Range<usize>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn client_err(err: client::error::Error) -> Error {
|
||||||
|
Error::Client(Box::new(err))
|
||||||
|
}
|
||||||
|
|
||||||
impl<B, E, Block: BlockT, RA> State<B, E, Block, RA> where
|
impl<B, E, Block: BlockT, RA> State<B, E, Block, RA> where
|
||||||
Block: BlockT<Hash=H256>,
|
Block: BlockT<Hash=H256>,
|
||||||
B: client::backend::Backend<Block, Blake2Hasher>,
|
B: client::backend::Backend<Block, Blake2Hasher>,
|
||||||
@@ -206,8 +94,8 @@ impl<B, E, Block: BlockT, RA> State<B, E, Block, RA> where
|
|||||||
to: Option<Block::Hash>
|
to: Option<Block::Hash>
|
||||||
) -> Result<QueryStorageRange<Block>> {
|
) -> Result<QueryStorageRange<Block>> {
|
||||||
let to = self.unwrap_or_best(to)?;
|
let to = self.unwrap_or_best(to)?;
|
||||||
let from_hdr = self.client.header(&BlockId::hash(from))?;
|
let from_hdr = self.client.header(&BlockId::hash(from)).map_err(client_err)?;
|
||||||
let to_hdr = self.client.header(&BlockId::hash(to))?;
|
let to_hdr = self.client.header(&BlockId::hash(to)).map_err(client_err)?;
|
||||||
match (from_hdr, to_hdr) {
|
match (from_hdr, to_hdr) {
|
||||||
(Some(ref from), Some(ref to)) if from.number() <= to.number() => {
|
(Some(ref from), Some(ref to)) if from.number() <= to.number() => {
|
||||||
// check if we can get from `to` to `from` by going through parent_hashes.
|
// check if we can get from `to` to `from` by going through parent_hashes.
|
||||||
@@ -216,7 +104,10 @@ impl<B, E, Block: BlockT, RA> State<B, E, Block, RA> where
|
|||||||
let mut blocks = vec![to.hash()];
|
let mut blocks = vec![to.hash()];
|
||||||
let mut last = to.clone();
|
let mut last = to.clone();
|
||||||
while *last.number() > from_number {
|
while *last.number() > from_number {
|
||||||
if let Some(hdr) = self.client.header(&BlockId::hash(*last.parent_hash()))? {
|
let hdr = self.client
|
||||||
|
.header(&BlockId::hash(*last.parent_hash()))
|
||||||
|
.map_err(client_err)?;
|
||||||
|
if let Some(hdr) = hdr {
|
||||||
blocks.push(hdr.hash());
|
blocks.push(hdr.hash());
|
||||||
last = hdr;
|
last = hdr;
|
||||||
} else {
|
} else {
|
||||||
@@ -238,7 +129,9 @@ impl<B, E, Block: BlockT, RA> State<B, E, Block, RA> where
|
|||||||
blocks
|
blocks
|
||||||
};
|
};
|
||||||
// check if we can filter blocks-with-changes from some (sub)range using changes tries
|
// check if we can filter blocks-with-changes from some (sub)range using changes tries
|
||||||
let changes_trie_range = self.client.max_key_changes_range(from_number, BlockId::Hash(to.hash()))?;
|
let changes_trie_range = self.client
|
||||||
|
.max_key_changes_range(from_number, BlockId::Hash(to.hash()))
|
||||||
|
.map_err(client_err)?;
|
||||||
let filtered_range_begin = changes_trie_range.map(|(begin, _)| (begin - from_number).saturated_into::<usize>());
|
let filtered_range_begin = changes_trie_range.map(|(begin, _)| (begin - from_number).saturated_into::<usize>());
|
||||||
let (unfiltered_range, filtered_range) = split_range(blocks.len(), filtered_range_begin);
|
let (unfiltered_range, filtered_range) = split_range(blocks.len(), filtered_range_begin);
|
||||||
Ok(QueryStorageRange {
|
Ok(QueryStorageRange {
|
||||||
@@ -268,7 +161,8 @@ impl<B, E, Block: BlockT, RA> State<B, E, Block, RA> where
|
|||||||
let id = BlockId::hash(block_hash);
|
let id = BlockId::hash(block_hash);
|
||||||
for key in keys {
|
for key in keys {
|
||||||
let (has_changed, data) = {
|
let (has_changed, data) = {
|
||||||
let curr_data = self.client.storage(&id, key)?;
|
let curr_data = self.client.storage(&id, key)
|
||||||
|
.map_err(client_err)?;
|
||||||
match last_values.get(key) {
|
match last_values.get(key) {
|
||||||
Some(prev_data) => (curr_data != *prev_data, curr_data),
|
Some(prev_data) => (curr_data != *prev_data, curr_data),
|
||||||
None => (true, curr_data),
|
None => (true, curr_data),
|
||||||
@@ -305,14 +199,14 @@ impl<B, E, Block: BlockT, RA> State<B, E, Block, RA> where
|
|||||||
for key in keys {
|
for key in keys {
|
||||||
let mut last_block = None;
|
let mut last_block = None;
|
||||||
let mut last_value = last_values.get(key).cloned().unwrap_or_default();
|
let mut last_value = last_values.get(key).cloned().unwrap_or_default();
|
||||||
for (block, _) in self.client.key_changes(begin, end, key)?.into_iter().rev() {
|
for (block, _) in self.client.key_changes(begin, end, key).map_err(client_err)?.into_iter().rev() {
|
||||||
if last_block == Some(block) {
|
if last_block == Some(block) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let block_hash = range.hashes[(block - range.first_number).saturated_into::<usize>()].clone();
|
let block_hash = range.hashes[(block - range.first_number).saturated_into::<usize>()].clone();
|
||||||
let id = BlockId::Hash(block_hash);
|
let id = BlockId::Hash(block_hash);
|
||||||
let value_at_block = self.client.storage(&id, key)?;
|
let value_at_block = self.client.storage(&id, key).map_err(client_err)?;
|
||||||
if last_value == value_at_block {
|
if last_value == value_at_block {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -360,26 +254,27 @@ impl<B, E, Block, RA> StateApi<Block::Hash> for State<B, E, Block, RA> where
|
|||||||
.call(
|
.call(
|
||||||
&BlockId::Hash(block),
|
&BlockId::Hash(block),
|
||||||
&method, &data.0, ExecutionStrategy::NativeElseWasm, state_machine::NeverOffchainExt::new(),
|
&method, &data.0, ExecutionStrategy::NativeElseWasm, state_machine::NeverOffchainExt::new(),
|
||||||
)?;
|
)
|
||||||
|
.map_err(client_err)?;
|
||||||
Ok(Bytes(return_data))
|
Ok(Bytes(return_data))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn storage_keys(&self, key_prefix: StorageKey, block: Option<Block::Hash>) -> Result<Vec<StorageKey>> {
|
fn storage_keys(&self, key_prefix: StorageKey, block: Option<Block::Hash>) -> Result<Vec<StorageKey>> {
|
||||||
let block = self.unwrap_or_best(block)?;
|
let block = self.unwrap_or_best(block)?;
|
||||||
trace!(target: "rpc", "Querying storage keys at {:?}", block);
|
trace!(target: "rpc", "Querying storage keys at {:?}", block);
|
||||||
Ok(self.client.storage_keys(&BlockId::Hash(block), &key_prefix)?)
|
Ok(self.client.storage_keys(&BlockId::Hash(block), &key_prefix).map_err(client_err)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn storage(&self, key: StorageKey, block: Option<Block::Hash>) -> Result<Option<StorageData>> {
|
fn storage(&self, key: StorageKey, block: Option<Block::Hash>) -> Result<Option<StorageData>> {
|
||||||
let block = self.unwrap_or_best(block)?;
|
let block = self.unwrap_or_best(block)?;
|
||||||
trace!(target: "rpc", "Querying storage at {:?} for key {}", block, HexDisplay::from(&key.0));
|
trace!(target: "rpc", "Querying storage at {:?} for key {}", block, HexDisplay::from(&key.0));
|
||||||
Ok(self.client.storage(&BlockId::Hash(block), &key)?)
|
Ok(self.client.storage(&BlockId::Hash(block), &key).map_err(client_err)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn storage_hash(&self, key: StorageKey, block: Option<Block::Hash>) -> Result<Option<Block::Hash>> {
|
fn storage_hash(&self, key: StorageKey, block: Option<Block::Hash>) -> Result<Option<Block::Hash>> {
|
||||||
let block = self.unwrap_or_best(block)?;
|
let block = self.unwrap_or_best(block)?;
|
||||||
trace!(target: "rpc", "Querying storage hash at {:?} for key {}", block, HexDisplay::from(&key.0));
|
trace!(target: "rpc", "Querying storage hash at {:?} for key {}", block, HexDisplay::from(&key.0));
|
||||||
Ok(self.client.storage_hash(&BlockId::Hash(block), &key)?)
|
Ok(self.client.storage_hash(&BlockId::Hash(block), &key).map_err(client_err)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn storage_size(&self, key: StorageKey, block: Option<Block::Hash>) -> Result<Option<u64>> {
|
fn storage_size(&self, key: StorageKey, block: Option<Block::Hash>) -> Result<Option<u64>> {
|
||||||
@@ -394,7 +289,10 @@ impl<B, E, Block, RA> StateApi<Block::Hash> for State<B, E, Block, RA> where
|
|||||||
) -> Result<Option<StorageData>> {
|
) -> Result<Option<StorageData>> {
|
||||||
let block = self.unwrap_or_best(block)?;
|
let block = self.unwrap_or_best(block)?;
|
||||||
trace!(target: "rpc", "Querying child storage at {:?} for key {}", block, HexDisplay::from(&key.0));
|
trace!(target: "rpc", "Querying child storage at {:?} for key {}", block, HexDisplay::from(&key.0));
|
||||||
Ok(self.client.child_storage(&BlockId::Hash(block), &child_storage_key, &key)?)
|
Ok(self.client
|
||||||
|
.child_storage(&BlockId::Hash(block), &child_storage_key, &key)
|
||||||
|
.map_err(client_err)?
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn child_storage_keys(
|
fn child_storage_keys(
|
||||||
@@ -405,7 +303,10 @@ impl<B, E, Block, RA> StateApi<Block::Hash> for State<B, E, Block, RA> where
|
|||||||
) -> Result<Vec<StorageKey>> {
|
) -> Result<Vec<StorageKey>> {
|
||||||
let block = self.unwrap_or_best(block)?;
|
let block = self.unwrap_or_best(block)?;
|
||||||
trace!(target: "rpc", "Querying child storage keys at {:?}", block);
|
trace!(target: "rpc", "Querying child storage keys at {:?}", block);
|
||||||
Ok(self.client.child_storage_keys(&BlockId::Hash(block), &child_storage_key, &key_prefix)?)
|
Ok(self.client
|
||||||
|
.child_storage_keys(&BlockId::Hash(block), &child_storage_key, &key_prefix)
|
||||||
|
.map_err(client_err)?
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn child_storage_hash(
|
fn child_storage_hash(
|
||||||
@@ -420,7 +321,10 @@ impl<B, E, Block, RA> StateApi<Block::Hash> for State<B, E, Block, RA> where
|
|||||||
block,
|
block,
|
||||||
HexDisplay::from(&key.0),
|
HexDisplay::from(&key.0),
|
||||||
);
|
);
|
||||||
Ok(self.client.child_storage_hash(&BlockId::Hash(block), &child_storage_key, &key)?)
|
Ok(self.client
|
||||||
|
.child_storage_hash(&BlockId::Hash(block), &child_storage_key, &key)
|
||||||
|
.map_err(client_err)?
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn child_storage_size(
|
fn child_storage_size(
|
||||||
@@ -434,7 +338,11 @@ impl<B, E, Block, RA> StateApi<Block::Hash> for State<B, E, Block, RA> where
|
|||||||
|
|
||||||
fn metadata(&self, block: Option<Block::Hash>) -> Result<Bytes> {
|
fn metadata(&self, block: Option<Block::Hash>) -> Result<Bytes> {
|
||||||
let block = self.unwrap_or_best(block)?;
|
let block = self.unwrap_or_best(block)?;
|
||||||
self.client.runtime_api().metadata(&BlockId::Hash(block)).map(Into::into).map_err(Into::into)
|
self.client
|
||||||
|
.runtime_api()
|
||||||
|
.metadata(&BlockId::Hash(block))
|
||||||
|
.map(Into::into)
|
||||||
|
.map_err(client_err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn query_storage(
|
fn query_storage(
|
||||||
@@ -464,7 +372,7 @@ impl<B, E, Block, RA> StateApi<Block::Hash> for State<B, E, Block, RA> where
|
|||||||
) {
|
) {
|
||||||
Ok(stream) => stream,
|
Ok(stream) => stream,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
let _ = subscriber.reject(error::Error::from(err).into());
|
let _ = subscriber.reject(client_err(err).into());
|
||||||
return;
|
return;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -508,7 +416,7 @@ impl<B, E, Block, RA> StateApi<Block::Hash> for State<B, E, Block, RA> where
|
|||||||
|
|
||||||
fn runtime_version(&self, at: Option<Block::Hash>) -> Result<RuntimeVersion> {
|
fn runtime_version(&self, at: Option<Block::Hash>) -> Result<RuntimeVersion> {
|
||||||
let at = self.unwrap_or_best(at)?;
|
let at = self.unwrap_or_best(at)?;
|
||||||
Ok(self.client.runtime_version_at(&BlockId::Hash(at))?)
|
Ok(self.client.runtime_version_at(&BlockId::Hash(at)).map_err(client_err)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn subscribe_runtime_version(&self, _meta: Self::Metadata, subscriber: Subscriber<RuntimeVersion>) {
|
fn subscribe_runtime_version(&self, _meta: Self::Metadata, subscriber: Subscriber<RuntimeVersion>) {
|
||||||
@@ -518,7 +426,7 @@ impl<B, E, Block, RA> StateApi<Block::Hash> for State<B, E, Block, RA> where
|
|||||||
) {
|
) {
|
||||||
Ok(stream) => stream,
|
Ok(stream) => stream,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
let _ = subscriber.reject(error::Error::from(err).into());
|
let _ = subscriber.reject(client_err(err).into());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -535,7 +443,7 @@ impl<B, E, Block, RA> StateApi<Block::Hash> for State<B, E, Block, RA> where
|
|||||||
let info = client.info();
|
let info = client.info();
|
||||||
let version = client
|
let version = client
|
||||||
.runtime_version_at(&BlockId::hash(info.chain.best_hash))
|
.runtime_version_at(&BlockId::hash(info.chain.best_hash))
|
||||||
.map_err(error::Error::from)
|
.map_err(client_err)
|
||||||
.map_err(Into::into);
|
.map_err(Into::into);
|
||||||
if previous_version != version {
|
if previous_version != version {
|
||||||
previous_version = version.clone();
|
previous_version = version.clone();
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ fn should_call_contract() {
|
|||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
client.call("balanceOf".into(), Bytes(vec![1,2,3]), Some(genesis_hash).into()),
|
client.call("balanceOf".into(), Bytes(vec![1,2,3]), Some(genesis_hash).into()),
|
||||||
Err(Error::Client(client::error::Error::Execution(_)))
|
Err(Error::Client(_))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,62 +16,18 @@
|
|||||||
|
|
||||||
//! Substrate system API.
|
//! Substrate system API.
|
||||||
|
|
||||||
pub mod error;
|
|
||||||
pub mod helpers;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
use crate::helpers::Receiver;
|
|
||||||
use futures03::{channel::{mpsc, oneshot}, compat::Compat};
|
use futures03::{channel::{mpsc, oneshot}, compat::Compat};
|
||||||
use jsonrpc_derive::rpc;
|
use api::Receiver;
|
||||||
use network;
|
|
||||||
use sr_primitives::traits::{self, Header as HeaderT};
|
use sr_primitives::traits::{self, Header as HeaderT};
|
||||||
|
|
||||||
use self::error::Result;
|
use self::error::Result;
|
||||||
|
|
||||||
|
pub use api::system::*;
|
||||||
pub use self::helpers::{Properties, SystemInfo, Health, PeerInfo};
|
pub use self::helpers::{Properties, SystemInfo, Health, PeerInfo};
|
||||||
pub use self::gen_client::Client as SystemClient;
|
pub use self::gen_client::Client as SystemClient;
|
||||||
|
|
||||||
/// Substrate system RPC API
|
|
||||||
#[rpc]
|
|
||||||
pub trait SystemApi<Hash, Number> {
|
|
||||||
/// Get the node's implementation name. Plain old string.
|
|
||||||
#[rpc(name = "system_name")]
|
|
||||||
fn system_name(&self) -> Result<String>;
|
|
||||||
|
|
||||||
/// Get the node implementation's version. Should be a semver string.
|
|
||||||
#[rpc(name = "system_version")]
|
|
||||||
fn system_version(&self) -> Result<String>;
|
|
||||||
|
|
||||||
/// Get the chain's type. Given as a string identifier.
|
|
||||||
#[rpc(name = "system_chain")]
|
|
||||||
fn system_chain(&self) -> Result<String>;
|
|
||||||
|
|
||||||
/// Get a custom set of properties as a JSON object, defined in the chain spec.
|
|
||||||
#[rpc(name = "system_properties")]
|
|
||||||
fn system_properties(&self) -> Result<Properties>;
|
|
||||||
|
|
||||||
/// Return health status of the node.
|
|
||||||
///
|
|
||||||
/// Node is considered healthy if it is:
|
|
||||||
/// - connected to some peers (unless running in dev mode)
|
|
||||||
/// - not performing a major sync
|
|
||||||
#[rpc(name = "system_health", returns = "Health")]
|
|
||||||
fn system_health(&self) -> Receiver<Health>;
|
|
||||||
|
|
||||||
/// Returns currently connected peers
|
|
||||||
#[rpc(name = "system_peers", returns = "Vec<PeerInfo<Hash, Number>>")]
|
|
||||||
fn system_peers(&self) -> Receiver<Vec<PeerInfo<Hash, Number>>>;
|
|
||||||
|
|
||||||
/// Returns current state of the network.
|
|
||||||
///
|
|
||||||
/// **Warning**: This API is not stable.
|
|
||||||
// TODO: make this stable and move structs https://github.com/paritytech/substrate/issues/1890
|
|
||||||
#[rpc(name = "system_networkState", returns = "network::NetworkState")]
|
|
||||||
fn system_network_state(&self) -> Receiver<network::NetworkState>;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// System API implementation
|
/// System API implementation
|
||||||
pub struct System<B: traits::Block> {
|
pub struct System<B: traits::Block> {
|
||||||
info: SystemInfo,
|
info: SystemInfo,
|
||||||
@@ -85,7 +41,7 @@ pub enum Request<B: traits::Block> {
|
|||||||
/// Must return information about the peers we are connected to.
|
/// Must return information about the peers we are connected to.
|
||||||
Peers(oneshot::Sender<Vec<PeerInfo<B::Hash, <B::Header as HeaderT>::Number>>>),
|
Peers(oneshot::Sender<Vec<PeerInfo<B::Hash, <B::Header as HeaderT>::Number>>>),
|
||||||
/// Must return the state of the network.
|
/// Must return the state of the network.
|
||||||
NetworkState(oneshot::Sender<network::NetworkState>),
|
NetworkState(oneshot::Sender<rpc::Value>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: traits::Block> System<B> {
|
impl<B: traits::Block> System<B> {
|
||||||
@@ -133,7 +89,7 @@ impl<B: traits::Block> SystemApi<B::Hash, <B::Header as HeaderT>::Number> for Sy
|
|||||||
Receiver(Compat::new(rx))
|
Receiver(Compat::new(rx))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn system_network_state(&self) -> Receiver<network::NetworkState> {
|
fn system_network_state(&self) -> Receiver<rpc::Value> {
|
||||||
let (tx, rx) = oneshot::channel();
|
let (tx, rx) = oneshot::channel();
|
||||||
let _ = self.send_back.unbounded_send(Request::NetworkState(tx));
|
let _ = self.send_back.unbounded_send(Request::NetworkState(tx));
|
||||||
Receiver(Compat::new(rx))
|
Receiver(Compat::new(rx))
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ fn api<T: Into<Option<Status>>>(sync: T) -> System<Block> {
|
|||||||
let _ = sender.send(peers);
|
let _ = sender.send(peers);
|
||||||
}
|
}
|
||||||
Request::NetworkState(sender) => {
|
Request::NetworkState(sender) => {
|
||||||
let _ = sender.send(network::NetworkState {
|
let _ = sender.send(serde_json::to_value(&network::NetworkState {
|
||||||
peer_id: String::new(),
|
peer_id: String::new(),
|
||||||
listened_addresses: Default::default(),
|
listened_addresses: Default::default(),
|
||||||
external_addresses: Default::default(),
|
external_addresses: Default::default(),
|
||||||
@@ -78,7 +78,7 @@ fn api<T: Into<Option<Status>>>(sync: T) -> System<Block> {
|
|||||||
average_download_per_sec: 0,
|
average_download_per_sec: 0,
|
||||||
average_upload_per_sec: 0,
|
average_upload_per_sec: 0,
|
||||||
peerset: serde_json::Value::Null,
|
peerset: serde_json::Value::Null,
|
||||||
});
|
}).unwrap());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -206,8 +206,9 @@ fn system_peers() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn system_network_state() {
|
fn system_network_state() {
|
||||||
|
let res = wait_receiver(api(None).system_network_state());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
wait_receiver(api(None).system_network_state()),
|
serde_json::from_value::<network::NetworkState>(res).unwrap(),
|
||||||
network::NetworkState {
|
network::NetworkState {
|
||||||
peer_id: String::new(),
|
peer_id: String::new(),
|
||||||
listened_addresses: Default::default(),
|
listened_addresses: Default::default(),
|
||||||
|
|||||||
@@ -725,7 +725,9 @@ fn build_network_future<
|
|||||||
).collect());
|
).collect());
|
||||||
}
|
}
|
||||||
rpc::system::Request::NetworkState(sender) => {
|
rpc::system::Request::NetworkState(sender) => {
|
||||||
let _ = sender.send(network.network_state());
|
if let Some(network_state) = serde_json::to_value(&network.network_state()).ok() {
|
||||||
|
let _ = sender.send(network_state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user