diff --git a/parity/main.rs b/parity/main.rs index 5c8cc60e0..59f08c1fe 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -79,7 +79,6 @@ use std::fs::File; use std::str::{FromStr, from_utf8}; use std::thread::sleep; use std::time::Duration; -use std::collections::HashSet; use rustc_serialize::hex::FromHex; use ctrlc::CtrlC; use util::{H256, ToPretty, NetworkConfiguration, PayloadInfo, Bytes}; @@ -201,7 +200,7 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig) let deps_for_rpc_apis = Arc::new(rpc_apis::Dependencies { signer_enabled: conf.args.flag_signer, - signer_queue: Arc::new(Mutex::new(HashSet::new())), + signer_queue: Arc::new(rpc_apis::ConfirmationsQueue::default()), client: client.clone(), sync: sync.clone(), secret_store: account_service.clone(), diff --git a/parity/rpc_apis.rs b/parity/rpc_apis.rs index 7d6e55fee..4278fb060 100644 --- a/parity/rpc_apis.rs +++ b/parity/rpc_apis.rs @@ -26,7 +26,17 @@ use util::RotatingLogger; use util::keys::store::AccountService; use util::network_settings::NetworkSettings; -use ethcore_rpc::{SigningQueue, Extendable}; +#[cfg(feature="rpc")] +pub use ethcore_rpc::ConfirmationsQueue; +#[cfg(not(feature="rpc"))] +#[derive(Default)] +pub struct ConfirmationsQueue; + +#[cfg(feature="rpc")] +use ethcore_rpc::Extendable; + + + pub enum Api { Web3, @@ -62,7 +72,7 @@ impl FromStr for Api { pub struct Dependencies { pub signer_enabled: bool, - pub signer_queue: Arc, + pub signer_queue: Arc, pub client: Arc, pub sync: Arc, pub secret_store: Arc, @@ -125,7 +135,10 @@ pub fn setup_rpc(server: T, deps: Arc, apis: Option } }, Api::Personal => { - server.add_delegate(PersonalClient::new(&deps.secret_store, &deps.client, &deps.miner).to_delegate()) + server.add_delegate(PersonalClient::new(&deps.secret_store, &deps.client, &deps.miner).to_delegate()); + if deps.signer_enabled { + server.add_delegate(SignerClient::new(&deps.secret_store, &deps.client, &deps.miner, &deps.signer_queue).to_delegate()); + } }, Api::Ethcore => { server.add_delegate(EthcoreClient::new(&deps.miner, deps.logger.clone(), deps.settings.clone()).to_delegate()) diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 80ecf8b71..699ee9ba1 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -39,7 +39,7 @@ use self::jsonrpc_core::{IoHandler, IoDelegate}; pub use jsonrpc_http_server::{Server, RpcServerError}; pub mod v1; -pub use v1::SigningQueue; +pub use v1::{SigningQueue, ConfirmationsQueue}; /// An object that can be extended with `IoDelegates` pub trait Extendable { diff --git a/rpc/src/v1/helpers/signing_queue.rs b/rpc/src/v1/helpers/signing_queue.rs index 4e26fbaf6..b2e89522d 100644 --- a/rpc/src/v1/helpers/signing_queue.rs +++ b/rpc/src/v1/helpers/signing_queue.rs @@ -31,6 +31,7 @@ pub trait SigningQueue: Send + Sync { fn requests(&self) -> Vec; } +/// Queue for all unconfirmed transactions. #[derive(Default)] pub struct ConfirmationsQueue { id: Mutex, diff --git a/rpc/src/v1/impls/eth_signing.rs b/rpc/src/v1/impls/eth_signing.rs index 2a4c845b8..f4a972fb5 100644 --- a/rpc/src/v1/impls/eth_signing.rs +++ b/rpc/src/v1/impls/eth_signing.rs @@ -22,7 +22,7 @@ use ethminer::MinerService; use ethcore::client::BlockChainClient; use util::numbers::*; use util::keys::store::AccountProvider; -use v1::helpers::SigningQueue; +use v1::helpers::{SigningQueue, ConfirmationsQueue}; use v1::traits::EthSigning; use v1::types::TransactionRequest; use v1::impls::sign_and_dispatch; @@ -30,12 +30,12 @@ use v1::impls::sign_and_dispatch; /// Implementation of functions that require signing when no trusted signer is used. pub struct EthSigningQueueClient { - queue: Weak, + queue: Weak, } impl EthSigningQueueClient { /// Creates a new signing queue client given shared signing queue. - pub fn new(queue: &Arc) -> Self { + pub fn new(queue: &Arc) -> Self { EthSigningQueueClient { queue: Arc::downgrade(queue), } diff --git a/rpc/src/v1/impls/personal_signer.rs b/rpc/src/v1/impls/personal_signer.rs index 6afedfea9..cf4e927ac 100644 --- a/rpc/src/v1/impls/personal_signer.rs +++ b/rpc/src/v1/impls/personal_signer.rs @@ -21,7 +21,7 @@ use jsonrpc_core::*; use v1::traits::PersonalSigner; use v1::types::TransactionModification; use v1::impls::sign_and_dispatch; -use v1::helpers::SigningQueue; +use v1::helpers::{SigningQueue, ConfirmationsQueue}; use util::keys::store::AccountProvider; use util::numbers::*; use ethcore::client::BlockChainClient; @@ -30,7 +30,7 @@ use ethminer::MinerService; /// Transactions confirmation (personal) rpc implementation. pub struct SignerClient where A: AccountProvider, C: BlockChainClient, M: MinerService { - queue: Weak, + queue: Weak, accounts: Weak, client: Weak, miner: Weak, @@ -40,7 +40,7 @@ impl SignerClient where A: AccountProvider, C: BlockChainClient, M: MinerService { /// Create new instance of signer client. - pub fn new(store: &Arc, client: &Arc, miner: &Arc, queue: &Arc) -> Self { + pub fn new(store: &Arc, client: &Arc, miner: &Arc, queue: &Arc) -> Self { SignerClient { queue: Arc::downgrade(queue), accounts: Arc::downgrade(store), diff --git a/rpc/src/v1/mod.rs b/rpc/src/v1/mod.rs index deb580d2b..54628d892 100644 --- a/rpc/src/v1/mod.rs +++ b/rpc/src/v1/mod.rs @@ -27,4 +27,4 @@ pub mod types; pub use self::traits::{Web3, Eth, EthFilter, EthSigning, Personal, PersonalSigner, Net, Ethcore, Traces, Rpc}; pub use self::impls::*; -pub use self::helpers::SigningQueue; +pub use self::helpers::{SigningQueue, ConfirmationsQueue}; diff --git a/rpc/src/v1/tests/mocked/eth_signing.rs b/rpc/src/v1/tests/mocked/eth_signing.rs index 7522fabec..6eb6e3fd6 100644 --- a/rpc/src/v1/tests/mocked/eth_signing.rs +++ b/rpc/src/v1/tests/mocked/eth_signing.rs @@ -22,13 +22,13 @@ use v1::helpers::{ConfirmationsQueue, SigningQueue}; use util::keys::TestAccount; struct EthSigningTester { - pub queue: Arc, + pub queue: Arc, pub io: IoHandler, } impl Default for EthSigningTester { fn default() -> Self { - let queue: Arc = Arc::new(ConfirmationsQueue::default()); + let queue = Arc::new(ConfirmationsQueue::default()); let io = IoHandler::new(); io.add_delegate(EthSigningQueueClient::new(&queue).to_delegate()); diff --git a/rpc/src/v1/tests/mocked/personal_signer.rs b/rpc/src/v1/tests/mocked/personal_signer.rs index b6d28b986..cd1f81d9a 100644 --- a/rpc/src/v1/tests/mocked/personal_signer.rs +++ b/rpc/src/v1/tests/mocked/personal_signer.rs @@ -29,7 +29,7 @@ use v1::types::TransactionRequest; struct PersonalSignerTester { - queue: Arc, + queue: Arc, accounts: Arc, io: IoHandler, miner: Arc, @@ -54,7 +54,7 @@ fn miner_service() -> Arc { } fn signer_tester() -> PersonalSignerTester { - let queue: Arc = Arc::new(ConfirmationsQueue::default()); + let queue = Arc::new(ConfirmationsQueue::default()); let accounts = accounts_provider(); let client = blockchain_client(); let miner = miner_service();