mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 03:31:10 +00:00
JSON-RPC client generation (#2778)
* Bump jsonrpc & generate clients. * Initial version of JSON-RPC client. * Re-wort * Remove spurious `#[derive(Encode, Decode)]` They did not compile, since `Encode` and `Decode` are deliberately not implemented for `usize`. Fixes #2742. * Re-write rpc-client example. * Update to jsonrpc=12.0.0 * Remove unnecessary import * Bump version. * Revert version bump. * Bump again.
This commit is contained in:
committed by
Gavin Wood
parent
5df89a8a6f
commit
6112f815b3
@@ -6,9 +6,10 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
derive_more = "0.14.0"
|
||||
jsonrpc-core = "10.0.1"
|
||||
jsonrpc-pubsub = "10.0.1"
|
||||
jsonrpc-derive = "10.0.2"
|
||||
jsonrpc-core = "12.0.0"
|
||||
jsonrpc-core-client = "12.0.0"
|
||||
jsonrpc-pubsub = "12.0.0"
|
||||
jsonrpc-derive = "12.0.0"
|
||||
log = "0.4"
|
||||
parking_lot = "0.7.1"
|
||||
parity-codec = "3.3"
|
||||
|
||||
@@ -14,13 +14,15 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Extrinsic helpers for author RPC module.
|
||||
|
||||
use primitives::Bytes;
|
||||
use serde::Deserialize;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
/// RPC Extrinsic or hash
|
||||
///
|
||||
/// Allows to refer to extrinsic either by its raw representation or its hash.
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum ExtrinsicOrHash<Hash> {
|
||||
/// The hash of the extrinsic.
|
||||
|
||||
@@ -16,6 +16,12 @@
|
||||
|
||||
//! Substrate block-author/full-node API.
|
||||
|
||||
pub mod error;
|
||||
pub mod hash;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use client::{self, Client};
|
||||
@@ -27,6 +33,7 @@ use log::warn;
|
||||
use parity_codec::{Encode, Decode};
|
||||
use primitives::{Bytes, Blake2Hasher, H256};
|
||||
use runtime_primitives::{generic, traits};
|
||||
use self::error::Result;
|
||||
use transaction_pool::{
|
||||
txpool::{
|
||||
ChainApi as PoolChainApi,
|
||||
@@ -38,13 +45,7 @@ use transaction_pool::{
|
||||
},
|
||||
};
|
||||
|
||||
pub mod error;
|
||||
mod hash;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
use self::error::Result;
|
||||
pub use self::gen_client::Client as AuthorClient;
|
||||
|
||||
/// Substrate authoring RPC API
|
||||
#[rpc]
|
||||
|
||||
@@ -14,6 +14,9 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
//! Error helpers for Chain RPC module.
|
||||
|
||||
use client;
|
||||
use crate::rpc;
|
||||
use crate::errors;
|
||||
|
||||
@@ -16,27 +16,28 @@
|
||||
|
||||
//! Substrate blockchain API.
|
||||
|
||||
use std::sync::Arc;
|
||||
pub mod error;
|
||||
pub mod number;
|
||||
|
||||
use log::warn;
|
||||
use client::{self, Client, BlockchainEvents};
|
||||
use jsonrpc_derive::rpc;
|
||||
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId};
|
||||
use primitives::{H256, Blake2Hasher};
|
||||
use crate::rpc::Result as RpcResult;
|
||||
use crate::rpc::futures::{stream, Future, Sink, Stream};
|
||||
use runtime_primitives::generic::{BlockId, SignedBlock};
|
||||
use runtime_primitives::traits::{Block as BlockT, Header, NumberFor};
|
||||
|
||||
use crate::subscriptions::Subscriptions;
|
||||
|
||||
mod error;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
mod number;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use client::{self, Client, BlockchainEvents};
|
||||
use crate::rpc::Result as RpcResult;
|
||||
use crate::rpc::futures::{stream, Future, Sink, Stream};
|
||||
use crate::subscriptions::Subscriptions;
|
||||
use jsonrpc_derive::rpc;
|
||||
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId};
|
||||
use log::warn;
|
||||
use primitives::{H256, Blake2Hasher};
|
||||
use runtime_primitives::generic::{BlockId, SignedBlock};
|
||||
use runtime_primitives::traits::{Block as BlockT, Header, NumberFor};
|
||||
use self::error::Result;
|
||||
|
||||
pub use self::gen_client::Client as ChainClient;
|
||||
|
||||
/// Substrate blockchain API
|
||||
#[rpc]
|
||||
pub trait ChainApi<Number, Hash, Header, SignedBlock> {
|
||||
|
||||
@@ -14,7 +14,9 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use serde::Deserialize;
|
||||
//! Chain RPC Block number type.
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
use std::{convert::TryFrom, fmt::Debug};
|
||||
use primitives::U256;
|
||||
|
||||
@@ -25,7 +27,7 @@ use primitives::U256;
|
||||
/// or we attempt to parse given hex value.
|
||||
/// We do that for consistency with the returned type, default generic header
|
||||
/// serializes block number as hex to avoid overflows in JavaScript.
|
||||
#[derive(Deserialize)]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum NumberOrHex<Number> {
|
||||
/// The original header number type of block.
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! State RPC errors.
|
||||
|
||||
use client;
|
||||
use crate::rpc;
|
||||
use crate::errors;
|
||||
@@ -29,8 +31,11 @@ pub enum Error {
|
||||
/// Provided block range couldn't be resolved to a list of blocks.
|
||||
#[display(fmt = "Cannot resolve a block range ['{:?}' ... '{:?}]. {}", from, to, details)]
|
||||
InvalidBlockRange {
|
||||
/// Beginning of the block range.
|
||||
from: String,
|
||||
/// End of the block range.
|
||||
to: String,
|
||||
/// Details of the error message.
|
||||
details: String,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -16,36 +16,37 @@
|
||||
|
||||
//! Substrate state API.
|
||||
|
||||
pub mod error;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
use std::{
|
||||
collections::{BTreeMap, HashMap},
|
||||
ops::Range,
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use log::{warn, trace};
|
||||
use client::{self, Client, CallExecutor, BlockchainEvents, runtime_api::Metadata};
|
||||
use jsonrpc_derive::rpc;
|
||||
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId};
|
||||
use primitives::{H256, Blake2Hasher, Bytes};
|
||||
use primitives::hexdisplay::HexDisplay;
|
||||
use primitives::storage::{self, StorageKey, StorageData, StorageChangeSet};
|
||||
use crate::rpc::Result as RpcResult;
|
||||
use crate::rpc::futures::{stream, Future, Sink, Stream};
|
||||
use crate::subscriptions::Subscriptions;
|
||||
use jsonrpc_derive::rpc;
|
||||
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId};
|
||||
use log::{warn, trace};
|
||||
use primitives::hexdisplay::HexDisplay;
|
||||
use primitives::storage::{self, StorageKey, StorageData, StorageChangeSet};
|
||||
use primitives::{H256, Blake2Hasher, Bytes};
|
||||
use runtime_primitives::generic::BlockId;
|
||||
use runtime_primitives::traits::{
|
||||
Block as BlockT, Header, ProvideRuntimeApi, NumberFor,
|
||||
SaturatedConversion
|
||||
};
|
||||
use runtime_version::RuntimeVersion;
|
||||
use self::error::Result;
|
||||
use state_machine::{self, ExecutionStrategy};
|
||||
|
||||
use crate::subscriptions::Subscriptions;
|
||||
|
||||
mod error;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
use self::error::Result;
|
||||
pub use self::gen_client::Client as StateClient;
|
||||
|
||||
/// Substrate state API
|
||||
#[rpc]
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
//! Substrate system API helpers.
|
||||
|
||||
use std::fmt;
|
||||
use serde::Serialize;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde_json::{Value, map::Map};
|
||||
|
||||
/// Node properties
|
||||
@@ -37,7 +37,7 @@ pub struct SystemInfo {
|
||||
}
|
||||
|
||||
/// Health struct returned by the RPC
|
||||
#[derive(Debug, PartialEq, Serialize)]
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Health {
|
||||
/// Number of connected peers
|
||||
@@ -51,7 +51,7 @@ pub struct Health {
|
||||
}
|
||||
|
||||
/// Network Peer information
|
||||
#[derive(Debug, PartialEq, Serialize)]
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PeerInfo<Hash, Number> {
|
||||
/// Peer ID
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
//! Substrate system API.
|
||||
|
||||
pub mod error;
|
||||
pub mod helpers;
|
||||
|
||||
mod helpers;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
@@ -30,6 +30,8 @@ use runtime_primitives::traits::{self, Header as HeaderT};
|
||||
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> {
|
||||
|
||||
Reference in New Issue
Block a user