traitified secret store
This commit is contained in:
@@ -30,20 +30,23 @@ use ethcore::ethereum::denominations::shannon;
|
||||
use v1::traits::{Eth, EthFilter};
|
||||
use v1::types::{Block, BlockTransactions, BlockNumber, Bytes, SyncStatus, SyncInfo, Transaction, TransactionRequest, OptionalValue, Index, Filter, Log};
|
||||
use v1::helpers::{PollFilter, PollManager};
|
||||
use util::keys::store::AccountProvider;
|
||||
|
||||
/// Eth rpc implementation.
|
||||
pub struct EthClient<C, S> where C: BlockChainClient, S: SyncStatusProvider {
|
||||
pub struct EthClient<C, S, A> where C: BlockChainClient, S: SyncStatusProvider, A: AccountProvider {
|
||||
client: Weak<C>,
|
||||
sync: Weak<S>,
|
||||
accounts: Weak<A>,
|
||||
hashrates: RwLock<HashMap<H256, u64>>,
|
||||
}
|
||||
|
||||
impl<C, S> EthClient<C, S> where C: BlockChainClient, S: SyncStatusProvider {
|
||||
impl<C, S, A> EthClient<C, S, A> where C: BlockChainClient, S: SyncStatusProvider, A: AccountProvider {
|
||||
/// Creates new EthClient.
|
||||
pub fn new(client: &Arc<C>, sync: &Arc<S>) -> Self {
|
||||
pub fn new(client: &Arc<C>, sync: &Arc<S>, accounts: &Arc<A>) -> Self {
|
||||
EthClient {
|
||||
client: Arc::downgrade(client),
|
||||
sync: Arc::downgrade(sync),
|
||||
accounts: Arc::downgrade(accounts),
|
||||
hashrates: RwLock::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
@@ -94,7 +97,7 @@ impl<C, S> EthClient<C, S> where C: BlockChainClient, S: SyncStatusProvider {
|
||||
}
|
||||
}
|
||||
|
||||
impl<C, S> Eth for EthClient<C, S> where C: BlockChainClient + 'static, S: SyncStatusProvider + 'static {
|
||||
impl<C, S, A> Eth for EthClient<C, S, A> where C: BlockChainClient + 'static, S: SyncStatusProvider + 'static, A: AccountProvider + 'static {
|
||||
fn protocol_version(&self, params: Params) -> Result<Value, Error> {
|
||||
match params {
|
||||
Params::None => to_value(&U256::from(take_weak!(self.sync).status().protocol_version)),
|
||||
@@ -256,9 +259,8 @@ impl<C, S> Eth for EthClient<C, S> where C: BlockChainClient + 'static, S: SyncS
|
||||
fn send_transaction(&self, params: Params) -> Result<Value, Error> {
|
||||
from_params::<(TransactionRequest, )>(params)
|
||||
.and_then(|(transaction_request, )| {
|
||||
let client = take_weak!(self.client);
|
||||
let store = client.secret_store().read().unwrap();
|
||||
match store.account_secret(&transaction_request.from) {
|
||||
let accounts = take_weak!(self.accounts);
|
||||
match accounts.account_secret(&transaction_request.from) {
|
||||
Ok(secret) => {
|
||||
let sync = take_weak!(self.sync);
|
||||
let (transaction, _) = transaction_request.to_eth();
|
||||
|
||||
Reference in New Issue
Block a user