From 1114ad3ca701ebb13100c34be81ac73bbaafad09 Mon Sep 17 00:00:00 2001 From: GitLab Build Bot Date: Tue, 13 Dec 2016 05:15:44 +0000 Subject: [PATCH 1/3] [ci skip] js-precompiled 20161213-051314 --- Cargo.lock | 2 +- js/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 316978f20..9095934c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1290,7 +1290,7 @@ dependencies = [ [[package]] name = "parity-ui-precompiled" version = "1.4.0" -source = "git+https://github.com/ethcore/js-precompiled.git#b29e2a151561ae41aa27af3b226522844ae8aae2" +source = "git+https://github.com/ethcore/js-precompiled.git#a8f4db707c521f71f093b62e3173b98144569c4e" dependencies = [ "parity-dapps-glue 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/js/package.json b/js/package.json index 5cbdd6bf3..36cd9ad5a 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "parity.js", - "version": "0.2.120", + "version": "0.2.121", "main": "release/index.js", "jsnext:main": "src/index.js", "author": "Parity Team ", From f47be5084370e5ee1f64621fb605c7f0559e20a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Tue, 13 Dec 2016 14:27:27 +0100 Subject: [PATCH 2/3] Using jsonrpc-macros --- Cargo.lock | 33 ++- rpc/Cargo.toml | 1 + rpc/src/lib.rs | 2 + rpc/src/v1/helpers/auto_args.rs | 310 --------------------------- rpc/src/v1/helpers/mod.rs | 4 - rpc/src/v1/helpers/params.rs | 46 ---- rpc/src/v1/impls/eth.rs | 2 +- rpc/src/v1/impls/parity.rs | 2 +- rpc/src/v1/impls/parity_set.rs | 2 +- rpc/src/v1/impls/signing.rs | 2 +- rpc/src/v1/impls/signing_unsafe.rs | 2 +- rpc/src/v1/impls/traces.rs | 20 +- rpc/src/v1/traits/eth.rs | 2 +- rpc/src/v1/traits/eth_signing.rs | 3 +- rpc/src/v1/traits/net.rs | 4 +- rpc/src/v1/traits/parity.rs | 6 +- rpc/src/v1/traits/parity_accounts.rs | 3 +- rpc/src/v1/traits/parity_set.rs | 2 +- rpc/src/v1/traits/parity_signing.rs | 2 +- rpc/src/v1/traits/personal.rs | 1 - rpc/src/v1/traits/rpc.rs | 8 +- rpc/src/v1/traits/signer.rs | 2 - rpc/src/v1/traits/traces.rs | 3 +- rpc/src/v1/traits/web3.rs | 2 - 24 files changed, 59 insertions(+), 405 deletions(-) delete mode 100644 rpc/src/v1/helpers/auto_args.rs delete mode 100644 rpc/src/v1/helpers/params.rs diff --git a/Cargo.lock b/Cargo.lock index 9095934c4..6bd3257be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -530,6 +530,7 @@ dependencies = [ "jsonrpc-core 4.0.0 (git+https://github.com/ethcore/jsonrpc.git)", "jsonrpc-http-server 6.1.1 (git+https://github.com/ethcore/jsonrpc.git)", "jsonrpc-ipc-server 0.2.4 (git+https://github.com/ethcore/jsonrpc.git)", + "jsonrpc-macros 0.1.0 (git+https://github.com/ethcore/jsonrpc.git)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.1.0", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", @@ -860,10 +861,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "jsonrpc-core" version = "4.0.0" -source = "git+https://github.com/ethcore/jsonrpc.git#1500da1b9613a0a17fc0109d825f3ccc60199a53" +source = "git+https://github.com/ethcore/jsonrpc.git#33262d626a294a00c20435dec331058ba65e224a" dependencies = [ "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde_codegen 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -872,7 +873,7 @@ dependencies = [ [[package]] name = "jsonrpc-http-server" version = "6.1.1" -source = "git+https://github.com/ethcore/jsonrpc.git#1500da1b9613a0a17fc0109d825f3ccc60199a53" +source = "git+https://github.com/ethcore/jsonrpc.git#33262d626a294a00c20435dec331058ba65e224a" dependencies = [ "hyper 0.10.0-a.0 (git+https://github.com/ethcore/hyper)", "jsonrpc-core 4.0.0 (git+https://github.com/ethcore/jsonrpc.git)", @@ -883,7 +884,7 @@ dependencies = [ [[package]] name = "jsonrpc-ipc-server" version = "0.2.4" -source = "git+https://github.com/ethcore/jsonrpc.git#1500da1b9613a0a17fc0109d825f3ccc60199a53" +source = "git+https://github.com/ethcore/jsonrpc.git#33262d626a294a00c20435dec331058ba65e224a" dependencies = [ "bytes 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -895,10 +896,19 @@ dependencies = [ "slab 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "jsonrpc-macros" +version = "0.1.0" +source = "git+https://github.com/ethcore/jsonrpc.git#33262d626a294a00c20435dec331058ba65e224a" +dependencies = [ + "jsonrpc-core 4.0.0 (git+https://github.com/ethcore/jsonrpc.git)", + "serde 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "jsonrpc-tcp-server" version = "0.1.0" -source = "git+https://github.com/ethcore/jsonrpc.git#1500da1b9613a0a17fc0109d825f3ccc60199a53" +source = "git+https://github.com/ethcore/jsonrpc.git#33262d626a294a00c20435dec331058ba65e224a" dependencies = [ "bytes 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1295,17 +1305,6 @@ dependencies = [ "parity-dapps-glue 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "parking_lot" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "parking_lot" version = "0.3.5" @@ -2065,6 +2064,7 @@ dependencies = [ "checksum jsonrpc-core 4.0.0 (git+https://github.com/ethcore/jsonrpc.git)" = "" "checksum jsonrpc-http-server 6.1.1 (git+https://github.com/ethcore/jsonrpc.git)" = "" "checksum jsonrpc-ipc-server 0.2.4 (git+https://github.com/ethcore/jsonrpc.git)" = "" +"checksum jsonrpc-macros 0.1.0 (git+https://github.com/ethcore/jsonrpc.git)" = "" "checksum jsonrpc-tcp-server 0.1.0 (git+https://github.com/ethcore/jsonrpc.git)" = "" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" @@ -2107,7 +2107,6 @@ dependencies = [ "checksum owning_ref 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8d91377085359426407a287ab16884a0111ba473aa6844ff01d4ec20ce3d75e7" "checksum parity-dapps-glue 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "98378dec0a185da2b7180308752f0bad73aaa949c3e0a3b0528d0e067945f7ab" "checksum parity-ui-precompiled 1.4.0 (git+https://github.com/ethcore/js-precompiled.git)" = "" -"checksum parking_lot 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "968f685642555d2f7e202c48b8b11de80569e9bfea817f7f12d7c61aac62d4e6" "checksum parking_lot 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "dbc5847584161f273e69edc63c1a86254a22f570a0b5dd87aa6f9773f6f7d125" "checksum parking_lot_core 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fb1b97670a2ffadce7c397fb80a3d687c4f3060140b885621ef1653d0e5d5068" "checksum phf 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)" = "447d9d45f2e0b4a9b532e808365abf18fc211be6ca217202fcd45236ef12f026" diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index 5d974e59f..d766af674 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -15,6 +15,7 @@ serde_json = "0.8" jsonrpc-core = { git = "https://github.com/ethcore/jsonrpc.git" } jsonrpc-http-server = { git = "https://github.com/ethcore/jsonrpc.git" } jsonrpc-ipc-server = { git = "https://github.com/ethcore/jsonrpc.git" } +jsonrpc-macros = { git = "https://github.com/ethcore/jsonrpc.git" } ethcore-io = { path = "../util/io" } ethcore-util = { path = "../util" } ethcore = { path = "../ethcore" } diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index bbd4a5164..7f105b0d0 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -24,6 +24,8 @@ extern crate serde; extern crate serde_json; extern crate jsonrpc_core; extern crate jsonrpc_http_server; +#[macro_use] +extern crate jsonrpc_macros; extern crate ethcore_io as io; extern crate ethcore; diff --git a/rpc/src/v1/helpers/auto_args.rs b/rpc/src/v1/helpers/auto_args.rs deleted file mode 100644 index 9c4e1d74a..000000000 --- a/rpc/src/v1/helpers/auto_args.rs +++ /dev/null @@ -1,310 +0,0 @@ -// Copyright 2015, 2016 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity 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. - -// Parity 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 Parity. If not, see . - -//! Automatically serialize and deserialize parameters around a strongly-typed function. - -// because we reuse the type names as idents in the macros as a dirty hack to -// work around `concat_idents!` being unstable. -#![allow(non_snake_case)] - -use super::errors; - -use jsonrpc_core::{Error, Params, Value, from_params, to_value}; -use serde::{Serialize, Deserialize}; - -/// Auto-generates an RPC trait from trait definition. -/// -/// This just copies out all the methods, docs, and adds another -/// function `to_delegate` which will automatically wrap each strongly-typed -/// function in a wrapper which handles parameter and output type serialization. -/// -/// RPC functions may come in a couple forms: async and synchronous. -/// These are parsed with the custom `#[rpc]` attribute, which must follow -/// documentation. -/// -/// ## The #[rpc] attribute -/// -/// Valid forms: -/// - `#[rpc(name = "name_here")]` (a synchronous rpc function which should be bound to the given name) -/// - `#[rpc(async, name = "name_here")]` (an async rpc function which should be bound to the given name) -/// -/// Synchronous function format: -/// `fn foo(&self, Param1, Param2, Param3) -> Out`. -/// -/// Asynchronous RPC functions must come in this form: -/// `fn foo(&self, Param1, Param2, Param3, Ready); -/// -/// Anything else will be rejected by the code generator. -macro_rules! build_rpc_trait { - // entry-point. todo: make another for traits w/ bounds. - ( - $(#[$t_attr: meta])* - pub trait $name: ident { - $( - $( #[doc=$m_doc:expr] )* - #[ rpc( $($t:tt)* ) ] - fn $m_name: ident ( $($p: tt)* ) $( -> Result<$out: ty, Error> )* ; - )* - } - ) => { - $(#[$t_attr])* - pub trait $name: Sized + Send + Sync + 'static { - $( - $(#[doc=$m_doc])* - fn $m_name ( $($p)* ) $( -> Result<$out, Error> )* ; - )* - - /// Transform this into an `IoDelegate`, automatically wrapping - /// the parameters. - fn to_delegate(self) -> ::jsonrpc_core::IoDelegate { - let mut del = ::jsonrpc_core::IoDelegate::new(self.into()); - $( - build_rpc_trait!(WRAP del => - ( $($t)* ) - fn $m_name ( $($p)* ) $( -> Result<$out, Error> )* - ); - )* - del - } - } - }; - - ( WRAP $del: expr => - (name = $name: expr) - fn $method: ident (&self $(, $param: ty)*) -> Result<$out: ty, Error> - ) => { - $del.add_method($name, move |base, params| { - (Self::$method as fn(&_ $(, $param)*) -> Result<$out, Error>).wrap_rpc(base, params) - }) - }; - - ( WRAP $del: expr => - (async, name = $name: expr) - fn $method: ident (&self, Ready<$out: ty> $(, $param: ty)*) - ) => { - $del.add_async_method($name, move |base, params, ready| { - (Self::$method as fn(&_, Ready<$out> $(, $param)*)).wrap_rpc(base, params, ready) - }) - }; -} - -/// A wrapper type without an implementation of `Deserialize` -/// which allows a special implementation of `Wrap` for functions -/// that take a trailing default parameter. -pub struct Trailing(pub T); - -/// A wrapper type for `jsonrpc_core`'s weakly-typed `Ready` struct. -pub struct Ready { - inner: ::jsonrpc_core::Ready, - _marker: ::std::marker::PhantomData, -} - -impl From<::jsonrpc_core::Ready> for Ready { - fn from(ready: ::jsonrpc_core::Ready) -> Self { - Ready { inner: ready, _marker: ::std::marker::PhantomData } - } -} - -impl Ready { - /// Respond withthe asynchronous result. - pub fn ready(self, result: Result) { - self.inner.ready(result.map(to_value)) - } -} - -/// Wrapper trait for synchronous RPC functions. -pub trait Wrap { - fn wrap_rpc(&self, base: &B, params: Params) -> Result; -} - -/// Wrapper trait for asynchronous RPC functions. -pub trait WrapAsync { - fn wrap_rpc(&self, base: &B, params: Params, ready: ::jsonrpc_core::Ready); -} - -// special impl for no parameters. -impl Wrap for fn(&B) -> Result - where B: Send + Sync + 'static, OUT: Serialize -{ - fn wrap_rpc(&self, base: &B, params: Params) -> Result { - ::v1::helpers::params::expect_no_params(params) - .and_then(|()| (self)(base)) - .map(to_value) - } -} - -impl WrapAsync for fn(&B, Ready) - where B: Send + Sync + 'static, OUT: Serialize -{ - fn wrap_rpc(&self, base: &B, params: Params, ready: ::jsonrpc_core::Ready) { - match ::v1::helpers::params::expect_no_params(params) { - Ok(()) => (self)(base, ready.into()), - Err(e) => ready.ready(Err(e)), - } - } -} - -// creates a wrapper implementation which deserializes the parameters, -// calls the function with concrete type, and serializes the output. -macro_rules! wrap { - ($($x: ident),+) => { - - // synchronous implementation - impl < - BASE: Send + Sync + 'static, - OUT: Serialize, - $($x: Deserialize,)+ - > Wrap for fn(&BASE, $($x,)+) -> Result { - fn wrap_rpc(&self, base: &BASE, params: Params) -> Result { - from_params::<($($x,)+)>(params).and_then(|($($x,)+)| { - (self)(base, $($x,)+) - }).map(to_value) - } - } - - // asynchronous implementation - impl < - BASE: Send + Sync + 'static, - OUT: Serialize, - $($x: Deserialize,)+ - > WrapAsync for fn(&BASE, Ready, $($x,)+ ) { - fn wrap_rpc(&self, base: &BASE, params: Params, ready: ::jsonrpc_core::Ready) { - match from_params::<($($x,)+)>(params) { - Ok(($($x,)+)) => (self)(base, ready.into(), $($x,)+), - Err(e) => ready.ready(Err(e)), - } - } - } - } -} - -// special impl for no parameters other than block parameter. -impl Wrap for fn(&B, Trailing) -> Result - where B: Send + Sync + 'static, OUT: Serialize, T: Default + Deserialize -{ - fn wrap_rpc(&self, base: &B, params: Params) -> Result { - let len = match params { - Params::Array(ref v) => v.len(), - Params::None => 0, - _ => return Err(errors::invalid_params("not an array", "")), - }; - - let (id,) = match len { - 0 => (T::default(),), - 1 => try!(from_params::<(T,)>(params)), - _ => return Err(Error::invalid_params()), - }; - - (self)(base, Trailing(id)).map(to_value) - } -} - -impl WrapAsync for fn(&B, Ready, Trailing) - where B: Send + Sync + 'static, OUT: Serialize, T: Default + Deserialize -{ - fn wrap_rpc(&self, base: &B, params: Params, ready: ::jsonrpc_core::Ready) { - let len = match params { - Params::Array(ref v) => v.len(), - Params::None => 0, - _ => return ready.ready(Err(errors::invalid_params("not an array", ""))), - }; - - let id = match len { - 0 => Ok((T::default(),)), - 1 => from_params::<(T,)>(params), - _ => Err(Error::invalid_params()), - }; - - match id { - Ok((id,)) => (self)(base, ready.into(), Trailing(id)), - Err(e) => ready.ready(Err(e)), - } - } -} - -// similar to `wrap!`, but handles a single default trailing parameter -// accepts an additional argument indicating the number of non-trailing parameters. -macro_rules! wrap_with_trailing { - ($num: expr, $($x: ident),+) => { - // synchronous implementation - impl < - BASE: Send + Sync + 'static, - OUT: Serialize, - $($x: Deserialize,)+ - TRAILING: Default + Deserialize, - > Wrap for fn(&BASE, $($x,)+ Trailing) -> Result { - fn wrap_rpc(&self, base: &BASE, params: Params) -> Result { - let len = match params { - Params::Array(ref v) => v.len(), - Params::None => 0, - _ => return Err(errors::invalid_params("not an array", "")), - }; - - let params = match len - $num { - 0 => from_params::<($($x,)+)>(params) - .map(|($($x,)+)| ($($x,)+ TRAILING::default())), - 1 => from_params::<($($x,)+ TRAILING)>(params) - .map(|($($x,)+ id)| ($($x,)+ id)), - _ => Err(Error::invalid_params()), - }; - - let ($($x,)+ id) = try!(params); - (self)(base, $($x,)+ Trailing(id)).map(to_value) - } - } - - // asynchronous implementation - impl < - BASE: Send + Sync + 'static, - OUT: Serialize, - $($x: Deserialize,)+ - TRAILING: Default + Deserialize, - > WrapAsync for fn(&BASE, Ready, $($x,)+ Trailing) { - fn wrap_rpc(&self, base: &BASE, params: Params, ready: ::jsonrpc_core::Ready) { - let len = match params { - Params::Array(ref v) => v.len(), - Params::None => 0, - _ => return ready.ready(Err(errors::invalid_params("not an array", ""))), - }; - - let params = match len - $num { - 0 => from_params::<($($x,)+)>(params) - .map(|($($x,)+)| ($($x,)+ TRAILING::default())), - 1 => from_params::<($($x,)+ TRAILING)>(params) - .map(|($($x,)+ id)| ($($x,)+ id)), - _ => Err(Error::invalid_params()), - }; - - match params { - Ok(($($x,)+ id)) => (self)(base, ready.into(), $($x,)+ Trailing(id)), - Err(e) => ready.ready(Err(e)) - } - } - } - } -} - -wrap!(A, B, C, D, E); -wrap!(A, B, C, D); -wrap!(A, B, C); -wrap!(A, B); -wrap!(A); - -wrap_with_trailing!(5, A, B, C, D, E); -wrap_with_trailing!(4, A, B, C, D); -wrap_with_trailing!(3, A, B, C); -wrap_with_trailing!(2, A, B); -wrap_with_trailing!(1, A); \ No newline at end of file diff --git a/rpc/src/v1/helpers/mod.rs b/rpc/src/v1/helpers/mod.rs index 3c6d1a739..20ca49ec6 100644 --- a/rpc/src/v1/helpers/mod.rs +++ b/rpc/src/v1/helpers/mod.rs @@ -14,14 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -#[macro_use] -pub mod auto_args; - #[macro_use] pub mod errors; pub mod dispatch; -pub mod params; pub mod block_import; mod poll_manager; diff --git a/rpc/src/v1/helpers/params.rs b/rpc/src/v1/helpers/params.rs deleted file mode 100644 index b533c1b89..000000000 --- a/rpc/src/v1/helpers/params.rs +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2015, 2016 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity 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. - -// Parity 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 Parity. If not, see . - -//! Parameters parsing helpers - -use serde; -use jsonrpc_core::{Error, Params, from_params}; -use v1::types::BlockNumber; -use v1::helpers::errors; - -pub fn expect_no_params(params: Params) -> Result<(), Error> { - match params { - Params::None => Ok(()), - p => Err(errors::invalid_params("No parameters were expected", p)), - } -} - -/// Returns number of different parameters in given `Params` object. -pub fn params_len(params: &Params) -> usize { - match params { - &Params::Array(ref vec) => vec.len(), - _ => 0, - } -} - -/// Deserialize request parameters with optional third parameter `BlockNumber` defaulting to `BlockNumber::Latest`. -pub fn from_params_default_third(params: Params) -> Result<(F1, F2, BlockNumber, ), Error> where F1: serde::de::Deserialize, F2: serde::de::Deserialize { - match params_len(¶ms) { - 2 => from_params::<(F1, F2, )>(params).map(|(f1, f2)| (f1, f2, BlockNumber::Latest)), - _ => from_params::<(F1, F2, BlockNumber)>(params) - } -} - diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index 97134951c..1364af033 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -27,6 +27,7 @@ use time::get_time; use ethsync::{SyncProvider}; use ethcore::miner::{MinerService, ExternalMinerService}; use jsonrpc_core::*; +use jsonrpc_macros::Trailing; use util::{H256, Address, FixedHash, U256, H64, Uint}; use util::sha3::*; use util::{FromHex, Mutex}; @@ -51,7 +52,6 @@ use v1::types::{ use v1::helpers::{CallRequest as CRequest, errors, limit_logs}; use v1::helpers::dispatch::{dispatch_transaction, default_gas_price}; use v1::helpers::block_import::is_major_importing; -use v1::helpers::auto_args::Trailing; const EXTRA_INFO_PROOF: &'static str = "Object exists in in blockchain (fetched earlier), extra_info is always available if object exists; qed"; diff --git a/rpc/src/v1/impls/parity.rs b/rpc/src/v1/impls/parity.rs index 1f995749a..2c6a498a1 100644 --- a/rpc/src/v1/impls/parity.rs +++ b/rpc/src/v1/impls/parity.rs @@ -32,6 +32,7 @@ use ethcore::mode::Mode; use ethcore::account_provider::AccountProvider; use jsonrpc_core::Error; +use jsonrpc_macros::Trailing; use v1::traits::Parity; use v1::types::{ Bytes, U256, H160, H256, H512, @@ -41,7 +42,6 @@ use v1::types::{ }; use v1::helpers::{errors, SigningQueue, SignerService, NetworkSettings}; use v1::helpers::dispatch::DEFAULT_MAC; -use v1::helpers::auto_args::Trailing; /// Parity implementation. pub struct ParityClient where diff --git a/rpc/src/v1/impls/parity_set.rs b/rpc/src/v1/impls/parity_set.rs index b63adaa67..6371a46ea 100644 --- a/rpc/src/v1/impls/parity_set.rs +++ b/rpc/src/v1/impls/parity_set.rs @@ -26,7 +26,7 @@ use fetch::{Client as FetchClient, Fetch}; use util::{Mutex, sha3}; use jsonrpc_core::Error; -use v1::helpers::auto_args::Ready; +use jsonrpc_macros::Ready; use v1::helpers::errors; use v1::traits::ParitySet; use v1::types::{Bytes, H160, H256, U256}; diff --git a/rpc/src/v1/impls/signing.rs b/rpc/src/v1/impls/signing.rs index 5fc6558da..c65e30816 100644 --- a/rpc/src/v1/impls/signing.rs +++ b/rpc/src/v1/impls/signing.rs @@ -25,7 +25,7 @@ use ethcore::miner::MinerService; use ethcore::client::MiningBlockChainClient; use jsonrpc_core::Error; -use v1::helpers::auto_args::Ready; +use jsonrpc_macros::Ready; use v1::helpers::{ errors, dispatch, SigningQueue, ConfirmationPromise, ConfirmationResult, ConfirmationPayload, SignerService diff --git a/rpc/src/v1/impls/signing_unsafe.rs b/rpc/src/v1/impls/signing_unsafe.rs index 2b3b81d57..17dbdcb55 100644 --- a/rpc/src/v1/impls/signing_unsafe.rs +++ b/rpc/src/v1/impls/signing_unsafe.rs @@ -24,7 +24,7 @@ use ethcore::miner::MinerService; use ethcore::client::MiningBlockChainClient; use jsonrpc_core::Error; -use v1::helpers::auto_args::Ready; +use jsonrpc_macros::Ready; use v1::helpers::errors; use v1::helpers::dispatch; use v1::traits::{EthSigning, ParitySigning}; diff --git a/rpc/src/v1/impls/traces.rs b/rpc/src/v1/impls/traces.rs index 2fd912284..6b37e40cc 100644 --- a/rpc/src/v1/impls/traces.rs +++ b/rpc/src/v1/impls/traces.rs @@ -18,13 +18,15 @@ use std::sync::{Weak, Arc}; use jsonrpc_core::*; +use serde; + use rlp::{UntrustedRlp, View}; use ethcore::client::{BlockChainClient, CallAnalytics, TransactionId, TraceId}; use ethcore::miner::MinerService; use ethcore::transaction::{Transaction as EthTransaction, SignedTransaction, Action}; + use v1::traits::Traces; use v1::helpers::{errors, CallRequest as CRequest}; -use v1::helpers::params::from_params_default_third; use v1::types::{TraceFilter, LocalizedTrace, BlockNumber, Index, CallRequest, Bytes, TraceResults, H256}; fn to_call_analytics(flags: Vec) -> CallAnalytics { @@ -35,6 +37,22 @@ fn to_call_analytics(flags: Vec) -> CallAnalytics { } } +/// Returns number of different parameters in given `Params` object. +fn params_len(params: &Params) -> usize { + match params { + &Params::Array(ref vec) => vec.len(), + _ => 0, + } +} + +/// Deserialize request parameters with optional third parameter `BlockNumber` defaulting to `BlockNumber::Latest`. +fn from_params_default_third(params: Params) -> Result<(F1, F2, BlockNumber, ), Error> where F1: serde::de::Deserialize, F2: serde::de::Deserialize { + match params_len(¶ms) { + 2 => from_params::<(F1, F2, )>(params).map(|(f1, f2)| (f1, f2, BlockNumber::Latest)), + _ => from_params::<(F1, F2, BlockNumber)>(params) + } +} + /// Traces api implementation. pub struct TracesClient where C: BlockChainClient, M: MinerService { client: Weak, diff --git a/rpc/src/v1/traits/eth.rs b/rpc/src/v1/traits/eth.rs index 14ee8ca62..2d52b7c70 100644 --- a/rpc/src/v1/traits/eth.rs +++ b/rpc/src/v1/traits/eth.rs @@ -21,7 +21,7 @@ use v1::types::{RichBlock, BlockNumber, Bytes, CallRequest, Filter, FilterChange use v1::types::{Log, Receipt, SyncStatus, Transaction, Work}; use v1::types::{H64, H160, H256, U256}; -use v1::helpers::auto_args::{Trailing, Wrap}; +use jsonrpc_macros::Trailing; build_rpc_trait! { /// Eth rpc interface. diff --git a/rpc/src/v1/traits/eth_signing.rs b/rpc/src/v1/traits/eth_signing.rs index aa306f3f0..442883339 100644 --- a/rpc/src/v1/traits/eth_signing.rs +++ b/rpc/src/v1/traits/eth_signing.rs @@ -16,7 +16,8 @@ //! Eth rpc interface. -use v1::helpers::auto_args::{WrapAsync, Ready}; +use jsonrpc_macros::Ready; + use v1::types::{Bytes, H160, H256, H520, TransactionRequest, RichRawTransaction}; build_rpc_trait! { diff --git a/rpc/src/v1/traits/net.rs b/rpc/src/v1/traits/net.rs index a34270826..ebe93472e 100644 --- a/rpc/src/v1/traits/net.rs +++ b/rpc/src/v1/traits/net.rs @@ -17,8 +17,6 @@ //! Net rpc interface. use jsonrpc_core::Error; -use v1::helpers::auto_args::Wrap; - build_rpc_trait! { /// Net rpc interface. pub trait Net { @@ -35,4 +33,4 @@ build_rpc_trait! { #[rpc(name = "net_listening")] fn is_listening(&self) -> Result; } -} \ No newline at end of file +} diff --git a/rpc/src/v1/traits/parity.rs b/rpc/src/v1/traits/parity.rs index ba6514168..fecc05667 100644 --- a/rpc/src/v1/traits/parity.rs +++ b/rpc/src/v1/traits/parity.rs @@ -15,10 +15,12 @@ // along with Parity. If not, see . //! Parity-specific rpc interface. -use jsonrpc_core::Error; use std::collections::BTreeMap; -use v1::helpers::auto_args::{Wrap, Trailing}; + +use jsonrpc_core::Error; +use jsonrpc_macros::Trailing; + use v1::types::{ H160, H256, H512, U256, Bytes, Peers, Transaction, RpcSettings, Histogram, diff --git a/rpc/src/v1/traits/parity_accounts.rs b/rpc/src/v1/traits/parity_accounts.rs index e4393c149..d21a8459e 100644 --- a/rpc/src/v1/traits/parity_accounts.rs +++ b/rpc/src/v1/traits/parity_accounts.rs @@ -16,9 +16,8 @@ //! Parity Accounts-related rpc interface. use std::collections::BTreeMap; -use jsonrpc_core::{Value, Error}; -use v1::helpers::auto_args::Wrap; +use jsonrpc_core::{Value, Error}; use v1::types::{H160, H256, DappId}; build_rpc_trait! { diff --git a/rpc/src/v1/traits/parity_set.rs b/rpc/src/v1/traits/parity_set.rs index 486f7fb42..6ae3610c8 100644 --- a/rpc/src/v1/traits/parity_set.rs +++ b/rpc/src/v1/traits/parity_set.rs @@ -17,8 +17,8 @@ //! Parity-specific rpc interface for operations altering the settings. use jsonrpc_core::Error; +use jsonrpc_macros::Ready; -use v1::helpers::auto_args::{Wrap, WrapAsync, Ready}; use v1::types::{Bytes, H160, H256, U256}; build_rpc_trait! { diff --git a/rpc/src/v1/traits/parity_signing.rs b/rpc/src/v1/traits/parity_signing.rs index 5eb5ff8b3..a6fdbe2cd 100644 --- a/rpc/src/v1/traits/parity_signing.rs +++ b/rpc/src/v1/traits/parity_signing.rs @@ -16,8 +16,8 @@ //! ParitySigning rpc interface. use jsonrpc_core::Error; +use jsonrpc_macros::Ready; -use v1::helpers::auto_args::{Wrap, WrapAsync, Ready}; use v1::types::{U256, H160, H256, Bytes, ConfirmationResponse, TransactionRequest, Either}; build_rpc_trait! { diff --git a/rpc/src/v1/traits/personal.rs b/rpc/src/v1/traits/personal.rs index edb1a9d79..a7cc996ea 100644 --- a/rpc/src/v1/traits/personal.rs +++ b/rpc/src/v1/traits/personal.rs @@ -17,7 +17,6 @@ //! Personal rpc interface. use jsonrpc_core::Error; -use v1::helpers::auto_args::Wrap; use v1::types::{U128, H160, H256, TransactionRequest}; build_rpc_trait! { diff --git a/rpc/src/v1/traits/rpc.rs b/rpc/src/v1/traits/rpc.rs index a03d67b55..9b44b560f 100644 --- a/rpc/src/v1/traits/rpc.rs +++ b/rpc/src/v1/traits/rpc.rs @@ -16,12 +16,10 @@ //! RPC interface. -use jsonrpc_core::Error; - -use v1::helpers::auto_args::Wrap; - use std::collections::BTreeMap; +use jsonrpc_core::Error; + build_rpc_trait! { /// RPC Interface. pub trait Rpc { @@ -33,4 +31,4 @@ build_rpc_trait! { #[rpc(name = "rpc_modules")] fn rpc_modules(&self) -> Result, Error>; } -} \ No newline at end of file +} diff --git a/rpc/src/v1/traits/signer.rs b/rpc/src/v1/traits/signer.rs index 5a18fe293..19861b922 100644 --- a/rpc/src/v1/traits/signer.rs +++ b/rpc/src/v1/traits/signer.rs @@ -17,10 +17,8 @@ //! Parity Signer-related rpc interface. use jsonrpc_core::Error; -use v1::helpers::auto_args::Wrap; use v1::types::{U256, Bytes, TransactionModification, ConfirmationRequest, ConfirmationResponse}; - build_rpc_trait! { /// Signer extension for confirmations rpc interface. pub trait Signer { diff --git a/rpc/src/v1/traits/traces.rs b/rpc/src/v1/traits/traces.rs index 0440b4dff..36561216f 100644 --- a/rpc/src/v1/traits/traces.rs +++ b/rpc/src/v1/traits/traces.rs @@ -15,8 +15,9 @@ // along with Parity. If not, see . //! Traces specific rpc interface. + use std::sync::Arc; -use jsonrpc_core::*; +use jsonrpc_core::{Params, Value, Error, IoDelegate}; /// Traces specific rpc interface. pub trait Traces: Sized + Send + Sync + 'static { diff --git a/rpc/src/v1/traits/web3.rs b/rpc/src/v1/traits/web3.rs index efe26e307..c2f5f55e1 100644 --- a/rpc/src/v1/traits/web3.rs +++ b/rpc/src/v1/traits/web3.rs @@ -17,10 +17,8 @@ //! Web3 rpc interface. use jsonrpc_core::Error; -use v1::helpers::auto_args::Wrap; use v1::types::{H256, Bytes}; - build_rpc_trait! { /// Web3 rpc interface. pub trait Web3 { From 65d62ccf04d29e03465779937be6b2dc6f5acfc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Tue, 13 Dec 2016 14:59:19 +0100 Subject: [PATCH 3/3] Altering the order [ci:skip] --- rpc/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 7f105b0d0..c5af5d727 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -24,8 +24,6 @@ extern crate serde; extern crate serde_json; extern crate jsonrpc_core; extern crate jsonrpc_http_server; -#[macro_use] -extern crate jsonrpc_macros; extern crate ethcore_io as io; extern crate ethcore; @@ -44,6 +42,8 @@ extern crate fetch; extern crate log; #[macro_use] extern crate ethcore_util as util; +#[macro_use] +extern crate jsonrpc_macros; #[cfg(test)] extern crate ethjson;