From 49f49194c50ea89a8573f09e18295083ae981858 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Wed, 8 Feb 2017 20:44:40 +0100 Subject: [PATCH] use Dispatcher when starting RPCs --- parity/rpc_apis.rs | 12 ++++++++---- rpc/src/lib.rs | 2 +- rpc/src/v1/helpers/dispatch.rs | 16 +++++++++++++++- rpc/src/v1/mod.rs | 2 +- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/parity/rpc_apis.rs b/parity/rpc_apis.rs index 4c5e88406..548e84995 100644 --- a/parity/rpc_apis.rs +++ b/parity/rpc_apis.rs @@ -28,6 +28,7 @@ use ethcore::miner::{Miner, ExternalMiner}; use ethcore::snapshot::SnapshotService; use ethcore_rpc::{Metadata, NetworkSettings}; use ethcore_rpc::informant::{Middleware, RpcStats, ClientNotifier}; +use ethcore_rpc::dispatch::FullDispatcher; use ethsync::{ManageNetwork, SyncProvider}; use hash_fetch::fetch::Client as FetchClient; use jsonrpc_core::{MetaIoHandler}; @@ -176,10 +177,11 @@ macro_rules! add_signing_methods { { let handler = &mut $handler; let deps = &$deps; + let dispatcher = FullDispatcher::new(Arc::downgrade(&deps.client), Arc::downgrade(&deps.miner)); if deps.signer_service.is_enabled() { - handler.extend_with($namespace::to_delegate(SigningQueueClient::new(&deps.signer_service, &deps.client, &deps.miner, &deps.secret_store))) + handler.extend_with($namespace::to_delegate(SigningQueueClient::new(&deps.signer_service, dispatcher, &deps.secret_store))) } else { - handler.extend_with($namespace::to_delegate(SigningUnsafeClient::new(&deps.client, &deps.secret_store, &deps.miner))) + handler.extend_with($namespace::to_delegate(SigningUnsafeClient::new(&deps.secret_store, dispatcher))) } } } @@ -194,6 +196,8 @@ pub fn setup_rpc(stats: Arc, deps: Arc, apis: ApiSet) -> // it's turned into vector, cause ont of the cases requires &[] let apis = apis.list_apis().into_iter().collect::>(); + let dispatcher = FullDispatcher::new(Arc::downgrade(&deps.client), Arc::downgrade(&deps.miner)); + for api in &apis { match *api { Api::Web3 => { @@ -223,10 +227,10 @@ pub fn setup_rpc(stats: Arc, deps: Arc, apis: ApiSet) -> add_signing_methods!(EthSigning, handler, deps); }, Api::Personal => { - handler.extend_with(PersonalClient::new(&deps.secret_store, &deps.client, &deps.miner, deps.geth_compatibility).to_delegate()); + handler.extend_with(PersonalClient::new(&deps.secret_store, dispatcher.clone(), deps.geth_compatibility).to_delegate()); }, Api::Signer => { - handler.extend_with(SignerClient::new(&deps.secret_store, &deps.client, &deps.miner, &deps.signer_service).to_delegate()); + handler.extend_with(SignerClient::new(&deps.secret_store, dispatcher.clone(), &deps.signer_service).to_delegate()); }, Api::Parity => { let signer = match deps.signer_service.is_enabled() { diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 0a32932f1..50cde77c5 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -65,7 +65,7 @@ use jsonrpc_core::reactor::RpcHandler; pub use ipc::{Server as IpcServer, Error as IpcServerError}; pub use jsonrpc_http_server::{ServerBuilder, Server, RpcServerError}; pub mod v1; -pub use v1::{SigningQueue, SignerService, ConfirmationsQueue, NetworkSettings, Metadata, Origin, informant}; +pub use v1::{SigningQueue, SignerService, ConfirmationsQueue, NetworkSettings, Metadata, Origin, informant, dispatch}; pub use v1::block_import::is_major_importing; /// Start http server asynchronously and returns result with `Server` handle on success or an error. diff --git a/rpc/src/v1/helpers/dispatch.rs b/rpc/src/v1/helpers/dispatch.rs index 24a0d41a6..36d5ad864 100644 --- a/rpc/src/v1/helpers/dispatch.rs +++ b/rpc/src/v1/helpers/dispatch.rs @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +//! Utilities and helpers for transaction dispatch. + use std::fmt::Debug; use std::ops::Deref; use std::sync::Weak; @@ -152,20 +154,29 @@ impl Dispatcher for FullDispatcher { + /// No token. No(T), + /// With token. Yes(T, AccountToken), } @@ -181,6 +192,7 @@ impl Deref for WithToken { } impl WithToken { + /// Map the value with the given closure, preserving the token. pub fn map(self, f: F) -> WithToken where S: Debug, F: FnOnce(T) -> S, @@ -191,6 +203,7 @@ impl WithToken { } } + /// Convert into inner value, ignoring possible token. pub fn into_value(self) -> T { match self { WithToken::No(v) => v, @@ -222,6 +235,7 @@ impl From<(T, Option)> for WithToken { } } +/// Execute a confirmation payload. pub fn execute( dispatcher: D, accounts: &AccountProvider, diff --git a/rpc/src/v1/mod.rs b/rpc/src/v1/mod.rs index 617dda0f9..f278718ae 100644 --- a/rpc/src/v1/mod.rs +++ b/rpc/src/v1/mod.rs @@ -38,5 +38,5 @@ pub mod types; pub use self::traits::{Web3, Eth, EthFilter, EthSigning, Net, Parity, ParityAccounts, ParitySet, ParitySigning, Signer, Personal, Traces, Rpc}; pub use self::impls::*; -pub use self::helpers::{SigningQueue, SignerService, ConfirmationsQueue, NetworkSettings, block_import, informant}; +pub use self::helpers::{SigningQueue, SignerService, ConfirmationsQueue, NetworkSettings, block_import, informant, dispatch}; pub use self::metadata::{Metadata, Origin};