Exposing PersonalSigner API
This commit is contained in:
parent
99f9747a3f
commit
a7dfa83da1
@ -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(),
|
||||
|
@ -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<SigningQueue>,
|
||||
pub signer_queue: Arc<ConfirmationsQueue>,
|
||||
pub client: Arc<Client>,
|
||||
pub sync: Arc<EthSync>,
|
||||
pub secret_store: Arc<AccountService>,
|
||||
@ -125,7 +135,10 @@ pub fn setup_rpc<T: Extendable>(server: T, deps: Arc<Dependencies>, 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())
|
||||
|
@ -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 {
|
||||
|
@ -31,6 +31,7 @@ pub trait SigningQueue: Send + Sync {
|
||||
fn requests(&self) -> Vec<TransactionConfirmation>;
|
||||
}
|
||||
|
||||
/// Queue for all unconfirmed transactions.
|
||||
#[derive(Default)]
|
||||
pub struct ConfirmationsQueue {
|
||||
id: Mutex<U256>,
|
||||
|
@ -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<SigningQueue>,
|
||||
queue: Weak<ConfirmationsQueue>,
|
||||
}
|
||||
|
||||
impl EthSigningQueueClient {
|
||||
/// Creates a new signing queue client given shared signing queue.
|
||||
pub fn new(queue: &Arc<SigningQueue>) -> Self {
|
||||
pub fn new(queue: &Arc<ConfirmationsQueue>) -> Self {
|
||||
EthSigningQueueClient {
|
||||
queue: Arc::downgrade(queue),
|
||||
}
|
||||
|
@ -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<A, C, M>
|
||||
where A: AccountProvider, C: BlockChainClient, M: MinerService {
|
||||
queue: Weak<SigningQueue>,
|
||||
queue: Weak<ConfirmationsQueue>,
|
||||
accounts: Weak<A>,
|
||||
client: Weak<C>,
|
||||
miner: Weak<M>,
|
||||
@ -40,7 +40,7 @@ impl<A: 'static, C: 'static, M: 'static> SignerClient<A, C, M>
|
||||
where A: AccountProvider, C: BlockChainClient, M: MinerService {
|
||||
|
||||
/// Create new instance of signer client.
|
||||
pub fn new(store: &Arc<A>, client: &Arc<C>, miner: &Arc<M>, queue: &Arc<SigningQueue>) -> Self {
|
||||
pub fn new(store: &Arc<A>, client: &Arc<C>, miner: &Arc<M>, queue: &Arc<ConfirmationsQueue>) -> Self {
|
||||
SignerClient {
|
||||
queue: Arc::downgrade(queue),
|
||||
accounts: Arc::downgrade(store),
|
||||
|
@ -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};
|
||||
|
@ -22,13 +22,13 @@ use v1::helpers::{ConfirmationsQueue, SigningQueue};
|
||||
use util::keys::TestAccount;
|
||||
|
||||
struct EthSigningTester {
|
||||
pub queue: Arc<SigningQueue>,
|
||||
pub queue: Arc<ConfirmationsQueue>,
|
||||
pub io: IoHandler,
|
||||
}
|
||||
|
||||
impl Default for EthSigningTester {
|
||||
fn default() -> Self {
|
||||
let queue: Arc<SigningQueue> = Arc::new(ConfirmationsQueue::default());
|
||||
let queue = Arc::new(ConfirmationsQueue::default());
|
||||
let io = IoHandler::new();
|
||||
io.add_delegate(EthSigningQueueClient::new(&queue).to_delegate());
|
||||
|
||||
|
@ -29,7 +29,7 @@ use v1::types::TransactionRequest;
|
||||
|
||||
|
||||
struct PersonalSignerTester {
|
||||
queue: Arc<SigningQueue>,
|
||||
queue: Arc<ConfirmationsQueue>,
|
||||
accounts: Arc<TestAccountProvider>,
|
||||
io: IoHandler,
|
||||
miner: Arc<TestMinerService>,
|
||||
@ -54,7 +54,7 @@ fn miner_service() -> Arc<TestMinerService> {
|
||||
}
|
||||
|
||||
fn signer_tester() -> PersonalSignerTester {
|
||||
let queue: Arc<SigningQueue> = Arc::new(ConfirmationsQueue::default());
|
||||
let queue = Arc::new(ConfirmationsQueue::default());
|
||||
let accounts = accounts_provider();
|
||||
let client = blockchain_client();
|
||||
let miner = miner_service();
|
||||
|
Loading…
Reference in New Issue
Block a user