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:
Tomasz Drwięga
2019-06-04 18:43:55 +02:00
committed by Gavin Wood
parent 5df89a8a6f
commit 6112f815b3
18 changed files with 289 additions and 103 deletions
+3
View File
@@ -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 -15
View File
@@ -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> {
+4 -2
View File
@@ -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.