Update jsonrpc dependencies and rewrite dapps to futures. (#6522)
* Bump version. * Fix RPC crate. * Fix BoxFuture in crates. * Compiles and passes tests! * Get rid of .boxed() * Fixing issues with the UI. * Remove minihttp. Support threads. * Reimplement files serving to do it in chunks. * Increase chunk size. * Remove some unecessary copying. * Fix tests. * Fix stratum warning and ipfs todo. * Switch to proper branch of jsonrpc. * Update Cargo.lock. * Update docs. * Include dapps-glue in workspace. * fixed merge artifacts * Fix test compilation.
This commit is contained in:
committed by
Arkadiy Paronyan
parent
492da38d67
commit
e8b418ca03
@@ -10,7 +10,6 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
[dependencies]
|
||||
ansi_term = "0.9"
|
||||
cid = "0.2"
|
||||
futures = "0.1"
|
||||
futures-cpupool = "0.1"
|
||||
log = "0.3"
|
||||
multihash ="0.6"
|
||||
@@ -28,13 +27,12 @@ tokio-timer = "0.1"
|
||||
transient-hashmap = "0.4"
|
||||
itertools = "0.5"
|
||||
|
||||
jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.7" }
|
||||
jsonrpc-http-server = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.7" }
|
||||
jsonrpc-minihttp-server = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.7" }
|
||||
jsonrpc-ws-server = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.7" }
|
||||
jsonrpc-ipc-server = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.7" }
|
||||
jsonrpc-macros = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.7" }
|
||||
jsonrpc-pubsub = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.7" }
|
||||
jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.8" }
|
||||
jsonrpc-http-server = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.8" }
|
||||
jsonrpc-ws-server = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.8" }
|
||||
jsonrpc-ipc-server = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.8" }
|
||||
jsonrpc-macros = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.8" }
|
||||
jsonrpc-pubsub = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.8" }
|
||||
|
||||
ethcore-io = { path = "../util/io" }
|
||||
ethcore-ipc = { path = "../ipc/rpc" }
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
use jsonrpc_core;
|
||||
use http;
|
||||
use hyper;
|
||||
use minihttp;
|
||||
|
||||
/// HTTP RPC server impl-independent metadata extractor
|
||||
pub trait HttpMetaExtractor: Send + Sync + 'static {
|
||||
@@ -29,24 +28,22 @@ pub trait HttpMetaExtractor: Send + Sync + 'static {
|
||||
fn read_metadata(&self, origin: Option<String>, user_agent: Option<String>, dapps_origin: Option<String>) -> Self::Metadata;
|
||||
}
|
||||
|
||||
pub struct HyperMetaExtractor<T> {
|
||||
pub struct MetaExtractor<T> {
|
||||
extractor: T,
|
||||
}
|
||||
|
||||
impl<T> HyperMetaExtractor<T> {
|
||||
impl<T> MetaExtractor<T> {
|
||||
pub fn new(extractor: T) -> Self {
|
||||
HyperMetaExtractor {
|
||||
extractor: extractor,
|
||||
}
|
||||
MetaExtractor { extractor }
|
||||
}
|
||||
}
|
||||
|
||||
impl<M, T> http::MetaExtractor<M> for HyperMetaExtractor<T> where
|
||||
impl<M, T> http::MetaExtractor<M> for MetaExtractor<T> where
|
||||
T: HttpMetaExtractor<Metadata = M>,
|
||||
M: jsonrpc_core::Metadata,
|
||||
{
|
||||
fn read_metadata(&self, req: &hyper::server::Request<hyper::net::HttpStream>) -> M {
|
||||
let as_string = |header: Option<&http::request_response::header::Raw>| header
|
||||
fn read_metadata(&self, req: &hyper::server::Request) -> M {
|
||||
let as_string = |header: Option<&hyper::header::Raw>| header
|
||||
.and_then(|raw| raw.one())
|
||||
.map(|raw| String::from_utf8_lossy(raw).into_owned());
|
||||
|
||||
@@ -56,28 +53,3 @@ impl<M, T> http::MetaExtractor<M> for HyperMetaExtractor<T> where
|
||||
self.extractor.read_metadata(origin, user_agent, dapps_origin)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MiniMetaExtractor<T> {
|
||||
extractor: T,
|
||||
}
|
||||
|
||||
impl<T> MiniMetaExtractor<T> {
|
||||
pub fn new(extractor: T) -> Self {
|
||||
MiniMetaExtractor {
|
||||
extractor: extractor,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<M, T> minihttp::MetaExtractor<M> for MiniMetaExtractor<T> where
|
||||
T: HttpMetaExtractor<Metadata = M>,
|
||||
M: jsonrpc_core::Metadata,
|
||||
{
|
||||
fn read_metadata(&self, req: &minihttp::Req) -> M {
|
||||
let origin = req.header("origin").map(|h| h.to_owned());
|
||||
let user_agent = req.header("user-agent").map(|h| h.to_owned());
|
||||
let dapps_origin = req.header("x-parity-origin").map(|h| h.to_owned());
|
||||
|
||||
self.extractor.read_metadata(origin, user_agent, dapps_origin)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
extern crate ansi_term;
|
||||
extern crate cid;
|
||||
extern crate crypto as rust_crypto;
|
||||
extern crate futures;
|
||||
extern crate futures_cpupool;
|
||||
extern crate itertools;
|
||||
extern crate multihash;
|
||||
@@ -41,7 +40,6 @@ extern crate transient_hashmap;
|
||||
extern crate jsonrpc_core;
|
||||
extern crate jsonrpc_http_server as http;
|
||||
extern crate jsonrpc_ipc_server as ipc;
|
||||
extern crate jsonrpc_minihttp_server as minihttp;
|
||||
extern crate jsonrpc_pubsub;
|
||||
|
||||
extern crate ethash;
|
||||
@@ -109,22 +107,8 @@ use std::net::SocketAddr;
|
||||
use http::tokio_core;
|
||||
|
||||
/// RPC HTTP Server instance
|
||||
pub enum HttpServer {
|
||||
/// Fast MiniHTTP variant
|
||||
Mini(minihttp::Server),
|
||||
/// Hyper variant
|
||||
Hyper(http::Server),
|
||||
}
|
||||
pub type HttpServer = http::Server;
|
||||
|
||||
impl HttpServer {
|
||||
/// Returns current listening address.
|
||||
pub fn address(&self) -> &SocketAddr {
|
||||
match *self {
|
||||
HttpServer::Mini(ref s) => s.address(),
|
||||
HttpServer::Hyper(ref s) => &s.addrs()[0],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// RPC HTTP Server error
|
||||
#[derive(Debug)]
|
||||
@@ -145,23 +129,6 @@ impl From<http::Error> for HttpServerError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<minihttp::Error> for HttpServerError {
|
||||
fn from(e: minihttp::Error) -> Self {
|
||||
use self::HttpServerError::*;
|
||||
match e {
|
||||
minihttp::Error::Io(io) => Io(io),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// HTTP server implementation-specific settings.
|
||||
pub enum HttpSettings<R: RequestMiddleware> {
|
||||
/// Enable fast minihttp server with given number of threads.
|
||||
Threads(usize),
|
||||
/// Enable standard server with optional dapps middleware.
|
||||
Dapps(Option<R>),
|
||||
}
|
||||
|
||||
/// Start http server asynchronously and returns result with `Server` handle on success or an error.
|
||||
pub fn start_http<M, S, H, T, R>(
|
||||
addr: &SocketAddr,
|
||||
@@ -170,7 +137,8 @@ pub fn start_http<M, S, H, T, R>(
|
||||
handler: H,
|
||||
remote: tokio_core::reactor::Remote,
|
||||
extractor: T,
|
||||
settings: HttpSettings<R>,
|
||||
middleware: Option<R>,
|
||||
threads: usize,
|
||||
) -> Result<HttpServer, HttpServerError> where
|
||||
M: jsonrpc_core::Metadata,
|
||||
S: jsonrpc_core::Middleware<M>,
|
||||
@@ -178,30 +146,18 @@ pub fn start_http<M, S, H, T, R>(
|
||||
T: HttpMetaExtractor<Metadata=M>,
|
||||
R: RequestMiddleware,
|
||||
{
|
||||
Ok(match settings {
|
||||
HttpSettings::Dapps(middleware) => {
|
||||
let mut builder = http::ServerBuilder::new(handler)
|
||||
.event_loop_remote(remote)
|
||||
.meta_extractor(http_common::HyperMetaExtractor::new(extractor))
|
||||
.cors(cors_domains.into())
|
||||
.allowed_hosts(allowed_hosts.into());
|
||||
let mut builder = http::ServerBuilder::new(handler)
|
||||
.threads(threads)
|
||||
.event_loop_remote(remote)
|
||||
.meta_extractor(http_common::MetaExtractor::new(extractor))
|
||||
.cors(cors_domains.into())
|
||||
.allowed_hosts(allowed_hosts.into());
|
||||
|
||||
if let Some(dapps) = middleware {
|
||||
builder = builder.request_middleware(dapps)
|
||||
}
|
||||
builder.start_http(addr)
|
||||
.map(HttpServer::Hyper)?
|
||||
},
|
||||
HttpSettings::Threads(threads) => {
|
||||
minihttp::ServerBuilder::new(handler)
|
||||
.threads(threads)
|
||||
.meta_extractor(http_common::MiniMetaExtractor::new(extractor))
|
||||
.cors(cors_domains.into())
|
||||
.allowed_hosts(allowed_hosts.into())
|
||||
.start_http(addr)
|
||||
.map(HttpServer::Mini)?
|
||||
},
|
||||
})
|
||||
if let Some(dapps) = middleware {
|
||||
builder = builder.request_middleware(dapps)
|
||||
}
|
||||
|
||||
Ok(builder.start_http(addr)?)
|
||||
}
|
||||
|
||||
/// Start ipc server asynchronously and returns result with `Server` handle on success or an error.
|
||||
|
||||
@@ -18,7 +18,7 @@ use devtools::http_client;
|
||||
use jsonrpc_core::MetaIoHandler;
|
||||
use http::{self, hyper};
|
||||
|
||||
use {HttpSettings, HttpServer};
|
||||
use {HttpServer};
|
||||
use tests::helpers::Server;
|
||||
use v1::{extractors, Metadata};
|
||||
|
||||
@@ -33,11 +33,13 @@ fn serve(handler: Option<MetaIoHandler<Metadata>>) -> Server<HttpServer> {
|
||||
handler,
|
||||
remote,
|
||||
extractors::RpcExtractor,
|
||||
HttpSettings::Dapps(Some(|_req: &hyper::server::Request<hyper::net::HttpStream>, _control: &hyper::Control| {
|
||||
Some(|request: hyper::Request| {
|
||||
http::RequestMiddlewareAction::Proceed {
|
||||
should_continue_on_invalid_cors: false
|
||||
should_continue_on_invalid_cors: false,
|
||||
request,
|
||||
}
|
||||
})),
|
||||
}),
|
||||
1,
|
||||
).unwrap())
|
||||
}
|
||||
|
||||
@@ -49,14 +51,13 @@ fn request(server: Server<HttpServer>, request: &str) -> http_client::Response {
|
||||
#[cfg(test)]
|
||||
mod testsing {
|
||||
use jsonrpc_core::{MetaIoHandler, Value};
|
||||
use jsonrpc_core::futures::{Future, future};
|
||||
use v1::Metadata;
|
||||
use super::{request, Server};
|
||||
|
||||
fn serve() -> (Server<::HttpServer>, ::std::net::SocketAddr) {
|
||||
let mut io = MetaIoHandler::default();
|
||||
io.add_method_with_meta("hello", |_, meta: Metadata| {
|
||||
future::ok(Value::String(format!("{}", meta.origin))).boxed()
|
||||
Ok(Value::String(format!("{}", meta.origin)))
|
||||
});
|
||||
let server = super::serve(Some(io));
|
||||
let address = server.server.address().to_owned();
|
||||
|
||||
@@ -236,7 +236,7 @@ impl<M: core::Middleware<Metadata>> core::Middleware<Metadata> for WsDispatcher<
|
||||
if use_full {
|
||||
A(self.full_handler.handle_rpc_request(request, meta))
|
||||
} else {
|
||||
B(process(request, meta).boxed())
|
||||
B(Box::new(process(request, meta)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ use std::fmt::Debug;
|
||||
use std::ops::Deref;
|
||||
use std::sync::Arc;
|
||||
|
||||
use futures::{future, Future, BoxFuture};
|
||||
use light::cache::Cache as LightDataCache;
|
||||
use light::client::LightChainClient;
|
||||
use light::on_demand::{request, OnDemand};
|
||||
@@ -43,7 +42,9 @@ use ethcore::transaction::{Action, SignedTransaction, PendingTransaction, Transa
|
||||
use ethcore::account_provider::AccountProvider;
|
||||
use crypto::DEFAULT_MAC;
|
||||
|
||||
use jsonrpc_core::Error;
|
||||
use jsonrpc_core::{BoxFuture, Error};
|
||||
use jsonrpc_core::futures::{future, Future};
|
||||
use jsonrpc_core::futures::future::Either;
|
||||
use v1::helpers::{errors, TransactionRequest, FilledTransactionRequest, ConfirmationPayload};
|
||||
use v1::types::{
|
||||
H256 as RpcH256, H520 as RpcH520, Bytes as RpcBytes,
|
||||
@@ -120,7 +121,7 @@ impl<C: MiningBlockChainClient, M: MinerService> Dispatcher for FullDispatcher<C
|
||||
false => request.nonce,
|
||||
true => Some(Self::fill_nonce(request.nonce, &from, &miner, &client)),
|
||||
};
|
||||
future::ok(FilledTransactionRequest {
|
||||
Box::new(future::ok(FilledTransactionRequest {
|
||||
from: from,
|
||||
used_default_from: request.from.is_none(),
|
||||
to: request.to,
|
||||
@@ -130,7 +131,7 @@ impl<C: MiningBlockChainClient, M: MinerService> Dispatcher for FullDispatcher<C
|
||||
value: request.value.unwrap_or_else(|| 0.into()),
|
||||
data: request.data.unwrap_or_else(Vec::new),
|
||||
condition: request.condition,
|
||||
}).boxed()
|
||||
}))
|
||||
}
|
||||
|
||||
fn sign(&self, accounts: Arc<AccountProvider>, filled: FilledTransactionRequest, password: SignWith)
|
||||
@@ -139,7 +140,7 @@ impl<C: MiningBlockChainClient, M: MinerService> Dispatcher for FullDispatcher<C
|
||||
let (client, miner) = (self.client.clone(), self.miner.clone());
|
||||
let chain_id = client.signing_chain_id();
|
||||
let address = filled.from;
|
||||
future::done({
|
||||
Box::new(future::done({
|
||||
let t = Transaction {
|
||||
nonce: Self::fill_nonce(filled.nonce, &filled.from, &miner, &client),
|
||||
action: filled.to.map_or(Action::Create, Action::Call),
|
||||
@@ -159,7 +160,7 @@ impl<C: MiningBlockChainClient, M: MinerService> Dispatcher for FullDispatcher<C
|
||||
.expect("Transaction was signed by AccountsProvider; it never produces invalid signatures; qed")
|
||||
}))
|
||||
}
|
||||
}).boxed()
|
||||
}))
|
||||
}
|
||||
|
||||
fn dispatch_transaction(&self, signed_transaction: PendingTransaction) -> Result<H256, Error> {
|
||||
@@ -182,7 +183,7 @@ pub fn fetch_gas_price_corpus(
|
||||
const GAS_PRICE_SAMPLE_SIZE: usize = 100;
|
||||
|
||||
if let Some(cached) = { cache.lock().gas_price_corpus() } {
|
||||
return future::ok(cached).boxed()
|
||||
return Box::new(future::ok(cached))
|
||||
}
|
||||
|
||||
let cache = cache.clone();
|
||||
@@ -217,8 +218,8 @@ pub fn fetch_gas_price_corpus(
|
||||
});
|
||||
|
||||
match eventual_corpus {
|
||||
Some(corp) => corp.map_err(|_| errors::no_light_peers()).boxed(),
|
||||
None => future::err(errors::network_disabled()).boxed(),
|
||||
Some(corp) => Box::new(corp.map_err(|_| errors::no_light_peers())),
|
||||
None => Box::new(future::err(errors::network_disabled())),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,7 +285,7 @@ impl LightDispatcher {
|
||||
// fast path where we don't go to network; nonce provided or can be gotten from queue.
|
||||
let maybe_nonce = self.transaction_queue.read().next_nonce(&addr);
|
||||
if let Some(nonce) = maybe_nonce {
|
||||
return future::ok(nonce).boxed()
|
||||
return Box::new(future::ok(nonce))
|
||||
}
|
||||
|
||||
let best_header = self.client.best_block_header();
|
||||
@@ -295,11 +296,11 @@ impl LightDispatcher {
|
||||
}).expect("no back-references; therefore all back-references valid; qed"));
|
||||
|
||||
match nonce_future {
|
||||
Some(x) =>
|
||||
Some(x) => Box::new(
|
||||
x.map(move |acc| acc.map_or(account_start_nonce, |acc| acc.nonce))
|
||||
.map_err(|_| errors::no_light_peers())
|
||||
.boxed(),
|
||||
None => future::err(errors::network_disabled()).boxed()
|
||||
),
|
||||
None => Box::new(future::err(errors::network_disabled()))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -332,29 +333,29 @@ impl Dispatcher for LightDispatcher {
|
||||
|
||||
// fast path for known gas price.
|
||||
let gas_price = match request_gas_price {
|
||||
Some(gas_price) => future::ok(with_gas_price(gas_price)).boxed(),
|
||||
None => fetch_gas_price_corpus(
|
||||
Some(gas_price) => Either::A(future::ok(with_gas_price(gas_price))),
|
||||
None => Either::B(fetch_gas_price_corpus(
|
||||
self.sync.clone(),
|
||||
self.client.clone(),
|
||||
self.on_demand.clone(),
|
||||
self.cache.clone()
|
||||
).and_then(|corp| match corp.median() {
|
||||
Some(median) => future::ok(*median),
|
||||
None => future::ok(DEFAULT_GAS_PRICE), // fall back to default on error.
|
||||
}).map(with_gas_price).boxed()
|
||||
Some(median) => Ok(*median),
|
||||
None => Ok(DEFAULT_GAS_PRICE), // fall back to default on error.
|
||||
}).map(with_gas_price))
|
||||
};
|
||||
|
||||
match (request_nonce, force_nonce) {
|
||||
(_, false) | (Some(_), true) => gas_price,
|
||||
(_, false) | (Some(_), true) => Box::new(gas_price),
|
||||
(None, true) => {
|
||||
let next_nonce = self.next_nonce(from);
|
||||
gas_price.and_then(move |mut filled| next_nonce
|
||||
Box::new(gas_price.and_then(move |mut filled| next_nonce
|
||||
.map_err(|_| errors::no_light_peers())
|
||||
.map(move |nonce| {
|
||||
filled.nonce = Some(nonce);
|
||||
filled
|
||||
})
|
||||
).boxed()
|
||||
))
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -390,13 +391,12 @@ impl Dispatcher for LightDispatcher {
|
||||
|
||||
// fast path for pre-filled nonce.
|
||||
if let Some(nonce) = filled.nonce {
|
||||
return future::done(with_nonce(filled, nonce)).boxed()
|
||||
return Box::new(future::done(with_nonce(filled, nonce)))
|
||||
}
|
||||
|
||||
self.next_nonce(address)
|
||||
Box::new(self.next_nonce(address)
|
||||
.map_err(|_| errors::no_light_peers())
|
||||
.and_then(move |nonce| with_nonce(filled, nonce))
|
||||
.boxed()
|
||||
.and_then(move |nonce| with_nonce(filled, nonce)))
|
||||
}
|
||||
|
||||
fn dispatch_transaction(&self, signed_transaction: PendingTransaction) -> Result<H256, Error> {
|
||||
@@ -497,7 +497,7 @@ pub fn execute<D: Dispatcher + 'static>(
|
||||
match payload {
|
||||
ConfirmationPayload::SendTransaction(request) => {
|
||||
let condition = request.condition.clone().map(Into::into);
|
||||
dispatcher.sign(accounts, request, pass)
|
||||
Box::new(dispatcher.sign(accounts, request, pass)
|
||||
.map(move |v| v.map(move |tx| PendingTransaction::new(tx, condition)))
|
||||
.map(WithToken::into_tuple)
|
||||
.map(|(tx, token)| (tx, token, dispatcher))
|
||||
@@ -506,18 +506,18 @@ pub fn execute<D: Dispatcher + 'static>(
|
||||
.map(RpcH256::from)
|
||||
.map(ConfirmationResponse::SendTransaction)
|
||||
.map(move |h| WithToken::from((h, tok)))
|
||||
}).boxed()
|
||||
}))
|
||||
},
|
||||
ConfirmationPayload::SignTransaction(request) => {
|
||||
dispatcher.sign(accounts, request, pass)
|
||||
Box::new(dispatcher.sign(accounts, request, pass)
|
||||
.map(|result| result
|
||||
.map(RpcRichRawTransaction::from)
|
||||
.map(ConfirmationResponse::SignTransaction)
|
||||
).boxed()
|
||||
))
|
||||
},
|
||||
ConfirmationPayload::EthSignMessage(address, data) => {
|
||||
if accounts.is_hardware_address(address) {
|
||||
return future::err(errors::unsupported("Signing via hardware wallets is not supported.", None)).boxed();
|
||||
return Box::new(future::err(errors::unsupported("Signing via hardware wallets is not supported.", None)));
|
||||
}
|
||||
|
||||
let hash = eth_data_hash(data);
|
||||
@@ -527,11 +527,11 @@ pub fn execute<D: Dispatcher + 'static>(
|
||||
.map(RpcH520::from)
|
||||
.map(ConfirmationResponse::Signature)
|
||||
);
|
||||
future::done(res).boxed()
|
||||
Box::new(future::done(res))
|
||||
},
|
||||
ConfirmationPayload::Decrypt(address, data) => {
|
||||
if accounts.is_hardware_address(address) {
|
||||
return future::err(errors::unsupported("Decrypting via hardware wallets is not supported.", None)).boxed();
|
||||
return Box::new(future::err(errors::unsupported("Decrypting via hardware wallets is not supported.", None)));
|
||||
}
|
||||
|
||||
let res = decrypt(&accounts, address, data, pass)
|
||||
@@ -539,7 +539,7 @@ pub fn execute<D: Dispatcher + 'static>(
|
||||
.map(RpcBytes)
|
||||
.map(ConfirmationResponse::Decrypt)
|
||||
);
|
||||
future::done(res).boxed()
|
||||
Box::new(future::done(res))
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -602,20 +602,18 @@ pub fn from_rpc<D>(payload: RpcConfirmationPayload, default_account: Address, di
|
||||
{
|
||||
match payload {
|
||||
RpcConfirmationPayload::SendTransaction(request) => {
|
||||
dispatcher.fill_optional_fields(request.into(), default_account, false)
|
||||
.map(ConfirmationPayload::SendTransaction)
|
||||
.boxed()
|
||||
Box::new(dispatcher.fill_optional_fields(request.into(), default_account, false)
|
||||
.map(ConfirmationPayload::SendTransaction))
|
||||
},
|
||||
RpcConfirmationPayload::SignTransaction(request) => {
|
||||
dispatcher.fill_optional_fields(request.into(), default_account, false)
|
||||
.map(ConfirmationPayload::SignTransaction)
|
||||
.boxed()
|
||||
Box::new(dispatcher.fill_optional_fields(request.into(), default_account, false)
|
||||
.map(ConfirmationPayload::SignTransaction))
|
||||
},
|
||||
RpcConfirmationPayload::Decrypt(RpcDecryptRequest { address, msg }) => {
|
||||
future::ok(ConfirmationPayload::Decrypt(address.into(), msg.into())).boxed()
|
||||
Box::new(future::ok(ConfirmationPayload::Decrypt(address.into(), msg.into())))
|
||||
},
|
||||
RpcConfirmationPayload::EthSignMessage(RpcSignRequest { address, data }) => {
|
||||
future::ok(ConfirmationPayload::EthSignMessage(address.into(), data.into())).boxed()
|
||||
Box::new(future::ok(ConfirmationPayload::EthSignMessage(address.into(), data.into())))
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ use std::fmt;
|
||||
use rlp::DecoderError;
|
||||
use ethcore::error::{Error as EthcoreError, CallError, TransactionError};
|
||||
use ethcore::account_provider::{SignError as AccountError};
|
||||
use jsonrpc_core::{Error, ErrorCode, Value};
|
||||
use jsonrpc_core::{futures, Error, ErrorCode, Value};
|
||||
|
||||
mod codes {
|
||||
// NOTE [ToDr] Codes from [-32099, -32000]
|
||||
@@ -379,6 +379,6 @@ pub fn deprecated<T: Into<Option<String>>>(message: T) -> Error {
|
||||
}
|
||||
|
||||
// on-demand sender cancelled.
|
||||
pub fn on_demand_cancel(_cancel: ::futures::sync::oneshot::Canceled) -> Error {
|
||||
pub fn on_demand_cancel(_cancel: futures::sync::oneshot::Canceled) -> Error {
|
||||
internal("on-demand sender cancelled", "")
|
||||
}
|
||||
|
||||
@@ -25,9 +25,9 @@ use ethcore::ids::BlockId;
|
||||
use ethcore::filter::Filter as EthcoreFilter;
|
||||
use ethcore::transaction::{Action, Transaction as EthTransaction};
|
||||
|
||||
use futures::{future, Future, BoxFuture};
|
||||
use futures::future::Either;
|
||||
use jsonrpc_core::Error;
|
||||
use jsonrpc_core::{BoxFuture, Error};
|
||||
use jsonrpc_core::futures::{future, Future};
|
||||
use jsonrpc_core::futures::future::Either;
|
||||
use jsonrpc_macros::Trailing;
|
||||
|
||||
use light::cache::Cache;
|
||||
@@ -113,22 +113,21 @@ impl LightFetch {
|
||||
let mut reqs = Vec::new();
|
||||
let header_ref = match self.make_header_requests(id, &mut reqs) {
|
||||
Ok(r) => r,
|
||||
Err(e) => return future::err(e).boxed(),
|
||||
Err(e) => return Box::new(future::err(e)),
|
||||
};
|
||||
|
||||
let maybe_future = self.sync.with_context(move |ctx| {
|
||||
self.on_demand.request_raw(ctx, reqs)
|
||||
Box::new(self.on_demand.request_raw(ctx, reqs)
|
||||
.expect("all back-references known to be valid; qed")
|
||||
.map(|res| extract_header(&res, header_ref)
|
||||
.expect("these responses correspond to requests that header_ref belongs to. \
|
||||
therefore it will not fail; qed"))
|
||||
.map_err(errors::on_demand_cancel)
|
||||
.boxed()
|
||||
.map_err(errors::on_demand_cancel))
|
||||
});
|
||||
|
||||
match maybe_future {
|
||||
Some(recv) => recv,
|
||||
None => future::err(errors::network_disabled()).boxed()
|
||||
None => Box::new(future::err(errors::network_disabled()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,25 +137,24 @@ impl LightFetch {
|
||||
let mut reqs = Vec::new();
|
||||
let header_ref = match self.make_header_requests(id, &mut reqs) {
|
||||
Ok(r) => r,
|
||||
Err(e) => return future::err(e).boxed(),
|
||||
Err(e) => return Box::new(future::err(e)),
|
||||
};
|
||||
|
||||
reqs.push(request::Account { header: header_ref, address: address }.into());
|
||||
|
||||
let maybe_future = self.sync.with_context(move |ctx| {
|
||||
self.on_demand.request_raw(ctx, reqs)
|
||||
Box::new(self.on_demand.request_raw(ctx, reqs)
|
||||
.expect("all back-references known to be valid; qed")
|
||||
.map(|mut res| match res.pop() {
|
||||
Some(OnDemandResponse::Account(acc)) => acc,
|
||||
_ => panic!("responses correspond directly with requests in amount and type; qed"),
|
||||
})
|
||||
.map_err(errors::on_demand_cancel)
|
||||
.boxed()
|
||||
.map_err(errors::on_demand_cancel))
|
||||
});
|
||||
|
||||
match maybe_future {
|
||||
Some(recv) => recv,
|
||||
None => future::err(errors::network_disabled()).boxed()
|
||||
None => Box::new(future::err(errors::network_disabled()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,7 +191,7 @@ impl LightFetch {
|
||||
let header_fut = self.header(id);
|
||||
|
||||
// fetch missing transaction fields from the network.
|
||||
nonce_fut.join(gas_price_fut).and_then(move |(nonce, gas_price)| {
|
||||
Box::new(nonce_fut.join(gas_price_fut).and_then(move |(nonce, gas_price)| {
|
||||
let action = req.to.map_or(Action::Create, Action::Call);
|
||||
let value = req.value.unwrap_or_else(U256::zero);
|
||||
let data = req.data.unwrap_or_default();
|
||||
@@ -222,10 +220,10 @@ impl LightFetch {
|
||||
// TODO: get last-hashes from network.
|
||||
let env_info = match client.env_info(id) {
|
||||
Some(env_info) => env_info,
|
||||
_ => return future::err(errors::unknown_block()).boxed(),
|
||||
_ => return Either::A(future::err(errors::unknown_block())),
|
||||
};
|
||||
|
||||
execute_tx(gas_known, ExecuteParams {
|
||||
Either::B(execute_tx(gas_known, ExecuteParams {
|
||||
from: from,
|
||||
tx: tx,
|
||||
hdr: hdr,
|
||||
@@ -233,8 +231,8 @@ impl LightFetch {
|
||||
engine: client.engine().clone(),
|
||||
on_demand: on_demand,
|
||||
sync: sync,
|
||||
})
|
||||
}).boxed()
|
||||
}))
|
||||
}))
|
||||
}
|
||||
|
||||
/// get a block itself. fails on unknown block ID.
|
||||
@@ -242,33 +240,31 @@ impl LightFetch {
|
||||
let mut reqs = Vec::new();
|
||||
let header_ref = match self.make_header_requests(id, &mut reqs) {
|
||||
Ok(r) => r,
|
||||
Err(e) => return future::err(e).boxed(),
|
||||
Err(e) => return Box::new(future::err(e)),
|
||||
};
|
||||
|
||||
reqs.push(request::Body(header_ref).into());
|
||||
|
||||
let maybe_future = self.sync.with_context(move |ctx| {
|
||||
self.on_demand.request_raw(ctx, reqs)
|
||||
Box::new(self.on_demand.request_raw(ctx, reqs)
|
||||
.expect("all back-references known to be valid; qed")
|
||||
.map(|mut res| match res.pop() {
|
||||
Some(OnDemandResponse::Body(b)) => b,
|
||||
_ => panic!("responses correspond directly with requests in amount and type; qed"),
|
||||
})
|
||||
.map_err(errors::on_demand_cancel)
|
||||
.boxed()
|
||||
.map_err(errors::on_demand_cancel))
|
||||
});
|
||||
|
||||
match maybe_future {
|
||||
Some(recv) => recv,
|
||||
None => future::err(errors::network_disabled()).boxed()
|
||||
None => Box::new(future::err(errors::network_disabled()))
|
||||
}
|
||||
}
|
||||
|
||||
/// get transaction logs
|
||||
pub fn logs(&self, filter: EthcoreFilter) -> BoxFuture<Vec<Log>, Error> {
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use futures::stream::{self, Stream};
|
||||
use jsonrpc_core::futures::stream::{self, Stream};
|
||||
|
||||
const NO_INVALID_BACK_REFS: &'static str = "Fails only on invalid back-references; back-references here known to be valid; qed";
|
||||
|
||||
@@ -282,9 +278,9 @@ impl LightFetch {
|
||||
};
|
||||
|
||||
match (block_number(filter.to_block), block_number(filter.from_block)) {
|
||||
(Some(to), Some(from)) if to < from => return future::ok(Vec::new()).boxed(),
|
||||
(Some(to), Some(from)) if to < from => return Box::new(future::ok(Vec::new())),
|
||||
(Some(_), Some(_)) => {},
|
||||
_ => return future::err(errors::unknown_block()).boxed(),
|
||||
_ => return Box::new(future::err(errors::unknown_block())),
|
||||
}
|
||||
|
||||
let maybe_future = self.sync.with_context(move |ctx| {
|
||||
@@ -318,8 +314,8 @@ impl LightFetch {
|
||||
});
|
||||
|
||||
match maybe_future {
|
||||
Some(fut) => fut.boxed(),
|
||||
None => future::err(errors::network_disabled()).boxed(),
|
||||
Some(fut) => Box::new(fut),
|
||||
None => Box::new(future::err(errors::network_disabled())),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -339,7 +335,7 @@ struct ExecuteParams {
|
||||
// this will double the gas on each `OutOfGas` error.
|
||||
fn execute_tx(gas_known: bool, params: ExecuteParams) -> BoxFuture<ExecutionResult, Error> {
|
||||
if !gas_known {
|
||||
future::loop_fn(params, |mut params| {
|
||||
Box::new(future::loop_fn(params, |mut params| {
|
||||
execute_tx(true, params.clone()).and_then(move |res| {
|
||||
match res {
|
||||
Ok(executed) => {
|
||||
@@ -360,7 +356,7 @@ fn execute_tx(gas_known: bool, params: ExecuteParams) -> BoxFuture<ExecutionResu
|
||||
failed => Ok(future::Loop::Break(failed)),
|
||||
}
|
||||
})
|
||||
}).boxed()
|
||||
}))
|
||||
} else {
|
||||
trace!(target: "light_fetch", "Placing execution request for {} gas in on_demand",
|
||||
params.tx.gas);
|
||||
@@ -381,8 +377,8 @@ fn execute_tx(gas_known: bool, params: ExecuteParams) -> BoxFuture<ExecutionResu
|
||||
});
|
||||
|
||||
match proved_future {
|
||||
Some(fut) => fut.boxed(),
|
||||
None => future::err(errors::network_disabled()).boxed(),
|
||||
Some(fut) => Box::new(fut),
|
||||
None => Box::new(future::err(errors::network_disabled())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use jsonrpc_core::Error;
|
||||
use futures::{self, Future};
|
||||
use futures::sync::oneshot;
|
||||
use jsonrpc_core::futures::{self, Future};
|
||||
use jsonrpc_core::futures::sync::oneshot;
|
||||
use v1::helpers::errors;
|
||||
|
||||
pub type Res<T> = Result<T, Error>;
|
||||
|
||||
@@ -22,8 +22,8 @@ use parking_lot::Mutex;
|
||||
|
||||
use jsonrpc_core::futures::future::{self, Either};
|
||||
use jsonrpc_core::futures::sync::mpsc;
|
||||
use jsonrpc_core::futures::{Sink, Future, BoxFuture};
|
||||
use jsonrpc_core::{self as core, MetaIoHandler};
|
||||
use jsonrpc_core::futures::{Sink, Future};
|
||||
use jsonrpc_core::{self as core, MetaIoHandler, BoxFuture};
|
||||
use jsonrpc_pubsub::SubscriptionId;
|
||||
|
||||
use v1::helpers::Subscribers;
|
||||
@@ -130,7 +130,7 @@ impl<S: core::Middleware<Metadata>> GenericPollManager<S> {
|
||||
}
|
||||
|
||||
// return a future represeting all the polls
|
||||
future::join_all(futures).map(|_| ()).boxed()
|
||||
Box::new(future::join_all(futures).map(|_| ()))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ use std::thread;
|
||||
use std::time::{Instant, Duration};
|
||||
use std::sync::Arc;
|
||||
|
||||
use futures::{self, future, BoxFuture, Future};
|
||||
use rlp::{self, UntrustedRlp};
|
||||
use time::get_time;
|
||||
use bigint::prelude::U256;
|
||||
@@ -41,7 +40,8 @@ use ethcore::transaction::SignedTransaction;
|
||||
use ethcore::snapshot::SnapshotService;
|
||||
use ethsync::{SyncProvider};
|
||||
|
||||
use jsonrpc_core::Error;
|
||||
use jsonrpc_core::{BoxFuture, Error};
|
||||
use jsonrpc_core::futures::future;
|
||||
use jsonrpc_macros::Trailing;
|
||||
|
||||
use v1::helpers::{errors, limit_logs, fake_sign};
|
||||
@@ -318,19 +318,15 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> where
|
||||
}
|
||||
}
|
||||
|
||||
fn author(&self, meta: Metadata) -> BoxFuture<RpcH160, Error> {
|
||||
fn author(&self, meta: Metadata) -> Result<RpcH160, Error> {
|
||||
let dapp = meta.dapp_id();
|
||||
|
||||
let author = move || {
|
||||
let mut miner = self.miner.author();
|
||||
if miner == 0.into() {
|
||||
miner = self.dapp_accounts(dapp.into())?.get(0).cloned().unwrap_or_default();
|
||||
}
|
||||
let mut miner = self.miner.author();
|
||||
if miner == 0.into() {
|
||||
miner = self.dapp_accounts(dapp.into())?.get(0).cloned().unwrap_or_default();
|
||||
}
|
||||
|
||||
Ok(RpcH160::from(miner))
|
||||
};
|
||||
|
||||
futures::done(author()).boxed()
|
||||
Ok(RpcH160::from(miner))
|
||||
}
|
||||
|
||||
fn is_mining(&self) -> Result<bool, Error> {
|
||||
@@ -345,15 +341,11 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> where
|
||||
Ok(RpcU256::from(default_gas_price(&*self.client, &*self.miner)))
|
||||
}
|
||||
|
||||
fn accounts(&self, meta: Metadata) -> BoxFuture<Vec<RpcH160>, Error> {
|
||||
fn accounts(&self, meta: Metadata) -> Result<Vec<RpcH160>, Error> {
|
||||
let dapp = meta.dapp_id();
|
||||
|
||||
let accounts = move || {
|
||||
let accounts = self.dapp_accounts(dapp.into())?;
|
||||
Ok(accounts.into_iter().map(Into::into).collect())
|
||||
};
|
||||
|
||||
futures::done(accounts()).boxed()
|
||||
let accounts = self.dapp_accounts(dapp.into())?;
|
||||
Ok(accounts.into_iter().map(Into::into).collect())
|
||||
}
|
||||
|
||||
fn block_number(&self) -> Result<RpcU256, Error> {
|
||||
@@ -371,7 +363,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> where
|
||||
None => Err(errors::state_pruned()),
|
||||
};
|
||||
|
||||
future::done(res).boxed()
|
||||
Box::new(future::done(res))
|
||||
}
|
||||
|
||||
fn storage_at(&self, address: RpcH160, pos: RpcU256, num: Trailing<BlockNumber>) -> BoxFuture<RpcH256, Error> {
|
||||
@@ -386,7 +378,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> where
|
||||
None => Err(errors::state_pruned()),
|
||||
};
|
||||
|
||||
future::done(res).boxed()
|
||||
Box::new(future::done(res))
|
||||
}
|
||||
|
||||
fn transaction_count(&self, address: RpcH160, num: Trailing<BlockNumber>) -> BoxFuture<RpcU256, Error> {
|
||||
@@ -411,38 +403,37 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> where
|
||||
}
|
||||
};
|
||||
|
||||
future::done(res).boxed()
|
||||
Box::new(future::done(res))
|
||||
}
|
||||
|
||||
fn block_transaction_count_by_hash(&self, hash: RpcH256) -> BoxFuture<Option<RpcU256>, Error> {
|
||||
future::ok(self.client.block(BlockId::Hash(hash.into()))
|
||||
.map(|block| block.transactions_count().into())).boxed()
|
||||
Box::new(future::ok(self.client.block(BlockId::Hash(hash.into()))
|
||||
.map(|block| block.transactions_count().into())))
|
||||
}
|
||||
|
||||
fn block_transaction_count_by_number(&self, num: BlockNumber) -> BoxFuture<Option<RpcU256>, Error> {
|
||||
future::ok(match num {
|
||||
Box::new(future::ok(match num {
|
||||
BlockNumber::Pending => Some(
|
||||
self.miner.status().transactions_in_pending_block.into()
|
||||
),
|
||||
_ =>
|
||||
self.client.block(num.into())
|
||||
.map(|block| block.transactions_count().into())
|
||||
}).boxed()
|
||||
}))
|
||||
}
|
||||
|
||||
fn block_uncles_count_by_hash(&self, hash: RpcH256) -> BoxFuture<Option<RpcU256>, Error> {
|
||||
future::ok(self.client.block(BlockId::Hash(hash.into()))
|
||||
.map(|block| block.uncles_count().into()))
|
||||
.boxed()
|
||||
Box::new(future::ok(self.client.block(BlockId::Hash(hash.into()))
|
||||
.map(|block| block.uncles_count().into())))
|
||||
}
|
||||
|
||||
fn block_uncles_count_by_number(&self, num: BlockNumber) -> BoxFuture<Option<RpcU256>, Error> {
|
||||
future::ok(match num {
|
||||
Box::new(future::ok(match num {
|
||||
BlockNumber::Pending => Some(0.into()),
|
||||
_ => self.client.block(num.into())
|
||||
.map(|block| block.uncles_count().into()
|
||||
),
|
||||
}).boxed()
|
||||
}))
|
||||
}
|
||||
|
||||
fn code_at(&self, address: RpcH160, num: Trailing<BlockNumber>) -> BoxFuture<Bytes, Error> {
|
||||
@@ -456,15 +447,15 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> where
|
||||
None => Err(errors::state_pruned()),
|
||||
};
|
||||
|
||||
future::done(res).boxed()
|
||||
Box::new(future::done(res))
|
||||
}
|
||||
|
||||
fn block_by_hash(&self, hash: RpcH256, include_txs: bool) -> BoxFuture<Option<RichBlock>, Error> {
|
||||
future::done(self.block(BlockId::Hash(hash.into()), include_txs)).boxed()
|
||||
Box::new(future::done(self.block(BlockId::Hash(hash.into()), include_txs)))
|
||||
}
|
||||
|
||||
fn block_by_number(&self, num: BlockNumber, include_txs: bool) -> BoxFuture<Option<RichBlock>, Error> {
|
||||
future::done(self.block(num.into(), include_txs)).boxed()
|
||||
Box::new(future::done(self.block(num.into(), include_txs)))
|
||||
}
|
||||
|
||||
fn transaction_by_hash(&self, hash: RpcH256) -> Result<Option<Transaction>, Error> {
|
||||
@@ -521,7 +512,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> where
|
||||
|
||||
let logs = limit_logs(logs, filter.limit);
|
||||
|
||||
future::ok(logs).boxed()
|
||||
Box::new(future::ok(logs))
|
||||
}
|
||||
|
||||
fn work(&self, no_new_work_timeout: Trailing<u64>) -> Result<Work, Error> {
|
||||
@@ -615,30 +606,24 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> where
|
||||
|
||||
fn call(&self, meta: Self::Metadata, request: CallRequest, num: Trailing<BlockNumber>) -> BoxFuture<Bytes, Error> {
|
||||
let request = CallRequest::into(request);
|
||||
let signed = match fake_sign::sign_call(&self.client, &self.miner, request, meta.is_dapp()) {
|
||||
Ok(signed) => signed,
|
||||
Err(e) => return future::err(e).boxed(),
|
||||
};
|
||||
let signed = try_bf!(fake_sign::sign_call(&self.client, &self.miner, request, meta.is_dapp()));
|
||||
|
||||
let num = num.unwrap_or_default();
|
||||
let result = self.client.call(&signed, Default::default(), num.into());
|
||||
|
||||
future::done(result
|
||||
Box::new(future::done(result
|
||||
.map(|b| b.output.into())
|
||||
.map_err(errors::call)
|
||||
).boxed()
|
||||
))
|
||||
}
|
||||
|
||||
fn estimate_gas(&self, meta: Self::Metadata, request: CallRequest, num: Trailing<BlockNumber>) -> BoxFuture<RpcU256, Error> {
|
||||
let request = CallRequest::into(request);
|
||||
let signed = match fake_sign::sign_call(&self.client, &self.miner, request, meta.is_dapp()) {
|
||||
Ok(signed) => signed,
|
||||
Err(e) => return future::err(e).boxed(),
|
||||
};
|
||||
future::done(self.client.estimate_gas(&signed, num.unwrap_or_default().into())
|
||||
let signed = try_bf!(fake_sign::sign_call(&self.client, &self.miner, request, meta.is_dapp()));
|
||||
Box::new(future::done(self.client.estimate_gas(&signed, num.unwrap_or_default().into())
|
||||
.map(Into::into)
|
||||
.map_err(errors::call)
|
||||
).boxed()
|
||||
))
|
||||
}
|
||||
|
||||
fn compile_lll(&self, _: String) -> Result<Bytes, Error> {
|
||||
|
||||
@@ -19,15 +19,15 @@
|
||||
use std::sync::Arc;
|
||||
use std::collections::HashSet;
|
||||
|
||||
use jsonrpc_core::*;
|
||||
use ethcore::miner::MinerService;
|
||||
use ethcore::filter::Filter as EthcoreFilter;
|
||||
use ethcore::client::{BlockChainClient, BlockId};
|
||||
use bigint::hash::H256;
|
||||
use parking_lot::Mutex;
|
||||
|
||||
use futures::{future, Future, BoxFuture};
|
||||
|
||||
use jsonrpc_core::{BoxFuture, Error};
|
||||
use jsonrpc_core::futures::{future, Future};
|
||||
use jsonrpc_core::futures::future::Either;
|
||||
use v1::traits::EthFilter;
|
||||
use v1::types::{BlockNumber, Index, Filter, FilterChanges, Log, H256 as RpcH256, U256 as RpcU256};
|
||||
use v1::helpers::{PollFilter, PollManager, limit_logs};
|
||||
@@ -89,7 +89,7 @@ impl<C, M> Filterable for EthFilterClient<C, M> where C: BlockChainClient, M: Mi
|
||||
}
|
||||
|
||||
fn logs(&self, filter: EthcoreFilter) -> BoxFuture<Vec<Log>, Error> {
|
||||
future::ok(self.client.logs(filter).into_iter().map(Into::into).collect()).boxed()
|
||||
Box::new(future::ok(self.client.logs(filter).into_iter().map(Into::into).collect()))
|
||||
}
|
||||
|
||||
fn pending_logs(&self, block_number: u64, filter: &EthcoreFilter) -> Vec<Log> {
|
||||
@@ -125,8 +125,8 @@ impl<T: Filterable + Send + Sync + 'static> EthFilter for T {
|
||||
|
||||
fn filter_changes(&self, index: Index) -> BoxFuture<FilterChanges, Error> {
|
||||
let mut polls = self.polls().lock();
|
||||
match polls.poll_mut(&index.value()) {
|
||||
None => future::ok(FilterChanges::Empty).boxed(),
|
||||
Box::new(match polls.poll_mut(&index.value()) {
|
||||
None => Either::A(future::ok(FilterChanges::Empty)),
|
||||
Some(filter) => match *filter {
|
||||
PollFilter::Block(ref mut block_number) => {
|
||||
// + 1, cause we want to return hashes including current block hash.
|
||||
@@ -138,7 +138,7 @@ impl<T: Filterable + Send + Sync + 'static> EthFilter for T {
|
||||
|
||||
*block_number = current_number;
|
||||
|
||||
future::ok(FilterChanges::Hashes(hashes)).boxed()
|
||||
Either::A(future::ok(FilterChanges::Hashes(hashes)))
|
||||
},
|
||||
PollFilter::PendingTransaction(ref mut previous_hashes) => {
|
||||
// get hashes of pending transactions
|
||||
@@ -162,7 +162,7 @@ impl<T: Filterable + Send + Sync + 'static> EthFilter for T {
|
||||
*previous_hashes = current_hashes;
|
||||
|
||||
// return new hashes
|
||||
future::ok(FilterChanges::Hashes(new_hashes)).boxed()
|
||||
Either::A(future::ok(FilterChanges::Hashes(new_hashes)))
|
||||
},
|
||||
PollFilter::Logs(ref mut block_number, ref mut previous_logs, ref filter) => {
|
||||
// retrive the current block number
|
||||
@@ -200,14 +200,13 @@ impl<T: Filterable + Send + Sync + 'static> EthFilter for T {
|
||||
|
||||
// retrieve logs in range from_block..min(BlockId::Latest..to_block)
|
||||
let limit = filter.limit;
|
||||
self.logs(filter)
|
||||
Either::B(self.logs(filter)
|
||||
.map(move |mut logs| { logs.extend(pending); logs }) // append fetched pending logs
|
||||
.map(move |logs| limit_logs(logs, limit)) // limit the logs
|
||||
.map(FilterChanges::Logs)
|
||||
.boxed()
|
||||
.map(FilterChanges::Logs))
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn filter_logs(&self, index: Index) -> BoxFuture<Vec<Log>, Error> {
|
||||
@@ -217,7 +216,7 @@ impl<T: Filterable + Send + Sync + 'static> EthFilter for T {
|
||||
match polls.poll(&index.value()) {
|
||||
Some(&PollFilter::Logs(ref _block_number, ref _previous_log, ref filter)) => filter.clone(),
|
||||
// just empty array
|
||||
_ => return future::ok(Vec::new()).boxed(),
|
||||
_ => return Box::new(future::ok(Vec::new())),
|
||||
}
|
||||
};
|
||||
|
||||
@@ -235,11 +234,10 @@ impl<T: Filterable + Send + Sync + 'static> EthFilter for T {
|
||||
// retrieve logs asynchronously, appending pending logs.
|
||||
let limit = filter.limit;
|
||||
let logs = self.logs(filter);
|
||||
let res = logs
|
||||
Box::new(logs
|
||||
.map(move |mut logs| { logs.extend(pending); logs })
|
||||
.map(move |logs| limit_logs(logs, limit))
|
||||
.boxed();
|
||||
res
|
||||
)
|
||||
}
|
||||
|
||||
fn uninstall_filter(&self, index: Index) -> Result<bool, Error> {
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
use std::sync::Arc;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use futures::{self, future, BoxFuture, Future};
|
||||
use jsonrpc_core::Error;
|
||||
use jsonrpc_core::{BoxFuture, Error};
|
||||
use jsonrpc_core::futures::{self, Future, IntoFuture};
|
||||
use jsonrpc_macros::Trailing;
|
||||
use jsonrpc_macros::pubsub::{Sink, Subscriber};
|
||||
use jsonrpc_pubsub::SubscriptionId;
|
||||
@@ -131,8 +131,10 @@ impl<C> ChainNotificationHandler<C> {
|
||||
}
|
||||
}
|
||||
|
||||
fn notify_logs<F>(&self, enacted: &[H256], logs: F) where
|
||||
F: Fn(EthFilter) -> BoxFuture<Vec<Log>, Error>,
|
||||
fn notify_logs<F, T>(&self, enacted: &[H256], logs: F) where
|
||||
F: Fn(EthFilter) -> T,
|
||||
T: IntoFuture<Item = Vec<Log>, Error = Error>,
|
||||
T::Future: Send + 'static,
|
||||
{
|
||||
for &(ref subscriber, ref filter) in self.logs_subscribers.read().values() {
|
||||
let logs = futures::future::join_all(enacted
|
||||
@@ -141,7 +143,7 @@ impl<C> ChainNotificationHandler<C> {
|
||||
let mut filter = filter.clone();
|
||||
filter.from_block = BlockId::Hash(*hash);
|
||||
filter.to_block = filter.from_block.clone();
|
||||
logs(filter)
|
||||
logs(filter).into_future()
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
);
|
||||
@@ -224,15 +226,15 @@ impl<C: BlockChainClient> ChainNotify for ChainNotificationHandler<C> {
|
||||
|
||||
// Enacted logs
|
||||
self.notify_logs(&enacted, |filter| {
|
||||
future::ok(self.client.logs(filter).into_iter().map(Into::into).collect()).boxed()
|
||||
Ok(self.client.logs(filter).into_iter().map(Into::into).collect())
|
||||
});
|
||||
|
||||
// Retracted logs
|
||||
self.notify_logs(&retracted, |filter| {
|
||||
future::ok(self.client.logs(filter).into_iter().map(Into::into).map(|mut log: Log| {
|
||||
Ok(self.client.logs(filter).into_iter().map(Into::into).map(|mut log: Log| {
|
||||
log.log_type = "removed".into();
|
||||
log
|
||||
}).collect()).boxed()
|
||||
}).collect())
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -270,10 +272,10 @@ impl<C: Send + Sync + 'static> EthPubSub for EthPubSubClient<C> {
|
||||
let _ = subscriber.reject(error);
|
||||
}
|
||||
|
||||
fn unsubscribe(&self, id: SubscriptionId) -> BoxFuture<bool, Error> {
|
||||
fn unsubscribe(&self, id: SubscriptionId) -> Result<bool, Error> {
|
||||
let res = self.heads_subscribers.write().remove(&id).is_some();
|
||||
let res2 = self.logs_subscribers.write().remove(&id).is_some();
|
||||
|
||||
future::ok(res || res2).boxed()
|
||||
Ok(res || res2)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,12 +16,11 @@
|
||||
|
||||
//! Eth RPC interface for the light client.
|
||||
|
||||
// TODO: remove when complete.
|
||||
#![allow(unused_imports, unused_variables)]
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use jsonrpc_core::Error;
|
||||
use jsonrpc_core::{BoxFuture, Error};
|
||||
use jsonrpc_core::futures::{future, Future};
|
||||
use jsonrpc_core::futures::future::Either;
|
||||
use jsonrpc_macros::Trailing;
|
||||
|
||||
use light::cache::Cache as LightDataCache;
|
||||
@@ -30,25 +29,20 @@ use light::{cht, TransactionQueue};
|
||||
use light::on_demand::{request, OnDemand};
|
||||
|
||||
use ethcore::account_provider::{AccountProvider, DappId};
|
||||
use ethcore::basic_account::BasicAccount;
|
||||
use ethcore::encoded;
|
||||
use ethcore::executed::{Executed, ExecutionError};
|
||||
use ethcore::ids::BlockId;
|
||||
use ethcore::filter::Filter as EthcoreFilter;
|
||||
use ethcore::transaction::{Action, SignedTransaction, Transaction as EthTransaction};
|
||||
use ethcore::transaction::SignedTransaction;
|
||||
use ethsync::LightSync;
|
||||
use rlp::UntrustedRlp;
|
||||
use hash::{KECCAK_NULL_RLP, KECCAK_EMPTY_LIST_RLP};
|
||||
use bigint::prelude::U256;
|
||||
use parking_lot::{RwLock, Mutex};
|
||||
|
||||
use futures::{future, Future, BoxFuture, IntoFuture};
|
||||
use futures::sync::oneshot;
|
||||
|
||||
use v1::impls::eth_filter::Filterable;
|
||||
use v1::helpers::{CallRequest as CRequest, errors, limit_logs, dispatch};
|
||||
use v1::helpers::{errors, limit_logs};
|
||||
use v1::helpers::{PollFilter, PollManager};
|
||||
use v1::helpers::block_import::is_major_importing;
|
||||
use v1::helpers::light_fetch::LightFetch;
|
||||
use v1::traits::Eth;
|
||||
use v1::types::{
|
||||
@@ -58,8 +52,6 @@ use v1::types::{
|
||||
};
|
||||
use v1::metadata::Metadata;
|
||||
|
||||
use util::Address;
|
||||
|
||||
const NO_INVALID_BACK_REFS: &'static str = "Fails only on invalid back-references; back-references here known to be valid; qed";
|
||||
|
||||
/// Light client `ETH` (and filter) RPC.
|
||||
@@ -162,10 +154,10 @@ impl<T: LightChainClient + 'static> EthClient<T> {
|
||||
};
|
||||
|
||||
// get the block itself.
|
||||
self.fetcher().block(id).and_then(move |block| {
|
||||
Box::new(self.fetcher().block(id).and_then(move |block| {
|
||||
// then fetch the total difficulty (this is much easier after getting the block).
|
||||
match client.score(id) {
|
||||
Some(score) => future::ok(fill_rich(block, Some(score))).boxed(),
|
||||
Some(score) => Either::A(future::ok(fill_rich(block, Some(score)))),
|
||||
None => {
|
||||
// make a CHT request to fetch the chain score.
|
||||
let req = cht::block_to_cht_number(block.number())
|
||||
@@ -181,7 +173,7 @@ impl<T: LightChainClient + 'static> EthClient<T> {
|
||||
.expect("genesis always stored; qed")
|
||||
.difficulty();
|
||||
|
||||
return future::ok(fill_rich(block, Some(score))).boxed()
|
||||
return Either::A(future::ok(fill_rich(block, Some(score))))
|
||||
}
|
||||
};
|
||||
|
||||
@@ -191,7 +183,7 @@ impl<T: LightChainClient + 'static> EthClient<T> {
|
||||
// - we get a score, and our hash is canonical.
|
||||
let maybe_fut = sync.with_context(move |ctx| on_demand.request(ctx, req).expect(NO_INVALID_BACK_REFS));
|
||||
match maybe_fut {
|
||||
Some(fut) => fut
|
||||
Some(fut) => Either::B(fut
|
||||
.map(move |(hash, score)| {
|
||||
let score = if hash == block.hash() {
|
||||
Some(score)
|
||||
@@ -199,13 +191,13 @@ impl<T: LightChainClient + 'static> EthClient<T> {
|
||||
None
|
||||
};
|
||||
|
||||
fill_rich(block, score)
|
||||
}).map_err(errors::on_demand_cancel).boxed(),
|
||||
None => return future::err(errors::network_disabled()).boxed(),
|
||||
fill_rich(block, score)
|
||||
}).map_err(errors::on_demand_cancel)),
|
||||
None => Either::A(future::err(errors::network_disabled())),
|
||||
}
|
||||
}
|
||||
}
|
||||
}).boxed()
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,8 +227,8 @@ impl<T: LightChainClient + 'static> Eth for EthClient<T> {
|
||||
}
|
||||
}
|
||||
|
||||
fn author(&self, _meta: Self::Metadata) -> BoxFuture<RpcH160, Error> {
|
||||
future::ok(Default::default()).boxed()
|
||||
fn author(&self, _meta: Self::Metadata) -> Result<RpcH160, Error> {
|
||||
Ok(Default::default())
|
||||
}
|
||||
|
||||
fn is_mining(&self) -> Result<bool, Error> {
|
||||
@@ -254,16 +246,14 @@ impl<T: LightChainClient + 'static> Eth for EthClient<T> {
|
||||
.unwrap_or_else(Default::default))
|
||||
}
|
||||
|
||||
fn accounts(&self, meta: Metadata) -> BoxFuture<Vec<RpcH160>, Error> {
|
||||
fn accounts(&self, meta: Metadata) -> Result<Vec<RpcH160>, Error> {
|
||||
let dapp: DappId = meta.dapp_id().into();
|
||||
|
||||
let accounts = self.accounts
|
||||
self.accounts
|
||||
.note_dapp_used(dapp.clone())
|
||||
.and_then(|_| self.accounts.dapp_addresses(dapp))
|
||||
.map_err(|e| errors::account("Could not fetch accounts.", e))
|
||||
.map(|accs| accs.into_iter().map(Into::<RpcH160>::into).collect());
|
||||
|
||||
future::done(accounts).boxed()
|
||||
.map(|accs| accs.into_iter().map(Into::<RpcH160>::into).collect())
|
||||
}
|
||||
|
||||
fn block_number(&self) -> Result<RpcU256, Error> {
|
||||
@@ -271,93 +261,93 @@ impl<T: LightChainClient + 'static> Eth for EthClient<T> {
|
||||
}
|
||||
|
||||
fn balance(&self, address: RpcH160, num: Trailing<BlockNumber>) -> BoxFuture<RpcU256, Error> {
|
||||
self.fetcher().account(address.into(), num.unwrap_or_default().into())
|
||||
.map(|acc| acc.map_or(0.into(), |a| a.balance).into()).boxed()
|
||||
Box::new(self.fetcher().account(address.into(), num.unwrap_or_default().into())
|
||||
.map(|acc| acc.map_or(0.into(), |a| a.balance).into()))
|
||||
}
|
||||
|
||||
fn storage_at(&self, _address: RpcH160, _key: RpcU256, _num: Trailing<BlockNumber>) -> BoxFuture<RpcH256, Error> {
|
||||
future::err(errors::unimplemented(None)).boxed()
|
||||
Box::new(future::err(errors::unimplemented(None)))
|
||||
}
|
||||
|
||||
fn block_by_hash(&self, hash: RpcH256, include_txs: bool) -> BoxFuture<Option<RichBlock>, Error> {
|
||||
self.rich_block(BlockId::Hash(hash.into()), include_txs).map(Some).boxed()
|
||||
Box::new(self.rich_block(BlockId::Hash(hash.into()), include_txs).map(Some))
|
||||
}
|
||||
|
||||
fn block_by_number(&self, num: BlockNumber, include_txs: bool) -> BoxFuture<Option<RichBlock>, Error> {
|
||||
self.rich_block(num.into(), include_txs).map(Some).boxed()
|
||||
Box::new(self.rich_block(num.into(), include_txs).map(Some))
|
||||
}
|
||||
|
||||
fn transaction_count(&self, address: RpcH160, num: Trailing<BlockNumber>) -> BoxFuture<RpcU256, Error> {
|
||||
self.fetcher().account(address.into(), num.unwrap_or_default().into())
|
||||
.map(|acc| acc.map_or(0.into(), |a| a.nonce).into()).boxed()
|
||||
Box::new(self.fetcher().account(address.into(), num.unwrap_or_default().into())
|
||||
.map(|acc| acc.map_or(0.into(), |a| a.nonce).into()))
|
||||
}
|
||||
|
||||
fn block_transaction_count_by_hash(&self, hash: RpcH256) -> BoxFuture<Option<RpcU256>, Error> {
|
||||
let (sync, on_demand) = (self.sync.clone(), self.on_demand.clone());
|
||||
|
||||
self.fetcher().header(BlockId::Hash(hash.into())).and_then(move |hdr| {
|
||||
Box::new(self.fetcher().header(BlockId::Hash(hash.into())).and_then(move |hdr| {
|
||||
if hdr.transactions_root() == KECCAK_NULL_RLP {
|
||||
future::ok(Some(U256::from(0).into())).boxed()
|
||||
Either::A(future::ok(Some(U256::from(0).into())))
|
||||
} else {
|
||||
sync.with_context(|ctx| on_demand.request(ctx, request::Body(hdr.into())))
|
||||
.map(|x| x.expect(NO_INVALID_BACK_REFS))
|
||||
.map(|x| x.map(|b| Some(U256::from(b.transactions_count()).into())))
|
||||
.map(|x| x.map_err(errors::on_demand_cancel).boxed())
|
||||
.unwrap_or_else(|| future::err(errors::network_disabled()).boxed())
|
||||
.map(|x| Either::B(x.map_err(errors::on_demand_cancel)))
|
||||
.unwrap_or_else(|| Either::A(future::err(errors::network_disabled())))
|
||||
}
|
||||
}).boxed()
|
||||
}))
|
||||
}
|
||||
|
||||
fn block_transaction_count_by_number(&self, num: BlockNumber) -> BoxFuture<Option<RpcU256>, Error> {
|
||||
let (sync, on_demand) = (self.sync.clone(), self.on_demand.clone());
|
||||
|
||||
self.fetcher().header(num.into()).and_then(move |hdr| {
|
||||
Box::new(self.fetcher().header(num.into()).and_then(move |hdr| {
|
||||
if hdr.transactions_root() == KECCAK_NULL_RLP {
|
||||
future::ok(Some(U256::from(0).into())).boxed()
|
||||
Either::A(future::ok(Some(U256::from(0).into())))
|
||||
} else {
|
||||
sync.with_context(|ctx| on_demand.request(ctx, request::Body(hdr.into())))
|
||||
.map(|x| x.expect(NO_INVALID_BACK_REFS))
|
||||
.map(|x| x.map(|b| Some(U256::from(b.transactions_count()).into())))
|
||||
.map(|x| x.map_err(errors::on_demand_cancel).boxed())
|
||||
.unwrap_or_else(|| future::err(errors::network_disabled()).boxed())
|
||||
.map(|x| Either::B(x.map_err(errors::on_demand_cancel)))
|
||||
.unwrap_or_else(|| Either::A(future::err(errors::network_disabled())))
|
||||
}
|
||||
}).boxed()
|
||||
}))
|
||||
}
|
||||
|
||||
fn block_uncles_count_by_hash(&self, hash: RpcH256) -> BoxFuture<Option<RpcU256>, Error> {
|
||||
let (sync, on_demand) = (self.sync.clone(), self.on_demand.clone());
|
||||
|
||||
self.fetcher().header(BlockId::Hash(hash.into())).and_then(move |hdr| {
|
||||
Box::new(self.fetcher().header(BlockId::Hash(hash.into())).and_then(move |hdr| {
|
||||
if hdr.uncles_hash() == KECCAK_EMPTY_LIST_RLP {
|
||||
future::ok(Some(U256::from(0).into())).boxed()
|
||||
Either::A(future::ok(Some(U256::from(0).into())))
|
||||
} else {
|
||||
sync.with_context(|ctx| on_demand.request(ctx, request::Body(hdr.into())))
|
||||
.map(|x| x.expect(NO_INVALID_BACK_REFS))
|
||||
.map(|x| x.map(|b| Some(U256::from(b.uncles_count()).into())))
|
||||
.map(|x| x.map_err(errors::on_demand_cancel).boxed())
|
||||
.unwrap_or_else(|| future::err(errors::network_disabled()).boxed())
|
||||
.map(|x| Either::B(x.map_err(errors::on_demand_cancel)))
|
||||
.unwrap_or_else(|| Either::A(future::err(errors::network_disabled())))
|
||||
}
|
||||
}).boxed()
|
||||
}))
|
||||
}
|
||||
|
||||
fn block_uncles_count_by_number(&self, num: BlockNumber) -> BoxFuture<Option<RpcU256>, Error> {
|
||||
let (sync, on_demand) = (self.sync.clone(), self.on_demand.clone());
|
||||
|
||||
self.fetcher().header(num.into()).and_then(move |hdr| {
|
||||
Box::new(self.fetcher().header(num.into()).and_then(move |hdr| {
|
||||
if hdr.uncles_hash() == KECCAK_EMPTY_LIST_RLP {
|
||||
future::ok(Some(U256::from(0).into())).boxed()
|
||||
Either::B(future::ok(Some(U256::from(0).into())))
|
||||
} else {
|
||||
sync.with_context(|ctx| on_demand.request(ctx, request::Body(hdr.into())))
|
||||
.map(|x| x.expect(NO_INVALID_BACK_REFS))
|
||||
.map(|x| x.map(|b| Some(U256::from(b.uncles_count()).into())))
|
||||
.map(|x| x.map_err(errors::on_demand_cancel).boxed())
|
||||
.unwrap_or_else(|| future::err(errors::network_disabled()).boxed())
|
||||
.map(|x| Either::A(x.map_err(errors::on_demand_cancel)))
|
||||
.unwrap_or_else(|| Either::B(future::err(errors::network_disabled())))
|
||||
}
|
||||
}).boxed()
|
||||
}))
|
||||
}
|
||||
|
||||
fn code_at(&self, address: RpcH160, num: Trailing<BlockNumber>) -> BoxFuture<Bytes, Error> {
|
||||
future::err(errors::unimplemented(None)).boxed()
|
||||
fn code_at(&self, _address: RpcH160, _num: Trailing<BlockNumber>) -> BoxFuture<Bytes, Error> {
|
||||
Box::new(future::err(errors::unimplemented(None)))
|
||||
}
|
||||
|
||||
fn send_raw_transaction(&self, raw: Bytes) -> Result<RpcH256, Error> {
|
||||
@@ -385,45 +375,45 @@ impl<T: LightChainClient + 'static> Eth for EthClient<T> {
|
||||
}
|
||||
|
||||
fn call(&self, _meta: Self::Metadata, req: CallRequest, num: Trailing<BlockNumber>) -> BoxFuture<Bytes, Error> {
|
||||
self.fetcher().proved_execution(req, num).and_then(|res| {
|
||||
Box::new(self.fetcher().proved_execution(req, num).and_then(|res| {
|
||||
match res {
|
||||
Ok(exec) => Ok(exec.output.into()),
|
||||
Err(e) => Err(errors::execution(e)),
|
||||
}
|
||||
}).boxed()
|
||||
}))
|
||||
}
|
||||
|
||||
fn estimate_gas(&self, _meta: Self::Metadata, req: CallRequest, num: Trailing<BlockNumber>) -> BoxFuture<RpcU256, Error> {
|
||||
// TODO: binary chop for more accurate estimates.
|
||||
self.fetcher().proved_execution(req, num).and_then(|res| {
|
||||
Box::new(self.fetcher().proved_execution(req, num).and_then(|res| {
|
||||
match res {
|
||||
Ok(exec) => Ok((exec.refunded + exec.gas_used).into()),
|
||||
Err(e) => Err(errors::execution(e)),
|
||||
}
|
||||
}).boxed()
|
||||
}))
|
||||
}
|
||||
|
||||
fn transaction_by_hash(&self, hash: RpcH256) -> Result<Option<Transaction>, Error> {
|
||||
fn transaction_by_hash(&self, _hash: RpcH256) -> Result<Option<Transaction>, Error> {
|
||||
Err(errors::unimplemented(None))
|
||||
}
|
||||
|
||||
fn transaction_by_block_hash_and_index(&self, hash: RpcH256, idx: Index) -> Result<Option<Transaction>, Error> {
|
||||
fn transaction_by_block_hash_and_index(&self, _hash: RpcH256, _idx: Index) -> Result<Option<Transaction>, Error> {
|
||||
Err(errors::unimplemented(None))
|
||||
}
|
||||
|
||||
fn transaction_by_block_number_and_index(&self, num: BlockNumber, idx: Index) -> Result<Option<Transaction>, Error> {
|
||||
fn transaction_by_block_number_and_index(&self, _num: BlockNumber, _idx: Index) -> Result<Option<Transaction>, Error> {
|
||||
Err(errors::unimplemented(None))
|
||||
}
|
||||
|
||||
fn transaction_receipt(&self, hash: RpcH256) -> Result<Option<Receipt>, Error> {
|
||||
fn transaction_receipt(&self, _hash: RpcH256) -> Result<Option<Receipt>, Error> {
|
||||
Err(errors::unimplemented(None))
|
||||
}
|
||||
|
||||
fn uncle_by_block_hash_and_index(&self, hash: RpcH256, idx: Index) -> Result<Option<RichBlock>, Error> {
|
||||
fn uncle_by_block_hash_and_index(&self, _hash: RpcH256, _idx: Index) -> Result<Option<RichBlock>, Error> {
|
||||
Err(errors::unimplemented(None))
|
||||
}
|
||||
|
||||
fn uncle_by_block_number_and_index(&self, num: BlockNumber, idx: Index) -> Result<Option<RichBlock>, Error> {
|
||||
fn uncle_by_block_number_and_index(&self, _num: BlockNumber, _idx: Index) -> Result<Option<RichBlock>, Error> {
|
||||
Err(errors::unimplemented(None))
|
||||
}
|
||||
|
||||
@@ -447,9 +437,8 @@ impl<T: LightChainClient + 'static> Eth for EthClient<T> {
|
||||
fn logs(&self, filter: Filter) -> BoxFuture<Vec<Log>, Error> {
|
||||
let limit = filter.limit;
|
||||
|
||||
Filterable::logs(self, filter.into())
|
||||
.map(move|logs| limit_logs(logs, limit))
|
||||
.boxed()
|
||||
Box::new(Filterable::logs(self, filter.into())
|
||||
.map(move|logs| limit_logs(logs, limit)))
|
||||
}
|
||||
|
||||
fn work(&self, _timeout: Trailing<u64>) -> Result<Work, Error> {
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
//! Parity-specific rpc implementation.
|
||||
use std::sync::Arc;
|
||||
use std::collections::{BTreeMap, HashSet};
|
||||
use futures::{future, Future, BoxFuture};
|
||||
|
||||
use util::misc::version_data;
|
||||
|
||||
@@ -31,7 +30,8 @@ use node_health::{NodeHealth, Health};
|
||||
|
||||
use light::client::LightChainClient;
|
||||
|
||||
use jsonrpc_core::Error;
|
||||
use jsonrpc_core::{BoxFuture, Error};
|
||||
use jsonrpc_core::futures::Future;
|
||||
use jsonrpc_macros::Trailing;
|
||||
use v1::helpers::{self, errors, ipfs, SigningQueue, SignerService, NetworkSettings};
|
||||
use v1::helpers::dispatch::LightDispatcher;
|
||||
@@ -140,15 +140,14 @@ impl Parity for ParityClient {
|
||||
Ok(store.locked_hardware_accounts().map_err(|e| errors::account("Error communicating with hardware wallet.", e))?)
|
||||
}
|
||||
|
||||
fn default_account(&self, meta: Self::Metadata) -> BoxFuture<H160, Error> {
|
||||
fn default_account(&self, meta: Self::Metadata) -> Result<H160, Error> {
|
||||
let dapp_id = meta.dapp_id();
|
||||
future::ok(self.accounts
|
||||
Ok(self.accounts
|
||||
.dapp_addresses(dapp_id.into())
|
||||
.ok()
|
||||
.and_then(|accounts| accounts.get(0).cloned())
|
||||
.map(|acc| acc.into())
|
||||
.unwrap_or_default()
|
||||
).boxed()
|
||||
.unwrap_or_default())
|
||||
}
|
||||
|
||||
fn transactions_limit(&self) -> Result<usize, Error> {
|
||||
@@ -221,10 +220,9 @@ impl Parity for ParityClient {
|
||||
}
|
||||
|
||||
fn gas_price_histogram(&self) -> BoxFuture<Histogram, Error> {
|
||||
self.light_dispatch.gas_price_corpus()
|
||||
Box::new(self.light_dispatch.gas_price_corpus()
|
||||
.and_then(|corpus| corpus.histogram(10).ok_or_else(errors::not_enough_data))
|
||||
.map(Into::into)
|
||||
.boxed()
|
||||
.map(Into::into))
|
||||
}
|
||||
|
||||
fn unsigned_transactions_count(&self) -> Result<usize, Error> {
|
||||
@@ -316,7 +314,7 @@ impl Parity for ParityClient {
|
||||
}
|
||||
|
||||
fn next_nonce(&self, address: H160) -> BoxFuture<U256, Error> {
|
||||
self.light_dispatch.next_nonce(address.into()).map(Into::into).boxed()
|
||||
Box::new(self.light_dispatch.next_nonce(address.into()).map(Into::into))
|
||||
}
|
||||
|
||||
fn mode(&self) -> Result<String, Error> {
|
||||
@@ -398,20 +396,19 @@ impl Parity for ParityClient {
|
||||
}
|
||||
};
|
||||
|
||||
self.fetcher().header(number.unwrap_or_default().into()).map(from_encoded).boxed()
|
||||
Box::new(self.fetcher().header(number.unwrap_or_default().into()).map(from_encoded))
|
||||
}
|
||||
|
||||
fn ipfs_cid(&self, content: Bytes) -> Result<String, Error> {
|
||||
ipfs::cid(content)
|
||||
}
|
||||
|
||||
fn call(&self, _meta: Self::Metadata, _requests: Vec<CallRequest>, _block: Trailing<BlockNumber>) -> BoxFuture<Vec<Bytes>, Error> {
|
||||
future::err(errors::light_unimplemented(None)).boxed()
|
||||
fn call(&self, _meta: Self::Metadata, _requests: Vec<CallRequest>, _block: Trailing<BlockNumber>) -> Result<Vec<Bytes>, Error> {
|
||||
Err(errors::light_unimplemented(None))
|
||||
}
|
||||
|
||||
fn node_health(&self) -> BoxFuture<Health, Error> {
|
||||
self.health.health()
|
||||
.map_err(|err| errors::internal("Health API failure.", err))
|
||||
.boxed()
|
||||
Box::new(self.health.health()
|
||||
.map_err(|err| errors::internal("Health API failure.", err)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,10 +22,10 @@ use std::sync::Arc;
|
||||
|
||||
use ethsync::ManageNetwork;
|
||||
use fetch::Fetch;
|
||||
use futures::{BoxFuture, Future};
|
||||
use hash::keccak_buffer;
|
||||
|
||||
use jsonrpc_core::Error;
|
||||
use jsonrpc_core::{BoxFuture, Error};
|
||||
use jsonrpc_core::futures::Future;
|
||||
use v1::helpers::dapps::DappsService;
|
||||
use v1::helpers::errors;
|
||||
use v1::traits::ParitySet;
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
//! Traces api implementation.
|
||||
|
||||
use jsonrpc_core::Error;
|
||||
use jsonrpc_core::futures::{future, Future, BoxFuture};
|
||||
use jsonrpc_macros::Trailing;
|
||||
use v1::Metadata;
|
||||
use v1::traits::Traces;
|
||||
@@ -47,12 +46,12 @@ impl Traces for TracesClient {
|
||||
Err(errors::light_unimplemented(None))
|
||||
}
|
||||
|
||||
fn call(&self, _meta: Self::Metadata, _request: CallRequest, _flags: TraceOptions, _block: Trailing<BlockNumber>) -> BoxFuture<TraceResults, Error> {
|
||||
future::err(errors::light_unimplemented(None)).boxed()
|
||||
fn call(&self, _meta: Self::Metadata, _request: CallRequest, _flags: TraceOptions, _block: Trailing<BlockNumber>) -> Result<TraceResults, Error> {
|
||||
Err(errors::light_unimplemented(None))
|
||||
}
|
||||
|
||||
fn call_many(&self, _meta: Self::Metadata, _request: Vec<(CallRequest, TraceOptions)>, _block: Trailing<BlockNumber>) -> BoxFuture<Vec<TraceResults>, Error> {
|
||||
future::err(errors::light_unimplemented(None)).boxed()
|
||||
fn call_many(&self, _meta: Self::Metadata, _request: Vec<(CallRequest, TraceOptions)>, _block: Trailing<BlockNumber>) -> Result<Vec<TraceResults>, Error> {
|
||||
Err(errors::light_unimplemented(None))
|
||||
}
|
||||
|
||||
fn raw_transaction(&self, _raw_transaction: Bytes, _flags: TraceOptions, _block: Trailing<BlockNumber>) -> Result<TraceResults, Error> {
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
use std::sync::Arc;
|
||||
use std::str::FromStr;
|
||||
use std::collections::{BTreeMap, HashSet};
|
||||
use futures::{future, Future, BoxFuture};
|
||||
|
||||
use util::Address;
|
||||
use util::misc::version_data;
|
||||
@@ -32,12 +31,12 @@ use ethcore::client::{MiningBlockChainClient};
|
||||
use ethcore::ids::BlockId;
|
||||
use ethcore::miner::MinerService;
|
||||
use ethcore::mode::Mode;
|
||||
use ethcore::transaction::SignedTransaction;
|
||||
use ethcore_logger::RotatingLogger;
|
||||
use node_health::{NodeHealth, Health};
|
||||
use updater::{Service as UpdateService};
|
||||
|
||||
use jsonrpc_core::Error;
|
||||
use jsonrpc_core::{BoxFuture, Error};
|
||||
use jsonrpc_core::futures::{future, Future};
|
||||
use jsonrpc_macros::Trailing;
|
||||
use v1::helpers::{self, errors, fake_sign, ipfs, SigningQueue, SignerService, NetworkSettings};
|
||||
use v1::helpers::accounts::unwrap_provider;
|
||||
@@ -157,15 +156,14 @@ impl<C, M, U> Parity for ParityClient<C, M, U> where
|
||||
Ok(store.locked_hardware_accounts().map_err(|e| errors::account("Error communicating with hardware wallet.", e))?)
|
||||
}
|
||||
|
||||
fn default_account(&self, meta: Self::Metadata) -> BoxFuture<H160, Error> {
|
||||
fn default_account(&self, meta: Self::Metadata) -> Result<H160, Error> {
|
||||
let dapp_id = meta.dapp_id();
|
||||
future::ok(
|
||||
try_bf!(self.account_provider())
|
||||
.dapp_default_address(dapp_id.into())
|
||||
.map(Into::into)
|
||||
.ok()
|
||||
.unwrap_or_default()
|
||||
).boxed()
|
||||
|
||||
Ok(self.account_provider()?
|
||||
.dapp_default_address(dapp_id.into())
|
||||
.map(Into::into)
|
||||
.ok()
|
||||
.unwrap_or_default())
|
||||
}
|
||||
|
||||
fn transactions_limit(&self) -> Result<usize, Error> {
|
||||
@@ -253,12 +251,12 @@ impl<C, M, U> Parity for ParityClient<C, M, U> where
|
||||
}
|
||||
|
||||
fn gas_price_histogram(&self) -> BoxFuture<Histogram, Error> {
|
||||
future::done(self.client
|
||||
Box::new(future::done(self.client
|
||||
.gas_price_corpus(100)
|
||||
.histogram(10)
|
||||
.ok_or_else(errors::not_enough_data)
|
||||
.map(Into::into)
|
||||
).boxed()
|
||||
))
|
||||
}
|
||||
|
||||
fn unsigned_transactions_count(&self) -> Result<usize, Error> {
|
||||
@@ -340,11 +338,11 @@ impl<C, M, U> Parity for ParityClient<C, M, U> where
|
||||
fn next_nonce(&self, address: H160) -> BoxFuture<U256, Error> {
|
||||
let address: Address = address.into();
|
||||
|
||||
future::ok(self.miner.last_nonce(&address)
|
||||
Box::new(future::ok(self.miner.last_nonce(&address)
|
||||
.map(|n| n + 1.into())
|
||||
.unwrap_or_else(|| self.client.latest_nonce(&address))
|
||||
.into()
|
||||
).boxed()
|
||||
))
|
||||
}
|
||||
|
||||
fn mode(&self) -> Result<String, Error> {
|
||||
@@ -403,41 +401,37 @@ impl<C, M, U> Parity for ParityClient<C, M, U> where
|
||||
let id: BlockId = number.unwrap_or_default().into();
|
||||
let encoded = match self.client.block_header(id.clone()) {
|
||||
Some(encoded) => encoded,
|
||||
None => return future::err(errors::unknown_block()).boxed(),
|
||||
None => return Box::new(future::err(errors::unknown_block())),
|
||||
};
|
||||
|
||||
future::ok(RichHeader {
|
||||
Box::new(future::ok(RichHeader {
|
||||
inner: encoded.into(),
|
||||
extra_info: self.client.block_extra_info(id).expect(EXTRA_INFO_PROOF),
|
||||
}).boxed()
|
||||
}))
|
||||
}
|
||||
|
||||
fn ipfs_cid(&self, content: Bytes) -> Result<String, Error> {
|
||||
ipfs::cid(content)
|
||||
}
|
||||
|
||||
fn call(&self, meta: Self::Metadata, requests: Vec<CallRequest>, block: Trailing<BlockNumber>) -> BoxFuture<Vec<Bytes>, Error> {
|
||||
let requests: Result<Vec<(SignedTransaction, _)>, Error> = requests
|
||||
fn call(&self, meta: Self::Metadata, requests: Vec<CallRequest>, block: Trailing<BlockNumber>) -> Result<Vec<Bytes>, Error> {
|
||||
let requests = requests
|
||||
.into_iter()
|
||||
.map(|request| Ok((
|
||||
fake_sign::sign_call(&self.client, &self.miner, request.into(), meta.is_dapp())?,
|
||||
Default::default()
|
||||
)))
|
||||
.collect();
|
||||
.collect::<Result<Vec<_>, Error>>()?;
|
||||
|
||||
let block = block.unwrap_or_default();
|
||||
let requests = try_bf!(requests);
|
||||
|
||||
let result = self.client.call_many(&requests, block.into())
|
||||
self.client.call_many(&requests, block.into())
|
||||
.map(|res| res.into_iter().map(|res| res.output.into()).collect())
|
||||
.map_err(errors::call);
|
||||
|
||||
future::done(result).boxed()
|
||||
.map_err(errors::call)
|
||||
}
|
||||
|
||||
fn node_health(&self) -> BoxFuture<Health, Error> {
|
||||
self.health.health()
|
||||
.map_err(|err| errors::internal("Health API failure.", err))
|
||||
.boxed()
|
||||
Box::new(self.health.health()
|
||||
.map_err(|err| errors::internal("Health API failure.", err)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ impl ParityAccounts for ParityAccountsClient {
|
||||
|
||||
for (address, account) in account_iter {
|
||||
match accounts.entry(address) {
|
||||
/// Insert only if occupied entry isn't already an account with UUID
|
||||
// Insert only if occupied entry isn't already an account with UUID
|
||||
Entry::Occupied(ref mut occupied) if occupied.get().uuid.is_none() => {
|
||||
occupied.insert(account);
|
||||
},
|
||||
|
||||
@@ -23,11 +23,11 @@ use ethcore::client::MiningBlockChainClient;
|
||||
use ethcore::mode::Mode;
|
||||
use ethsync::ManageNetwork;
|
||||
use fetch::{self, Fetch};
|
||||
use futures::{BoxFuture, Future};
|
||||
use hash::keccak_buffer;
|
||||
use updater::{Service as UpdateService};
|
||||
|
||||
use jsonrpc_core::Error;
|
||||
use jsonrpc_core::{BoxFuture, Error};
|
||||
use jsonrpc_core::futures::Future;
|
||||
use v1::helpers::dapps::DappsService;
|
||||
use v1::helpers::errors;
|
||||
use v1::traits::ParitySet;
|
||||
|
||||
@@ -24,8 +24,8 @@ use bigint::prelude::U128;
|
||||
use util::Address;
|
||||
use bytes::ToPretty;
|
||||
|
||||
use futures::{future, Future, BoxFuture};
|
||||
use jsonrpc_core::Error;
|
||||
use jsonrpc_core::{BoxFuture, Error};
|
||||
use jsonrpc_core::futures::{future, Future};
|
||||
use v1::helpers::errors;
|
||||
use v1::helpers::dispatch::{Dispatcher, SignWith};
|
||||
use v1::helpers::accounts::unwrap_provider;
|
||||
@@ -114,10 +114,10 @@ impl<D: Dispatcher + 'static> Personal for PersonalClient<D> {
|
||||
|
||||
let default = match default {
|
||||
Ok(default) => default,
|
||||
Err(e) => return future::err(e).boxed(),
|
||||
Err(e) => return Box::new(future::err(e)),
|
||||
};
|
||||
|
||||
dispatcher.fill_optional_fields(request.into(), default, false)
|
||||
Box::new(dispatcher.fill_optional_fields(request.into(), default, false)
|
||||
.and_then(move |filled| {
|
||||
let condition = filled.condition.clone().map(Into::into);
|
||||
dispatcher.sign(accounts, filled, SignWith::Password(password))
|
||||
@@ -131,8 +131,7 @@ impl<D: Dispatcher + 'static> Personal for PersonalClient<D> {
|
||||
::rlp::encode(&*pending_tx).into_vec().pretty(), chain_id);
|
||||
|
||||
dispatcher.dispatch_transaction(pending_tx).map(Into::into)
|
||||
})
|
||||
.boxed()
|
||||
}))
|
||||
}
|
||||
|
||||
fn sign_and_send_transaction(&self, meta: Metadata, request: TransactionRequest, password: String) -> BoxFuture<RpcH256, Error> {
|
||||
|
||||
@@ -20,8 +20,8 @@ use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use parking_lot::RwLock;
|
||||
|
||||
use futures::{self, BoxFuture, Future, Stream, Sink};
|
||||
use jsonrpc_core::{self as core, Error, MetaIoHandler};
|
||||
use jsonrpc_core::futures::{Future, Stream, Sink};
|
||||
use jsonrpc_macros::Trailing;
|
||||
use jsonrpc_macros::pubsub::Subscriber;
|
||||
use jsonrpc_pubsub::SubscriptionId;
|
||||
@@ -94,8 +94,8 @@ impl<S: core::Middleware<Metadata>> PubSub for PubSubClient<S> {
|
||||
}
|
||||
}
|
||||
|
||||
fn parity_unsubscribe(&self, id: SubscriptionId) -> BoxFuture<bool, Error> {
|
||||
fn parity_unsubscribe(&self, id: SubscriptionId) -> Result<bool, Error> {
|
||||
let res = self.poll_manager.write().unsubscribe(&id);
|
||||
futures::future::ok(res).boxed()
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,12 +21,13 @@ use std::sync::Arc;
|
||||
use ethcore::account_provider::AccountProvider;
|
||||
use ethcore::transaction::{SignedTransaction, PendingTransaction};
|
||||
use ethkey;
|
||||
use futures::{future, BoxFuture, Future, IntoFuture};
|
||||
use parity_reactor::Remote;
|
||||
use rlp::UntrustedRlp;
|
||||
use parking_lot::Mutex;
|
||||
|
||||
use jsonrpc_core::{futures, Error};
|
||||
use jsonrpc_core::{Error, BoxFuture};
|
||||
use jsonrpc_core::futures::{future, Future, IntoFuture};
|
||||
use jsonrpc_core::futures::future::Either;
|
||||
use jsonrpc_pubsub::SubscriptionId;
|
||||
use jsonrpc_macros::pubsub::{Sink, Subscriber};
|
||||
use v1::helpers::accounts::unwrap_provider;
|
||||
@@ -87,18 +88,11 @@ impl<D: Dispatcher + 'static> SignerClient<D> {
|
||||
T::Future: Send + 'static
|
||||
{
|
||||
let id = id.into();
|
||||
let accounts = try_bf!(self.account_provider());
|
||||
let dispatcher = self.dispatcher.clone();
|
||||
let signer = self.signer.clone();
|
||||
|
||||
let setup = || {
|
||||
Ok((self.account_provider()?, self.signer.clone()))
|
||||
};
|
||||
|
||||
let (accounts, signer) = match setup() {
|
||||
Ok(x) => x,
|
||||
Err(e) => return future::err(e).boxed(),
|
||||
};
|
||||
|
||||
signer.peek(&id).map(|confirmation| {
|
||||
Box::new(signer.peek(&id).map(|confirmation| {
|
||||
let mut payload = confirmation.payload.clone();
|
||||
// Modify payload
|
||||
if let ConfirmationPayload::SendTransaction(ref mut request) = payload {
|
||||
@@ -118,16 +112,16 @@ impl<D: Dispatcher + 'static> SignerClient<D> {
|
||||
}
|
||||
}
|
||||
let fut = f(dispatcher, accounts, payload);
|
||||
fut.into_future().then(move |result| {
|
||||
Either::A(fut.into_future().then(move |result| {
|
||||
// Execute
|
||||
if let Ok(ref response) = result {
|
||||
signer.request_confirmed(id, Ok((*response).clone()));
|
||||
}
|
||||
|
||||
result
|
||||
}).boxed()
|
||||
}))
|
||||
})
|
||||
.unwrap_or_else(|| future::err(errors::invalid_params("Unknown RequestID", id)).boxed())
|
||||
.unwrap_or_else(|| Either::B(future::err(errors::invalid_params("Unknown RequestID", id)))))
|
||||
}
|
||||
|
||||
fn verify_transaction<F>(bytes: Bytes, request: FilledTransactionRequest, process: F) -> Result<ConfirmationResponse, Error> where
|
||||
@@ -178,15 +172,15 @@ impl<D: Dispatcher + 'static> Signer for SignerClient<D> {
|
||||
fn confirm_request(&self, id: U256, modification: TransactionModification, pass: String)
|
||||
-> BoxFuture<ConfirmationResponse, Error>
|
||||
{
|
||||
self.confirm_internal(id, modification, move |dis, accounts, payload| {
|
||||
Box::new(self.confirm_internal(id, modification, move |dis, accounts, payload| {
|
||||
dispatch::execute(dis, accounts, payload, dispatch::SignWith::Password(pass))
|
||||
}).map(|v| v.into_value()).boxed()
|
||||
}).map(|v| v.into_value()))
|
||||
}
|
||||
|
||||
fn confirm_request_with_token(&self, id: U256, modification: TransactionModification, token: String)
|
||||
-> BoxFuture<ConfirmationResponseWithToken, Error>
|
||||
{
|
||||
self.confirm_internal(id, modification, move |dis, accounts, payload| {
|
||||
Box::new(self.confirm_internal(id, modification, move |dis, accounts, payload| {
|
||||
dispatch::execute(dis, accounts, payload, dispatch::SignWith::Token(token))
|
||||
}).and_then(|v| match v {
|
||||
WithToken::No(_) => Err(errors::internal("Unexpected response without token.", "")),
|
||||
@@ -194,7 +188,7 @@ impl<D: Dispatcher + 'static> Signer for SignerClient<D> {
|
||||
result: response,
|
||||
token: token,
|
||||
}),
|
||||
}).boxed()
|
||||
}))
|
||||
}
|
||||
|
||||
fn confirm_request_raw(&self, id: U256, bytes: Bytes) -> Result<ConfirmationResponse, Error> {
|
||||
@@ -253,8 +247,8 @@ impl<D: Dispatcher + 'static> Signer for SignerClient<D> {
|
||||
self.subscribers.lock().push(sub)
|
||||
}
|
||||
|
||||
fn unsubscribe_pending(&self, id: SubscriptionId) -> BoxFuture<bool, Error> {
|
||||
fn unsubscribe_pending(&self, id: SubscriptionId) -> Result<bool, Error> {
|
||||
let res = self.subscribers.lock().remove(&id).is_some();
|
||||
futures::future::ok(res).boxed()
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,9 @@ use parking_lot::Mutex;
|
||||
|
||||
use ethcore::account_provider::AccountProvider;
|
||||
|
||||
use futures::{future, BoxFuture, Future};
|
||||
use jsonrpc_core::Error;
|
||||
use jsonrpc_core::{BoxFuture, Error};
|
||||
use jsonrpc_core::futures::{future, Future};
|
||||
use jsonrpc_core::futures::future::Either;
|
||||
use v1::helpers::{
|
||||
errors, oneshot,
|
||||
DefaultAccount,
|
||||
@@ -115,23 +116,21 @@ impl<D: Dispatcher + 'static> SigningQueueClient<D> {
|
||||
|
||||
let dispatcher = self.dispatcher.clone();
|
||||
let signer = self.signer.clone();
|
||||
dispatch::from_rpc(payload, default_account, &dispatcher)
|
||||
Box::new(dispatch::from_rpc(payload, default_account, &dispatcher)
|
||||
.and_then(move |payload| {
|
||||
let sender = payload.sender();
|
||||
if accounts.is_unlocked(sender) {
|
||||
dispatch::execute(dispatcher, accounts, payload, dispatch::SignWith::Nothing)
|
||||
Either::A(dispatch::execute(dispatcher, accounts, payload, dispatch::SignWith::Nothing)
|
||||
.map(|v| v.into_value())
|
||||
.map(DispatchResult::Value)
|
||||
.boxed()
|
||||
.map(DispatchResult::Value))
|
||||
} else {
|
||||
future::done(
|
||||
Either::B(future::done(
|
||||
signer.add_request(payload, origin)
|
||||
.map(DispatchResult::Promise)
|
||||
.map_err(|_| errors::request_rejected_limit())
|
||||
).boxed()
|
||||
))
|
||||
}
|
||||
})
|
||||
.boxed()
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,12 +140,12 @@ impl<D: Dispatcher + 'static> ParitySigning for SigningQueueClient<D> {
|
||||
fn compose_transaction(&self, meta: Metadata, transaction: RpcTransactionRequest) -> BoxFuture<RpcTransactionRequest, Error> {
|
||||
let accounts = try_bf!(self.account_provider());
|
||||
let default_account = accounts.dapp_default_address(meta.dapp_id().into()).ok().unwrap_or_default();
|
||||
self.dispatcher.fill_optional_fields(transaction.into(), default_account, true).map(Into::into).boxed()
|
||||
Box::new(self.dispatcher.fill_optional_fields(transaction.into(), default_account, true).map(Into::into))
|
||||
}
|
||||
|
||||
fn post_sign(&self, meta: Metadata, address: RpcH160, data: RpcBytes) -> BoxFuture<RpcEither<RpcU256, RpcConfirmationResponse>, Error> {
|
||||
let pending = self.pending.clone();
|
||||
self.dispatch(
|
||||
Box::new(self.dispatch(
|
||||
RpcConfirmationPayload::EthSignMessage((address.clone(), data).into()),
|
||||
DefaultAccount::Provided(address.into()),
|
||||
meta.origin
|
||||
@@ -160,13 +159,12 @@ impl<D: Dispatcher + 'static> ParitySigning for SigningQueueClient<D> {
|
||||
|
||||
RpcEither::Either(id.into())
|
||||
},
|
||||
})
|
||||
.boxed()
|
||||
}))
|
||||
}
|
||||
|
||||
fn post_transaction(&self, meta: Metadata, request: RpcTransactionRequest) -> BoxFuture<RpcEither<RpcU256, RpcConfirmationResponse>, Error> {
|
||||
let pending = self.pending.clone();
|
||||
self.dispatch(RpcConfirmationPayload::SendTransaction(request), meta.dapp_id().into(), meta.origin)
|
||||
Box::new(self.dispatch(RpcConfirmationPayload::SendTransaction(request), meta.dapp_id().into(), meta.origin)
|
||||
.map(move |result| match result {
|
||||
DispatchResult::Value(v) => RpcEither::Or(v),
|
||||
DispatchResult::Promise(promise) => {
|
||||
@@ -177,8 +175,7 @@ impl<D: Dispatcher + 'static> ParitySigning for SigningQueueClient<D> {
|
||||
|
||||
RpcEither::Either(id.into())
|
||||
},
|
||||
})
|
||||
.boxed()
|
||||
}))
|
||||
}
|
||||
|
||||
fn check_request(&self, id: RpcU256) -> Result<Option<RpcConfirmationResponse>, Error> {
|
||||
@@ -203,7 +200,7 @@ impl<D: Dispatcher + 'static> ParitySigning for SigningQueueClient<D> {
|
||||
let (ready, p) = oneshot::oneshot();
|
||||
|
||||
// when dispatch is complete
|
||||
res.then(move |res| {
|
||||
Box::new(res.then(move |res| {
|
||||
// register callback via the oneshot sender.
|
||||
handle_dispatch(res, move |response| {
|
||||
match response {
|
||||
@@ -214,7 +211,7 @@ impl<D: Dispatcher + 'static> ParitySigning for SigningQueueClient<D> {
|
||||
});
|
||||
|
||||
p
|
||||
}).boxed()
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,7 +227,7 @@ impl<D: Dispatcher + 'static> EthSigning for SigningQueueClient<D> {
|
||||
|
||||
let (ready, p) = oneshot::oneshot();
|
||||
|
||||
res.then(move |res| {
|
||||
Box::new(res.then(move |res| {
|
||||
handle_dispatch(res, move |response| {
|
||||
match response {
|
||||
Ok(RpcConfirmationResponse::Signature(sig)) => ready.send(Ok(sig)),
|
||||
@@ -240,7 +237,7 @@ impl<D: Dispatcher + 'static> EthSigning for SigningQueueClient<D> {
|
||||
});
|
||||
|
||||
p
|
||||
}).boxed()
|
||||
}))
|
||||
}
|
||||
|
||||
fn send_transaction(&self, meta: Metadata, request: RpcTransactionRequest) -> BoxFuture<RpcH256, Error> {
|
||||
@@ -252,7 +249,7 @@ impl<D: Dispatcher + 'static> EthSigning for SigningQueueClient<D> {
|
||||
|
||||
let (ready, p) = oneshot::oneshot();
|
||||
|
||||
res.then(move |res| {
|
||||
Box::new(res.then(move |res| {
|
||||
handle_dispatch(res, move |response| {
|
||||
match response {
|
||||
Ok(RpcConfirmationResponse::SendTransaction(hash)) => ready.send(Ok(hash)),
|
||||
@@ -262,7 +259,7 @@ impl<D: Dispatcher + 'static> EthSigning for SigningQueueClient<D> {
|
||||
});
|
||||
|
||||
p
|
||||
}).boxed()
|
||||
}))
|
||||
}
|
||||
|
||||
fn sign_transaction(&self, meta: Metadata, request: RpcTransactionRequest) -> BoxFuture<RpcRichRawTransaction, Error> {
|
||||
@@ -274,7 +271,7 @@ impl<D: Dispatcher + 'static> EthSigning for SigningQueueClient<D> {
|
||||
|
||||
let (ready, p) = oneshot::oneshot();
|
||||
|
||||
res.then(move |res| {
|
||||
Box::new(res.then(move |res| {
|
||||
handle_dispatch(res, move |response| {
|
||||
match response {
|
||||
Ok(RpcConfirmationResponse::SignTransaction(tx)) => ready.send(Ok(tx)),
|
||||
@@ -284,6 +281,6 @@ impl<D: Dispatcher + 'static> EthSigning for SigningQueueClient<D> {
|
||||
});
|
||||
|
||||
p
|
||||
}).boxed()
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ use std::sync::Arc;
|
||||
|
||||
use ethcore::account_provider::AccountProvider;
|
||||
|
||||
use futures::{future, BoxFuture, Future};
|
||||
use jsonrpc_core::Error;
|
||||
use jsonrpc_core::{BoxFuture, Error};
|
||||
use jsonrpc_core::futures::{future, Future};
|
||||
use v1::helpers::{errors, DefaultAccount};
|
||||
use v1::helpers::dispatch::{self, Dispatcher};
|
||||
use v1::helpers::accounts::unwrap_provider;
|
||||
@@ -64,12 +64,11 @@ impl<D: Dispatcher + 'static> SigningUnsafeClient<D> {
|
||||
};
|
||||
|
||||
let dis = self.dispatcher.clone();
|
||||
dispatch::from_rpc(payload, default, &dis)
|
||||
Box::new(dispatch::from_rpc(payload, default, &dis)
|
||||
.and_then(move |payload| {
|
||||
dispatch::execute(dis, accounts, payload, dispatch::SignWith::Nothing)
|
||||
})
|
||||
.map(|v| v.into_value())
|
||||
.boxed()
|
||||
.map(|v| v.into_value()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,33 +77,30 @@ impl<D: Dispatcher + 'static> EthSigning for SigningUnsafeClient<D>
|
||||
type Metadata = Metadata;
|
||||
|
||||
fn sign(&self, _: Metadata, address: RpcH160, data: RpcBytes) -> BoxFuture<RpcH520, Error> {
|
||||
self.handle(RpcConfirmationPayload::EthSignMessage((address.clone(), data).into()), address.into())
|
||||
Box::new(self.handle(RpcConfirmationPayload::EthSignMessage((address.clone(), data).into()), address.into())
|
||||
.then(|res| match res {
|
||||
Ok(RpcConfirmationResponse::Signature(signature)) => Ok(signature),
|
||||
Err(e) => Err(e),
|
||||
e => Err(errors::internal("Unexpected result", e)),
|
||||
})
|
||||
.boxed()
|
||||
}))
|
||||
}
|
||||
|
||||
fn send_transaction(&self, meta: Metadata, request: RpcTransactionRequest) -> BoxFuture<RpcH256, Error> {
|
||||
self.handle(RpcConfirmationPayload::SendTransaction(request), meta.dapp_id().into())
|
||||
Box::new(self.handle(RpcConfirmationPayload::SendTransaction(request), meta.dapp_id().into())
|
||||
.then(|res| match res {
|
||||
Ok(RpcConfirmationResponse::SendTransaction(hash)) => Ok(hash),
|
||||
Err(e) => Err(e),
|
||||
e => Err(errors::internal("Unexpected result", e)),
|
||||
})
|
||||
.boxed()
|
||||
}))
|
||||
}
|
||||
|
||||
fn sign_transaction(&self, meta: Metadata, request: RpcTransactionRequest) -> BoxFuture<RpcRichRawTransaction, Error> {
|
||||
self.handle(RpcConfirmationPayload::SignTransaction(request), meta.dapp_id().into())
|
||||
Box::new(self.handle(RpcConfirmationPayload::SignTransaction(request), meta.dapp_id().into())
|
||||
.then(|res| match res {
|
||||
Ok(RpcConfirmationResponse::SignTransaction(tx)) => Ok(tx),
|
||||
Err(e) => Err(e),
|
||||
e => Err(errors::internal("Unexpected result", e)),
|
||||
})
|
||||
.boxed()
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,27 +110,26 @@ impl<D: Dispatcher + 'static> ParitySigning for SigningUnsafeClient<D> {
|
||||
fn compose_transaction(&self, meta: Metadata, transaction: RpcTransactionRequest) -> BoxFuture<RpcTransactionRequest, Error> {
|
||||
let accounts = try_bf!(self.account_provider());
|
||||
let default_account = accounts.dapp_default_address(meta.dapp_id().into()).ok().unwrap_or_default();
|
||||
self.dispatcher.fill_optional_fields(transaction.into(), default_account, true).map(Into::into).boxed()
|
||||
Box::new(self.dispatcher.fill_optional_fields(transaction.into(), default_account, true).map(Into::into))
|
||||
}
|
||||
|
||||
fn decrypt_message(&self, _: Metadata, address: RpcH160, data: RpcBytes) -> BoxFuture<RpcBytes, Error> {
|
||||
self.handle(RpcConfirmationPayload::Decrypt((address.clone(), data).into()), address.into())
|
||||
Box::new(self.handle(RpcConfirmationPayload::Decrypt((address.clone(), data).into()), address.into())
|
||||
.then(|res| match res {
|
||||
Ok(RpcConfirmationResponse::Decrypt(data)) => Ok(data),
|
||||
Err(e) => Err(e),
|
||||
e => Err(errors::internal("Unexpected result", e)),
|
||||
})
|
||||
.boxed()
|
||||
}))
|
||||
}
|
||||
|
||||
fn post_sign(&self, _: Metadata, _: RpcH160, _: RpcBytes) -> BoxFuture<RpcEither<RpcU256, RpcConfirmationResponse>, Error> {
|
||||
// We don't support this in non-signer mode.
|
||||
future::err(errors::signer_disabled()).boxed()
|
||||
Box::new(future::err(errors::signer_disabled()))
|
||||
}
|
||||
|
||||
fn post_transaction(&self, _: Metadata, _: RpcTransactionRequest) -> BoxFuture<RpcEither<RpcU256, RpcConfirmationResponse>, Error> {
|
||||
// We don't support this in non-signer mode.
|
||||
future::err((errors::signer_disabled())).boxed()
|
||||
Box::new(future::err((errors::signer_disabled())))
|
||||
}
|
||||
|
||||
fn check_request(&self, _: RpcU256) -> Result<Option<RpcConfirmationResponse>, Error> {
|
||||
|
||||
@@ -24,7 +24,6 @@ use ethcore::transaction::SignedTransaction;
|
||||
use rlp::UntrustedRlp;
|
||||
|
||||
use jsonrpc_core::Error;
|
||||
use jsonrpc_core::futures::{self, Future, BoxFuture};
|
||||
use jsonrpc_macros::Trailing;
|
||||
use v1::Metadata;
|
||||
use v1::traits::Traces;
|
||||
@@ -83,35 +82,31 @@ impl<C, M> Traces for TracesClient<C, M> where C: MiningBlockChainClient + 'stat
|
||||
.map(LocalizedTrace::from))
|
||||
}
|
||||
|
||||
fn call(&self, meta: Self::Metadata, request: CallRequest, flags: TraceOptions, block: Trailing<BlockNumber>) -> BoxFuture<TraceResults, Error> {
|
||||
fn call(&self, meta: Self::Metadata, request: CallRequest, flags: TraceOptions, block: Trailing<BlockNumber>) -> Result<TraceResults, Error> {
|
||||
let block = block.unwrap_or_default();
|
||||
|
||||
let request = CallRequest::into(request);
|
||||
let signed = try_bf!(fake_sign::sign_call(&self.client, &self.miner, request, meta.is_dapp()));
|
||||
let signed = fake_sign::sign_call(&self.client, &self.miner, request, meta.is_dapp())?;
|
||||
|
||||
let res = self.client.call(&signed, to_call_analytics(flags), block.into())
|
||||
self.client.call(&signed, to_call_analytics(flags), block.into())
|
||||
.map(TraceResults::from)
|
||||
.map_err(errors::call);
|
||||
|
||||
futures::done(res).boxed()
|
||||
.map_err(errors::call)
|
||||
}
|
||||
|
||||
fn call_many(&self, meta: Self::Metadata, requests: Vec<(CallRequest, TraceOptions)>, block: Trailing<BlockNumber>) -> BoxFuture<Vec<TraceResults>, Error> {
|
||||
fn call_many(&self, meta: Self::Metadata, requests: Vec<(CallRequest, TraceOptions)>, block: Trailing<BlockNumber>) -> Result<Vec<TraceResults>, Error> {
|
||||
let block = block.unwrap_or_default();
|
||||
|
||||
let requests = try_bf!(requests.into_iter()
|
||||
let requests = requests.into_iter()
|
||||
.map(|(request, flags)| {
|
||||
let request = CallRequest::into(request);
|
||||
let signed = fake_sign::sign_call(&self.client, &self.miner, request, meta.is_dapp())?;
|
||||
Ok((signed, to_call_analytics(flags)))
|
||||
})
|
||||
.collect::<Result<Vec<_>, Error>>());
|
||||
.collect::<Result<Vec<_>, Error>>()?;
|
||||
|
||||
let res = self.client.call_many(&requests, block.into())
|
||||
self.client.call_many(&requests, block.into())
|
||||
.map(|results| results.into_iter().map(TraceResults::from).collect())
|
||||
.map_err(errors::call);
|
||||
|
||||
futures::done(res).boxed()
|
||||
.map_err(errors::call)
|
||||
}
|
||||
|
||||
fn raw_transaction(&self, raw_transaction: Bytes, flags: TraceOptions, block: Trailing<BlockNumber>) -> Result<TraceResults, Error> {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
//! Web3 rpc implementation.
|
||||
use hash::keccak;
|
||||
use jsonrpc_core::*;
|
||||
use jsonrpc_core::Error;
|
||||
use util::version;
|
||||
use v1::traits::Web3;
|
||||
use v1::types::{H256, Bytes};
|
||||
|
||||
@@ -20,7 +20,6 @@ use std::fmt;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{self, AtomicUsize};
|
||||
use std::time;
|
||||
use futures::Future;
|
||||
use futures_cpupool as pool;
|
||||
use jsonrpc_core as rpc;
|
||||
use order_stat;
|
||||
@@ -222,15 +221,23 @@ impl<M: rpc::Metadata, T: ActivityNotifier> rpc::Middleware<M> for Middleware<T>
|
||||
self.notifier.active();
|
||||
self.stats.count_request();
|
||||
|
||||
let id = match request {
|
||||
rpc::Request::Single(rpc::Call::MethodCall(ref call)) => Some(call.id.clone()),
|
||||
_ => None,
|
||||
};
|
||||
let stats = self.stats.clone();
|
||||
let future = process(request, meta).map(move |res| {
|
||||
stats.add_roundtrip(Self::as_micro(start.elapsed()));
|
||||
let time = Self::as_micro(start.elapsed());
|
||||
if time > 10_000 {
|
||||
debug!(target: "rpc", "[{:?}] Took {}ms", id, time / 1_000);
|
||||
}
|
||||
stats.add_roundtrip(time);
|
||||
res
|
||||
});
|
||||
|
||||
match self.pool {
|
||||
Some(ref pool) => A(pool.spawn(future)),
|
||||
None => B(future.boxed()),
|
||||
None => B(Box::new(future)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ macro_rules! try_bf {
|
||||
($res: expr) => {
|
||||
match $res {
|
||||
Ok(val) => val,
|
||||
Err(e) => return ::futures::future::err(e.into()).boxed(),
|
||||
Err(e) => return Box::new(::jsonrpc_core::futures::future::err(e.into())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
//! Test implementation of fetch client.
|
||||
|
||||
use std::{io, thread};
|
||||
use futures::{self, Future};
|
||||
use jsonrpc_core::futures::{self, Future};
|
||||
use fetch::{self, Fetch};
|
||||
|
||||
/// Test implementation of fetcher. Will always return the same file.
|
||||
@@ -25,7 +25,7 @@ use fetch::{self, Fetch};
|
||||
pub struct TestFetch;
|
||||
|
||||
impl Fetch for TestFetch {
|
||||
type Result = futures::BoxFuture<fetch::Response, fetch::Error>;
|
||||
type Result = Box<Future<Item = fetch::Response, Error = fetch::Error> + Send + 'static>;
|
||||
|
||||
fn new() -> Result<Self, fetch::Error> where Self: Sized {
|
||||
Ok(TestFetch)
|
||||
@@ -38,6 +38,6 @@ impl Fetch for TestFetch {
|
||||
tx.send(fetch::Response::from_reader(cursor)).unwrap();
|
||||
});
|
||||
|
||||
rx.map_err(|_| fetch::Error::Aborted).boxed()
|
||||
Box::new(rx.map_err(|_| fetch::Error::Aborted))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ use std::time::Duration;
|
||||
use rlp;
|
||||
|
||||
use jsonrpc_core::{IoHandler, Success};
|
||||
use jsonrpc_core::futures::Future;
|
||||
use v1::impls::SigningQueueClient;
|
||||
use v1::metadata::Metadata;
|
||||
use v1::traits::{EthSigning, ParitySigning, Parity};
|
||||
@@ -36,7 +37,6 @@ use ethcore::account_provider::AccountProvider;
|
||||
use ethcore::client::TestBlockChainClient;
|
||||
use ethcore::transaction::{Transaction, Action, SignedTransaction};
|
||||
use ethstore::ethkey::{Generator, Random};
|
||||
use futures::Future;
|
||||
use serde_json;
|
||||
|
||||
struct SigningTester {
|
||||
|
||||
@@ -15,11 +15,9 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Eth rpc interface.
|
||||
use jsonrpc_core::Error;
|
||||
use jsonrpc_core::{BoxFuture, Error};
|
||||
use jsonrpc_macros::Trailing;
|
||||
|
||||
use futures::BoxFuture;
|
||||
|
||||
use v1::types::{RichBlock, BlockNumber, Bytes, CallRequest, Filter, FilterChanges, Index};
|
||||
use v1::types::{Log, Receipt, SyncStatus, Transaction, Work};
|
||||
use v1::types::{H64, H160, H256, U256};
|
||||
@@ -43,7 +41,7 @@ build_rpc_trait! {
|
||||
|
||||
/// Returns block author.
|
||||
#[rpc(meta, name = "eth_coinbase")]
|
||||
fn author(&self, Self::Metadata) -> BoxFuture<H160, Error>;
|
||||
fn author(&self, Self::Metadata) -> Result<H160, Error>;
|
||||
|
||||
/// Returns true if client is actively mining new blocks.
|
||||
#[rpc(name = "eth_mining")]
|
||||
@@ -55,50 +53,50 @@ build_rpc_trait! {
|
||||
|
||||
/// Returns accounts list.
|
||||
#[rpc(meta, name = "eth_accounts")]
|
||||
fn accounts(&self, Self::Metadata) -> BoxFuture<Vec<H160>, Error>;
|
||||
fn accounts(&self, Self::Metadata) -> Result<Vec<H160>, Error>;
|
||||
|
||||
/// Returns highest block number.
|
||||
#[rpc(name = "eth_blockNumber")]
|
||||
fn block_number(&self) -> Result<U256, Error>;
|
||||
|
||||
/// Returns balance of the given account.
|
||||
#[rpc(async, name = "eth_getBalance")]
|
||||
#[rpc(name = "eth_getBalance")]
|
||||
fn balance(&self, H160, Trailing<BlockNumber>) -> BoxFuture<U256, Error>;
|
||||
|
||||
/// Returns content of the storage at given address.
|
||||
#[rpc(async, name = "eth_getStorageAt")]
|
||||
#[rpc(name = "eth_getStorageAt")]
|
||||
fn storage_at(&self, H160, U256, Trailing<BlockNumber>) -> BoxFuture<H256, Error>;
|
||||
|
||||
/// Returns block with given hash.
|
||||
#[rpc(async, name = "eth_getBlockByHash")]
|
||||
#[rpc(name = "eth_getBlockByHash")]
|
||||
fn block_by_hash(&self, H256, bool) -> BoxFuture<Option<RichBlock>, Error>;
|
||||
|
||||
/// Returns block with given number.
|
||||
#[rpc(async, name = "eth_getBlockByNumber")]
|
||||
#[rpc(name = "eth_getBlockByNumber")]
|
||||
fn block_by_number(&self, BlockNumber, bool) -> BoxFuture<Option<RichBlock>, Error>;
|
||||
|
||||
/// Returns the number of transactions sent from given address at given time (block number).
|
||||
#[rpc(async, name = "eth_getTransactionCount")]
|
||||
#[rpc(name = "eth_getTransactionCount")]
|
||||
fn transaction_count(&self, H160, Trailing<BlockNumber>) -> BoxFuture<U256, Error>;
|
||||
|
||||
/// Returns the number of transactions in a block with given hash.
|
||||
#[rpc(async, name = "eth_getBlockTransactionCountByHash")]
|
||||
#[rpc(name = "eth_getBlockTransactionCountByHash")]
|
||||
fn block_transaction_count_by_hash(&self, H256) -> BoxFuture<Option<U256>, Error>;
|
||||
|
||||
/// Returns the number of transactions in a block with given block number.
|
||||
#[rpc(async, name = "eth_getBlockTransactionCountByNumber")]
|
||||
#[rpc(name = "eth_getBlockTransactionCountByNumber")]
|
||||
fn block_transaction_count_by_number(&self, BlockNumber) -> BoxFuture<Option<U256>, Error>;
|
||||
|
||||
/// Returns the number of uncles in a block with given hash.
|
||||
#[rpc(async, name = "eth_getUncleCountByBlockHash")]
|
||||
#[rpc(name = "eth_getUncleCountByBlockHash")]
|
||||
fn block_uncles_count_by_hash(&self, H256) -> BoxFuture<Option<U256>, Error>;
|
||||
|
||||
/// Returns the number of uncles in a block with given block number.
|
||||
#[rpc(async, name = "eth_getUncleCountByBlockNumber")]
|
||||
#[rpc(name = "eth_getUncleCountByBlockNumber")]
|
||||
fn block_uncles_count_by_number(&self, BlockNumber) -> BoxFuture<Option<U256>, Error>;
|
||||
|
||||
/// Returns the code at given address at given time (block number).
|
||||
#[rpc(async, name = "eth_getCode")]
|
||||
#[rpc(name = "eth_getCode")]
|
||||
fn code_at(&self, H160, Trailing<BlockNumber>) -> BoxFuture<Bytes, Error>;
|
||||
|
||||
/// Sends signed transaction, returning its hash.
|
||||
@@ -162,7 +160,7 @@ build_rpc_trait! {
|
||||
fn compile_serpent(&self, String) -> Result<Bytes, Error>;
|
||||
|
||||
/// Returns logs matching given filter object.
|
||||
#[rpc(async, name = "eth_getLogs")]
|
||||
#[rpc(name = "eth_getLogs")]
|
||||
fn logs(&self, Filter) -> BoxFuture<Vec<Log>, Error>;
|
||||
|
||||
/// Returns the hash of the current block, the seedHash, and the boundary condition to be met.
|
||||
@@ -196,11 +194,11 @@ build_rpc_trait! {
|
||||
fn new_pending_transaction_filter(&self) -> Result<U256, Error>;
|
||||
|
||||
/// Returns filter changes since last poll.
|
||||
#[rpc(async, name = "eth_getFilterChanges")]
|
||||
#[rpc(name = "eth_getFilterChanges")]
|
||||
fn filter_changes(&self, Index) -> BoxFuture<FilterChanges, Error>;
|
||||
|
||||
/// Returns all logs matching given filter (in a range 'from' - 'to').
|
||||
#[rpc(async, name = "eth_getFilterLogs")]
|
||||
#[rpc(name = "eth_getFilterLogs")]
|
||||
fn filter_logs(&self, Index) -> BoxFuture<Vec<Log>, Error>;
|
||||
|
||||
/// Uninstalls filter.
|
||||
|
||||
@@ -20,7 +20,6 @@ use jsonrpc_core::Error;
|
||||
use jsonrpc_macros::Trailing;
|
||||
use jsonrpc_macros::pubsub::Subscriber;
|
||||
use jsonrpc_pubsub::SubscriptionId;
|
||||
use futures::BoxFuture;
|
||||
|
||||
use v1::types::pubsub;
|
||||
|
||||
@@ -36,7 +35,7 @@ build_rpc_trait! {
|
||||
|
||||
/// Unsubscribe from existing Eth subscription.
|
||||
#[rpc(name = "eth_unsubscribe")]
|
||||
fn unsubscribe(&self, SubscriptionId) -> BoxFuture<bool, Error>;
|
||||
fn unsubscribe(&self, SubscriptionId) -> Result<bool, Error>;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
//! Eth rpc interface.
|
||||
|
||||
use jsonrpc_core::Error;
|
||||
use futures::BoxFuture;
|
||||
use jsonrpc_core::{BoxFuture, Error};
|
||||
|
||||
use v1::types::{Bytes, H160, H256, H520, TransactionRequest, RichRawTransaction};
|
||||
|
||||
|
||||
@@ -18,9 +18,8 @@
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use jsonrpc_core::Error;
|
||||
use jsonrpc_core::{BoxFuture, Error};
|
||||
use jsonrpc_macros::Trailing;
|
||||
use futures::BoxFuture;
|
||||
|
||||
use node_health::Health;
|
||||
use v1::types::{
|
||||
@@ -51,7 +50,7 @@ build_rpc_trait! {
|
||||
|
||||
/// Returns default account for dapp.
|
||||
#[rpc(meta, name = "parity_defaultAccount")]
|
||||
fn default_account(&self, Self::Metadata) -> BoxFuture<H160, Error>;
|
||||
fn default_account(&self, Self::Metadata) -> Result<H160, Error>;
|
||||
|
||||
/// Returns current transactions limit.
|
||||
#[rpc(name = "parity_transactionsLimit")]
|
||||
@@ -106,7 +105,7 @@ build_rpc_trait! {
|
||||
fn default_extra_data(&self) -> Result<Bytes, Error>;
|
||||
|
||||
/// Returns distribution of gas price in latest blocks.
|
||||
#[rpc(async, name = "parity_gasPriceHistogram")]
|
||||
#[rpc(name = "parity_gasPriceHistogram")]
|
||||
fn gas_price_histogram(&self) -> BoxFuture<Histogram, Error>;
|
||||
|
||||
/// Returns number of unsigned transactions waiting in the signer queue (if signer enabled)
|
||||
@@ -165,7 +164,7 @@ build_rpc_trait! {
|
||||
fn ws_url(&self) -> Result<String, Error>;
|
||||
|
||||
/// Returns next nonce for particular sender. Should include all transactions in the queue.
|
||||
#[rpc(async, name = "parity_nextNonce")]
|
||||
#[rpc(name = "parity_nextNonce")]
|
||||
fn next_nonce(&self, H160) -> BoxFuture<U256, Error>;
|
||||
|
||||
/// Get the mode. Returns one of: "active", "passive", "dark", "offline".
|
||||
@@ -208,7 +207,7 @@ build_rpc_trait! {
|
||||
|
||||
/// Get block header.
|
||||
/// Same as `eth_getBlockByNumber` but without uncles and transactions.
|
||||
#[rpc(async, name = "parity_getBlockHeaderByNumber")]
|
||||
#[rpc(name = "parity_getBlockHeaderByNumber")]
|
||||
fn block_header(&self, Trailing<BlockNumber>) -> BoxFuture<RichHeader, Error>;
|
||||
|
||||
/// Get IPFS CIDv0 given protobuf encoded bytes.
|
||||
@@ -217,10 +216,10 @@ build_rpc_trait! {
|
||||
|
||||
/// Call contract, returning the output data.
|
||||
#[rpc(meta, name = "parity_call")]
|
||||
fn call(&self, Self::Metadata, Vec<CallRequest>, Trailing<BlockNumber>) -> BoxFuture<Vec<Bytes>, Error>;
|
||||
fn call(&self, Self::Metadata, Vec<CallRequest>, Trailing<BlockNumber>) -> Result<Vec<Bytes>, Error>;
|
||||
|
||||
/// Returns node's health report.
|
||||
#[rpc(async, name = "parity_nodeHealth")]
|
||||
#[rpc(name = "parity_nodeHealth")]
|
||||
fn node_health(&self) -> BoxFuture<Health, Error>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
//! Parity-specific rpc interface for operations altering the settings.
|
||||
|
||||
use jsonrpc_core::Error;
|
||||
use futures::BoxFuture;
|
||||
use jsonrpc_core::{BoxFuture, Error};
|
||||
|
||||
use v1::types::{Bytes, H160, H256, U256, ReleaseInfo, Transaction, LocalDapp};
|
||||
|
||||
@@ -93,7 +92,7 @@ build_rpc_trait! {
|
||||
fn set_spec_name(&self, String) -> Result<bool, Error>;
|
||||
|
||||
/// Hash a file content under given URL.
|
||||
#[rpc(async, name = "parity_hashContent")]
|
||||
#[rpc(name = "parity_hashContent")]
|
||||
fn hash_content(&self, String) -> BoxFuture<H256, Error>;
|
||||
|
||||
/// Returns true if refresh successful, error if unsuccessful or server is disabled.
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! ParitySigning rpc interface.
|
||||
use jsonrpc_core::Error;
|
||||
use futures::BoxFuture;
|
||||
use jsonrpc_core::{BoxFuture, Error};
|
||||
|
||||
use v1::types::{U256, H160, Bytes, ConfirmationResponse, TransactionRequest, Either};
|
||||
|
||||
|
||||
@@ -15,9 +15,7 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Personal rpc interface.
|
||||
use jsonrpc_core::Error;
|
||||
|
||||
use futures::BoxFuture;
|
||||
use jsonrpc_core::{BoxFuture, Error};
|
||||
|
||||
use v1::types::{U128, H160, H256, TransactionRequest};
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ use jsonrpc_core::{Error, Value, Params};
|
||||
use jsonrpc_pubsub::SubscriptionId;
|
||||
use jsonrpc_macros::Trailing;
|
||||
use jsonrpc_macros::pubsub::Subscriber;
|
||||
use futures::BoxFuture;
|
||||
|
||||
build_rpc_trait! {
|
||||
/// Parity-specific PUB-SUB rpc interface.
|
||||
@@ -34,7 +33,7 @@ build_rpc_trait! {
|
||||
|
||||
/// Unsubscribe from existing Parity subscription.
|
||||
#[rpc(name = "parity_unsubscribe")]
|
||||
fn parity_unsubscribe(&self, SubscriptionId) -> BoxFuture<bool, Error>;
|
||||
fn parity_unsubscribe(&self, SubscriptionId) -> Result<bool, Error>;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,10 +15,9 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Parity Signer-related rpc interface.
|
||||
use jsonrpc_core::Error;
|
||||
use jsonrpc_core::{BoxFuture, Error};
|
||||
use jsonrpc_pubsub::SubscriptionId;
|
||||
use jsonrpc_macros::pubsub::Subscriber;
|
||||
use futures::BoxFuture;
|
||||
|
||||
use v1::types::{U256, Bytes, TransactionModification, ConfirmationRequest, ConfirmationResponse, ConfirmationResponseWithToken};
|
||||
|
||||
@@ -32,11 +31,11 @@ build_rpc_trait! {
|
||||
fn requests_to_confirm(&self) -> Result<Vec<ConfirmationRequest>, Error>;
|
||||
|
||||
/// Confirm specific request.
|
||||
#[rpc(async, name = "signer_confirmRequest")]
|
||||
#[rpc(name = "signer_confirmRequest")]
|
||||
fn confirm_request(&self, U256, TransactionModification, String) -> BoxFuture<ConfirmationResponse, Error>;
|
||||
|
||||
/// Confirm specific request with token.
|
||||
#[rpc(async, name = "signer_confirmRequestWithToken")]
|
||||
#[rpc(name = "signer_confirmRequestWithToken")]
|
||||
fn confirm_request_with_token(&self, U256, TransactionModification, String) -> BoxFuture<ConfirmationResponseWithToken, Error>;
|
||||
|
||||
/// Confirm specific request with already signed data.
|
||||
@@ -62,7 +61,7 @@ build_rpc_trait! {
|
||||
|
||||
/// Unsubscribe from pending requests subscription.
|
||||
#[rpc(name = "signer_unsubscribePending")]
|
||||
fn unsubscribe_pending(&self, SubscriptionId) -> BoxFuture<bool, Error>;
|
||||
fn unsubscribe_pending(&self, SubscriptionId) -> Result<bool, Error>;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
//! Traces specific rpc interface.
|
||||
|
||||
use jsonrpc_core::Error;
|
||||
use jsonrpc_core::futures::BoxFuture;
|
||||
use jsonrpc_macros::Trailing;
|
||||
use v1::types::{TraceFilter, LocalizedTrace, BlockNumber, Index, CallRequest, Bytes, TraceResults, H256, TraceOptions};
|
||||
|
||||
@@ -44,11 +43,11 @@ build_rpc_trait! {
|
||||
|
||||
/// Executes the given call and returns a number of possible traces for it.
|
||||
#[rpc(meta, name = "trace_call")]
|
||||
fn call(&self, Self::Metadata, CallRequest, TraceOptions, Trailing<BlockNumber>) -> BoxFuture<TraceResults, Error>;
|
||||
fn call(&self, Self::Metadata, CallRequest, TraceOptions, Trailing<BlockNumber>) -> Result<TraceResults, Error>;
|
||||
|
||||
/// Executes all given calls and returns a number of possible traces for each of it.
|
||||
#[rpc(meta, name = "trace_callMany")]
|
||||
fn call_many(&self, Self::Metadata, Vec<(CallRequest, TraceOptions)>, Trailing<BlockNumber>) -> BoxFuture<Vec<TraceResults>, Error>;
|
||||
fn call_many(&self, Self::Metadata, Vec<(CallRequest, TraceOptions)>, Trailing<BlockNumber>) -> Result<Vec<TraceResults>, Error>;
|
||||
|
||||
/// Executes the given raw transaction and returns a number of possible traces for it.
|
||||
#[rpc(name = "trace_rawTransaction")]
|
||||
|
||||
Reference in New Issue
Block a user