Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Convert to jsonrpc-derive, use jsonrpc-* from crates.io (#10298)
Browse files Browse the repository at this point in the history
* Use jsonrpc crates on local path

* Convert all RPC traits to use jsonrpc-derive

* Use local jsonrpc at top level

* Upgrade remaining jsonrpc dependencies

* Checkout Cargo.lock to master HEAD

* Use jsonrpc-* 10.0.1 from crates.io

* Attribute after docs
  • Loading branch information
ascjones authored and sorpaas committed Feb 5, 2019
1 parent 06cae8a commit 89ae0f0
Show file tree
Hide file tree
Showing 41 changed files with 1,131 additions and 1,157 deletions.
186 changes: 93 additions & 93 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ serde_derive = "1.0"
futures = "0.1"
fdlimit = "0.1"
ctrlc = { git = "https://github.com/paritytech/rust-ctrlc.git" }
jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-2.2" }
jsonrpc-core = "10.0.1"
ethcore = { path = "ethcore", features = ["parity"] }
parity-bytes = "0.1"
common-types = { path = "ethcore/types" }
Expand Down
4 changes: 2 additions & 2 deletions cli-signer/rpc-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ serde_json = "1.0"
url = "1.2.0"
matches = "0.1"
parking_lot = "0.7"
jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-2.2" }
jsonrpc-ws-server = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-2.2" }
jsonrpc-core = "10.0.1"
jsonrpc-ws-server = "10.0.1"
parity-rpc = { path = "../../rpc" }
keccak-hash = "0.1"
4 changes: 2 additions & 2 deletions ipfs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ authors = ["Parity Technologies <admin@parity.io>"]
ethcore = { path = "../ethcore" }
parity-bytes = "0.1"
ethereum-types = "0.4"
jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-2.2" }
jsonrpc-http-server = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-2.2" }
jsonrpc-core = "10.0.1"
jsonrpc-http-server = "10.0.1"
rlp = { version = "0.3.0", features = ["ethereum"] }
cid = "0.3"
multihash = "0.8"
Expand Down
5 changes: 2 additions & 3 deletions miner/stratum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ authors = ["Parity Technologies <admin@parity.io>"]
[dependencies]
ethereum-types = "0.4"
keccak-hash = "0.1"
jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-2.2" }
jsonrpc-macros = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-2.2" }
jsonrpc-tcp-server = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-2.2" }
jsonrpc-core = "10.0.1"
jsonrpc-tcp-server = "10.0.1"
log = "0.4"
parking_lot = "0.7"

Expand Down
4 changes: 1 addition & 3 deletions miner/stratum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
extern crate jsonrpc_tcp_server;
extern crate jsonrpc_core;
extern crate jsonrpc_macros;
extern crate ethereum_types;
extern crate keccak_hash as hash;
extern crate parking_lot;
Expand All @@ -39,8 +38,7 @@ use jsonrpc_tcp_server::{
Server as JsonRpcServer, ServerBuilder as JsonRpcServerBuilder,
RequestContext, MetaExtractor, Dispatcher, PushMessageError,
};
use jsonrpc_core::{MetaIoHandler, Params, to_value, Value, Metadata, Compatibility};
use jsonrpc_macros::IoDelegate;
use jsonrpc_core::{MetaIoHandler, Params, to_value, Value, Metadata, Compatibility, IoDelegate};
use std::sync::Arc;

use std::net::SocketAddr;
Expand Down
12 changes: 6 additions & 6 deletions rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ tokio-timer = "0.1"
transient-hashmap = "0.4"
itertools = "0.5"

jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-2.2" }
jsonrpc-http-server = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-2.2" }
jsonrpc-ws-server = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-2.2" }
jsonrpc-ipc-server = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-2.2" }
jsonrpc-macros = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-2.2" }
jsonrpc-pubsub = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-2.2" }
jsonrpc-core = "10.0.1"
jsonrpc-derive = "10.0.1"
jsonrpc-http-server = "10.0.1"
jsonrpc-ws-server = "10.0.1"
jsonrpc-ipc-server = "10.0.1"
jsonrpc-pubsub = "10.0.1"

common-types = { path = "../ethcore/types" }
ethash = { path = "../ethash" }
Expand Down
3 changes: 1 addition & 2 deletions rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ extern crate tokio_timer;
extern crate transient_hashmap;

extern crate jsonrpc_core;
extern crate jsonrpc_derive;
extern crate jsonrpc_http_server as http;
extern crate jsonrpc_ipc_server as ipc;
extern crate jsonrpc_pubsub;
Expand Down Expand Up @@ -75,8 +76,6 @@ extern crate fake_hardware_wallet as hardware_wallet;
#[macro_use]
extern crate log;
#[macro_use]
extern crate jsonrpc_macros;
#[macro_use]
extern crate serde_derive;

#[cfg(test)]
Expand Down
3 changes: 1 addition & 2 deletions rpc/src/v1/helpers/light_fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use ethcore::executed::ExecutionError;
use jsonrpc_core::{Result, Error};
use jsonrpc_core::futures::{future, Future};
use jsonrpc_core::futures::future::Either;
use jsonrpc_macros::Trailing;

use light::cache::Cache;
use light::client::LightChainClient;
Expand Down Expand Up @@ -202,7 +201,7 @@ impl LightFetch {
}

/// Helper for getting proved execution.
pub fn proved_read_only_execution(&self, req: CallRequest, num: Trailing<BlockNumber>) -> impl Future<Item = ExecutionResult, Error = Error> + Send {
pub fn proved_read_only_execution(&self, req: CallRequest, num: Option<BlockNumber>) -> impl Future<Item = ExecutionResult, Error = Error> + Send {
const DEFAULT_GAS_PRICE: u64 = 21_000;
// (21000 G_transaction + 32000 G_create + some marginal to allow a few operations)
const START_GAS: u64 = 60_000;
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/v1/helpers/subscribers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use std::{ops, str};
use std::collections::HashMap;
use jsonrpc_macros::pubsub::{Subscriber, Sink, SubscriptionId};
use jsonrpc_pubsub::{typed::{Subscriber, Sink}, SubscriptionId};
use rand::{Rng, StdRng};
use v1::types::H64;

Expand Down
17 changes: 8 additions & 9 deletions rpc/src/v1/impls/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ use types::filter::Filter as EthcoreFilter;

use jsonrpc_core::{BoxFuture, Result};
use jsonrpc_core::futures::future;
use jsonrpc_macros::Trailing;

use v1::helpers::{self, errors, limit_logs, fake_sign};
use v1::helpers::dispatch::{FullDispatcher, default_gas_price};
Expand Down Expand Up @@ -568,7 +567,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> Eth for EthClient<
Ok(RpcU256::from(self.client.chain_info().best_block_number))
}

fn balance(&self, address: RpcH160, num: Trailing<BlockNumber>) -> BoxFuture<RpcU256> {
fn balance(&self, address: RpcH160, num: Option<BlockNumber>) -> BoxFuture<RpcU256> {
let address = address.into();

let num = num.unwrap_or_default();
Expand All @@ -582,7 +581,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> Eth for EthClient<
Box::new(future::done(res))
}

fn proof(&self, address: RpcH160, values: Vec<RpcH256>, num: Trailing<BlockNumber>) -> BoxFuture<EthAccount> {
fn proof(&self, address: RpcH160, values: Vec<RpcH256>, num: Option<BlockNumber>) -> BoxFuture<EthAccount> {
try_bf!(errors::require_experimental(self.options.allow_experimental_rpcs, "1186"));

let a: H160 = address.clone().into();
Expand Down Expand Up @@ -625,7 +624,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> Eth for EthClient<
Box::new(future::done(res))
}

fn storage_at(&self, address: RpcH160, pos: RpcU256, num: Trailing<BlockNumber>) -> BoxFuture<RpcH256> {
fn storage_at(&self, address: RpcH160, pos: RpcU256, num: Option<BlockNumber>) -> BoxFuture<RpcH256> {
let address: Address = RpcH160::into(address);
let position: U256 = RpcU256::into(pos);

Expand All @@ -640,7 +639,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> Eth for EthClient<
Box::new(future::done(res))
}

fn transaction_count(&self, address: RpcH160, num: Trailing<BlockNumber>) -> BoxFuture<RpcU256> {
fn transaction_count(&self, address: RpcH160, num: Option<BlockNumber>) -> BoxFuture<RpcU256> {
let address: Address = RpcH160::into(address);

let res = match num.unwrap_or_default() {
Expand Down Expand Up @@ -723,7 +722,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> Eth for EthClient<
}))
}

fn code_at(&self, address: RpcH160, num: Trailing<BlockNumber>) -> BoxFuture<Bytes> {
fn code_at(&self, address: RpcH160, num: Option<BlockNumber>) -> BoxFuture<Bytes> {
let address: Address = RpcH160::into(address);

let num = num.unwrap_or_default();
Expand Down Expand Up @@ -832,7 +831,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> Eth for EthClient<
base_logs(&*self.client, &*self.miner, filter.into())
}

fn work(&self, no_new_work_timeout: Trailing<u64>) -> Result<Work> {
fn work(&self, no_new_work_timeout: Option<u64>) -> Result<Work> {
let no_new_work_timeout = no_new_work_timeout.unwrap_or_default();

// check if we're still syncing and return empty strings in that case
Expand Down Expand Up @@ -918,7 +917,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> Eth for EthClient<
self.send_raw_transaction(raw)
}

fn call(&self, request: CallRequest, num: Trailing<BlockNumber>) -> BoxFuture<Bytes> {
fn call(&self, request: CallRequest, num: Option<BlockNumber>) -> BoxFuture<Bytes> {
let request = CallRequest::into(request);
let signed = try_bf!(fake_sign::sign_call(request));

Expand Down Expand Up @@ -958,7 +957,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> Eth for EthClient<
))
}

fn estimate_gas(&self, request: CallRequest, num: Trailing<BlockNumber>) -> BoxFuture<RpcU256> {
fn estimate_gas(&self, request: CallRequest, num: Option<BlockNumber>) -> BoxFuture<RpcU256> {
let request = CallRequest::into(request);
let signed = try_bf!(fake_sign::sign_call(request));
let num = num.unwrap_or_default();
Expand Down
8 changes: 3 additions & 5 deletions rpc/src/v1/impls/eth_pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ use std::collections::BTreeMap;

use jsonrpc_core::{BoxFuture, Result, Error};
use jsonrpc_core::futures::{self, Future, IntoFuture};
use jsonrpc_macros::Trailing;
use jsonrpc_macros::pubsub::{Sink, Subscriber};
use jsonrpc_pubsub::SubscriptionId;
use jsonrpc_pubsub::{SubscriptionId, typed::{Sink, Subscriber}};

use v1::helpers::{errors, limit_logs, Subscribers};
use v1::helpers::light_fetch::LightFetch;
Expand Down Expand Up @@ -262,7 +260,7 @@ impl<C: Send + Sync + 'static> EthPubSub for EthPubSubClient<C> {
_meta: Metadata,
subscriber: Subscriber<pubsub::Result>,
kind: pubsub::Kind,
params: Trailing<pubsub::Params>,
params: Option<pubsub::Params>,
) {
let error = match (kind, params.into()) {
(pubsub::Kind::NewHeads, None) => {
Expand Down Expand Up @@ -299,7 +297,7 @@ impl<C: Send + Sync + 'static> EthPubSub for EthPubSubClient<C> {
let _ = subscriber.reject(error);
}

fn unsubscribe(&self, id: SubscriptionId) -> Result<bool> {
fn unsubscribe(&self, _: Option<Self::Metadata>, id: SubscriptionId) -> Result<bool> {
let res = self.heads_subscribers.write().remove(&id).is_some();
let res2 = self.logs_subscribers.write().remove(&id).is_some();
let res3 = self.transactions_subscribers.write().remove(&id).is_some();
Expand Down
17 changes: 8 additions & 9 deletions rpc/src/v1/impls/light/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use std::sync::Arc;
use jsonrpc_core::{Result, BoxFuture};
use jsonrpc_core::futures::{future, Future};
use jsonrpc_core::futures::future::Either;
use jsonrpc_macros::Trailing;

use light::cache::Cache as LightDataCache;
use light::client::LightChainClient;
Expand Down Expand Up @@ -272,12 +271,12 @@ impl<T: LightChainClient + 'static> Eth for EthClient<T> {
Ok(self.client.chain_info().best_block_number.into())
}

fn balance(&self, address: RpcH160, num: Trailing<BlockNumber>) -> BoxFuture<RpcU256> {
fn balance(&self, address: RpcH160, num: Option<BlockNumber>) -> BoxFuture<RpcU256> {
Box::new(self.fetcher().account(address.into(), num.unwrap_or_default().to_block_id())
.map(|acc| acc.map_or(0.into(), |a| a.balance).into()))
}

fn storage_at(&self, _address: RpcH160, _key: RpcU256, _num: Trailing<BlockNumber>) -> BoxFuture<RpcH256> {
fn storage_at(&self, _address: RpcH160, _key: RpcU256, _num: Option<BlockNumber>) -> BoxFuture<RpcH256> {
Box::new(future::err(errors::unimplemented(None)))
}

Expand All @@ -289,7 +288,7 @@ impl<T: LightChainClient + 'static> Eth for EthClient<T> {
Box::new(self.rich_block(num.to_block_id(), include_txs).map(Some))
}

fn transaction_count(&self, address: RpcH160, num: Trailing<BlockNumber>) -> BoxFuture<RpcU256> {
fn transaction_count(&self, address: RpcH160, num: Option<BlockNumber>) -> BoxFuture<RpcU256> {
Box::new(self.fetcher().account(address.into(), num.unwrap_or_default().to_block_id())
.map(|acc| acc.map_or(0.into(), |a| a.nonce).into()))
}
Expand Down Expand Up @@ -358,7 +357,7 @@ impl<T: LightChainClient + 'static> Eth for EthClient<T> {
}))
}

fn code_at(&self, address: RpcH160, num: Trailing<BlockNumber>) -> BoxFuture<Bytes> {
fn code_at(&self, address: RpcH160, num: Option<BlockNumber>) -> BoxFuture<Bytes> {
Box::new(self.fetcher().code(address.into(), num.unwrap_or_default().to_block_id()).map(Into::into))
}

Expand All @@ -385,7 +384,7 @@ impl<T: LightChainClient + 'static> Eth for EthClient<T> {
self.send_raw_transaction(raw)
}

fn call(&self, req: CallRequest, num: Trailing<BlockNumber>) -> BoxFuture<Bytes> {
fn call(&self, req: CallRequest, num: Option<BlockNumber>) -> BoxFuture<Bytes> {
Box::new(self.fetcher().proved_read_only_execution(req, num).and_then(|res| {
match res {
Ok(exec) => Ok(exec.output.into()),
Expand All @@ -394,7 +393,7 @@ impl<T: LightChainClient + 'static> Eth for EthClient<T> {
}))
}

fn estimate_gas(&self, req: CallRequest, num: Trailing<BlockNumber>) -> BoxFuture<RpcU256> {
fn estimate_gas(&self, req: CallRequest, num: Option<BlockNumber>) -> BoxFuture<RpcU256> {
// TODO: binary chop for more accurate estimates.
Box::new(self.fetcher().proved_read_only_execution(req, num).and_then(|res| {
match res {
Expand Down Expand Up @@ -475,7 +474,7 @@ impl<T: LightChainClient + 'static> Eth for EthClient<T> {
}))
}

fn proof(&self, _address: RpcH160, _values:Vec<RpcH256>, _num: Trailing<BlockNumber>) -> BoxFuture<EthAccount> {
fn proof(&self, _address: RpcH160, _values:Vec<RpcH256>, _num: Option<BlockNumber>) -> BoxFuture<EthAccount> {
Box::new(future::err(errors::unimplemented(None)))
}

Expand Down Expand Up @@ -505,7 +504,7 @@ impl<T: LightChainClient + 'static> Eth for EthClient<T> {
}).map(move |logs| limit_logs(logs, limit)))
}

fn work(&self, _timeout: Trailing<u64>) -> Result<Work> {
fn work(&self, _timeout: Option<u64>) -> Result<Work> {
Err(errors::light_unimplemented(None))
}

Expand Down
13 changes: 6 additions & 7 deletions rpc/src/v1/impls/light/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use ethcore_logger::RotatingLogger;

use jsonrpc_core::{Result, BoxFuture};
use jsonrpc_core::futures::{future, Future};
use jsonrpc_macros::Trailing;
use v1::helpers::{self, errors, ipfs, SigningQueue, SignerService, NetworkSettings, verify_signature};
use v1::helpers::dispatch::LightDispatcher;
use v1::helpers::light_fetch::{LightFetch, light_all_transactions};
Expand Down Expand Up @@ -232,11 +231,11 @@ impl Parity for ParityClient {
Ok(Brain::new(phrase).generate().unwrap().address().into())
}

fn list_accounts(&self, _: u64, _: Option<H160>, _: Trailing<BlockNumber>) -> Result<Option<Vec<H160>>> {
fn list_accounts(&self, _: u64, _: Option<H160>, _: Option<BlockNumber>) -> Result<Option<Vec<H160>>> {
Err(errors::light_unimplemented(None))
}

fn list_storage_keys(&self, _: H160, _: u64, _: Option<H256>, _: Trailing<BlockNumber>) -> Result<Option<Vec<H256>>> {
fn list_storage_keys(&self, _: H160, _: u64, _: Option<H256>, _: Option<BlockNumber>) -> Result<Option<Vec<H256>>> {
Err(errors::light_unimplemented(None))
}

Expand All @@ -246,7 +245,7 @@ impl Parity for ParityClient {
.map(Into::into)
}

fn pending_transactions(&self, limit: Trailing<usize>) -> Result<Vec<Transaction>> {
fn pending_transactions(&self, limit: Option<usize>) -> Result<Vec<Transaction>> {
let txq = self.light_dispatch.transaction_queue.read();
let chain_info = self.light_dispatch.client.chain_info();
Ok(
Expand Down Expand Up @@ -365,7 +364,7 @@ impl Parity for ParityClient {
})
}

fn block_header(&self, number: Trailing<BlockNumber>) -> BoxFuture<RichHeader> {
fn block_header(&self, number: Option<BlockNumber>) -> BoxFuture<RichHeader> {
use types::encoded;

let engine = self.light_dispatch.client.engine().clone();
Expand Down Expand Up @@ -399,7 +398,7 @@ impl Parity for ParityClient {
Box::new(self.fetcher().header(id).and_then(from_encoded))
}

fn block_receipts(&self, number: Trailing<BlockNumber>) -> BoxFuture<Vec<Receipt>> {
fn block_receipts(&self, number: Option<BlockNumber>) -> BoxFuture<Vec<Receipt>> {
let id = number.unwrap_or_default().to_block_id();
Box::new(self.fetcher().receipts(id).and_then(|receipts| Ok(receipts.into_iter().map(Into::into).collect())))
}
Expand All @@ -408,7 +407,7 @@ impl Parity for ParityClient {
ipfs::cid(content)
}

fn call(&self, _requests: Vec<CallRequest>, _block: Trailing<BlockNumber>) -> Result<Vec<Bytes>> {
fn call(&self, _requests: Vec<CallRequest>, _block: Option<BlockNumber>) -> Result<Vec<Bytes>> {
Err(errors::light_unimplemented(None))
}

Expand Down
7 changes: 3 additions & 4 deletions rpc/src/v1/impls/light/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
//! Traces api implementation.
use jsonrpc_core::Result;
use jsonrpc_macros::Trailing;
use v1::Metadata;
use v1::traits::Traces;
use v1::helpers::errors;
Expand Down Expand Up @@ -46,15 +45,15 @@ impl Traces for TracesClient {
Err(errors::light_unimplemented(None))
}

fn call(&self, _request: CallRequest, _flags: TraceOptions, _block: Trailing<BlockNumber>) -> Result<TraceResults> {
fn call(&self, _request: CallRequest, _flags: TraceOptions, _block: Option<BlockNumber>) -> Result<TraceResults> {
Err(errors::light_unimplemented(None))
}

fn call_many(&self, _request: Vec<(CallRequest, TraceOptions)>, _block: Trailing<BlockNumber>) -> Result<Vec<TraceResults>> {
fn call_many(&self, _request: Vec<(CallRequest, TraceOptions)>, _block: Option<BlockNumber>) -> Result<Vec<TraceResults>> {
Err(errors::light_unimplemented(None))
}

fn raw_transaction(&self, _raw_transaction: Bytes, _flags: TraceOptions, _block: Trailing<BlockNumber>) -> Result<TraceResults> {
fn raw_transaction(&self, _raw_transaction: Bytes, _flags: TraceOptions, _block: Option<BlockNumber>) -> Result<TraceResults> {
Err(errors::light_unimplemented(None))
}

Expand Down
Loading

0 comments on commit 89ae0f0

Please sign in to comment.