Asynchronous RPC support (#2017)
* Async RPC * Limiting number of transactions in queue * Fixing tests * Bumping serde and jsonrpc-core * serde updated to 0.8 * fixed failing tests * Bumping ipc server * Fixing API for endpoints * Experimenting with tests without --release mode
This commit is contained in:
committed by
Arkadiy Paronyan
parent
ca03cfa58a
commit
b4f3c4bd7a
@@ -131,7 +131,7 @@ impl<C, S: ?Sized, M, EM> EthClient<C, S, M, EM> where
|
||||
},
|
||||
extra_data: Bytes::new(view.extra_data())
|
||||
};
|
||||
to_value(&block)
|
||||
Ok(to_value(&block))
|
||||
},
|
||||
_ => Ok(Value::Null)
|
||||
}
|
||||
@@ -139,7 +139,7 @@ impl<C, S: ?Sized, M, EM> EthClient<C, S, M, EM> where
|
||||
|
||||
fn transaction(&self, id: TransactionID) -> Result<Value, Error> {
|
||||
match take_weak!(self.client).transaction(id) {
|
||||
Some(t) => to_value(&Transaction::from(t)),
|
||||
Some(t) => Ok(to_value(&Transaction::from(t))),
|
||||
None => Ok(Value::Null)
|
||||
}
|
||||
}
|
||||
@@ -177,7 +177,7 @@ impl<C, S: ?Sized, M, EM> EthClient<C, S, M, EM> where
|
||||
uncles: vec![],
|
||||
transactions: BlockTransactions::Hashes(vec![]),
|
||||
};
|
||||
to_value(&block)
|
||||
Ok(to_value(&block))
|
||||
}
|
||||
|
||||
fn sign_call(&self, request: CRequest) -> Result<SignedTransaction, Error> {
|
||||
@@ -270,28 +270,28 @@ impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
|
||||
}
|
||||
}
|
||||
};
|
||||
to_value(&res)
|
||||
Ok(to_value(&res))
|
||||
}
|
||||
|
||||
fn author(&self, params: Params) -> Result<Value, Error> {
|
||||
try!(self.active());
|
||||
try!(expect_no_params(params));
|
||||
|
||||
to_value(&RpcH160::from(take_weak!(self.miner).author()))
|
||||
Ok(to_value(&RpcH160::from(take_weak!(self.miner).author())))
|
||||
}
|
||||
|
||||
fn is_mining(&self, params: Params) -> Result<Value, Error> {
|
||||
try!(self.active());
|
||||
try!(expect_no_params(params));
|
||||
|
||||
to_value(&(take_weak!(self.miner).is_sealing()))
|
||||
Ok(to_value(&(take_weak!(self.miner).is_sealing())))
|
||||
}
|
||||
|
||||
fn hashrate(&self, params: Params) -> Result<Value, Error> {
|
||||
try!(self.active());
|
||||
try!(expect_no_params(params));
|
||||
|
||||
to_value(&RpcU256::from(self.external_miner.hashrate()))
|
||||
Ok(to_value(&RpcU256::from(self.external_miner.hashrate())))
|
||||
}
|
||||
|
||||
fn gas_price(&self, params: Params) -> Result<Value, Error> {
|
||||
@@ -299,7 +299,7 @@ impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
|
||||
try!(expect_no_params(params));
|
||||
|
||||
let (client, miner) = (take_weak!(self.client), take_weak!(self.miner));
|
||||
to_value(&RpcU256::from(default_gas_price(&*client, &*miner)))
|
||||
Ok(to_value(&RpcU256::from(default_gas_price(&*client, &*miner))))
|
||||
}
|
||||
|
||||
fn accounts(&self, params: Params) -> Result<Value, Error> {
|
||||
@@ -308,14 +308,14 @@ impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
|
||||
|
||||
let store = take_weak!(self.accounts);
|
||||
let accounts = try!(store.accounts().map_err(|e| errors::internal("Could not fetch accounts.", e)));
|
||||
to_value(&accounts.into_iter().map(Into::into).collect::<Vec<RpcH160>>())
|
||||
Ok(to_value(&accounts.into_iter().map(Into::into).collect::<Vec<RpcH160>>()))
|
||||
}
|
||||
|
||||
fn block_number(&self, params: Params) -> Result<Value, Error> {
|
||||
try!(self.active());
|
||||
try!(expect_no_params(params));
|
||||
|
||||
to_value(&RpcU256::from(take_weak!(self.client).chain_info().best_block_number))
|
||||
Ok(to_value(&RpcU256::from(take_weak!(self.client).chain_info().best_block_number)))
|
||||
}
|
||||
|
||||
fn balance(&self, params: Params) -> Result<Value, Error> {
|
||||
@@ -324,9 +324,9 @@ impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
|
||||
.and_then(|(address, block_number,)| {
|
||||
let address: Address = RpcH160::into(address);
|
||||
match block_number {
|
||||
BlockNumber::Pending => to_value(&RpcU256::from(take_weak!(self.miner).balance(&*take_weak!(self.client), &address))),
|
||||
BlockNumber::Pending => Ok(to_value(&RpcU256::from(take_weak!(self.miner).balance(&*take_weak!(self.client), &address)))),
|
||||
id => match take_weak!(self.client).balance(&address, id.into()) {
|
||||
Some(balance) => to_value(&RpcU256::from(balance)),
|
||||
Some(balance) => Ok(to_value(&RpcU256::from(balance))),
|
||||
None => Err(errors::state_pruned()),
|
||||
}
|
||||
}
|
||||
@@ -340,9 +340,9 @@ impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
|
||||
let address: Address = RpcH160::into(address);
|
||||
let position: U256 = RpcU256::into(position);
|
||||
match block_number {
|
||||
BlockNumber::Pending => to_value(&RpcU256::from(take_weak!(self.miner).storage_at(&*take_weak!(self.client), &address, &H256::from(position)))),
|
||||
BlockNumber::Pending => Ok(to_value(&RpcU256::from(take_weak!(self.miner).storage_at(&*take_weak!(self.client), &address, &H256::from(position))))),
|
||||
id => match take_weak!(self.client).storage_at(&address, &H256::from(position), id.into()) {
|
||||
Some(s) => to_value(&RpcH256::from(s)),
|
||||
Some(s) => Ok(to_value(&RpcH256::from(s))),
|
||||
None => Err(errors::state_pruned()),
|
||||
}
|
||||
}
|
||||
@@ -356,9 +356,9 @@ impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
|
||||
.and_then(|(address, block_number,)| {
|
||||
let address: Address = RpcH160::into(address);
|
||||
match block_number {
|
||||
BlockNumber::Pending => to_value(&RpcU256::from(take_weak!(self.miner).nonce(&*take_weak!(self.client), &address))),
|
||||
BlockNumber::Pending => Ok(to_value(&RpcU256::from(take_weak!(self.miner).nonce(&*take_weak!(self.client), &address)))),
|
||||
id => match take_weak!(self.client).nonce(&address, id.into()) {
|
||||
Some(nonce) => to_value(&RpcU256::from(nonce)),
|
||||
Some(nonce) => Ok(to_value(&RpcU256::from(nonce))),
|
||||
None => Err(errors::state_pruned()),
|
||||
}
|
||||
}
|
||||
@@ -370,18 +370,18 @@ impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
|
||||
from_params::<(RpcH256,)>(params)
|
||||
.and_then(|(hash,)| // match
|
||||
take_weak!(self.client).block(BlockID::Hash(hash.into()))
|
||||
.map_or(Ok(Value::Null), |bytes| to_value(&RpcU256::from(BlockView::new(&bytes).transactions_count()))))
|
||||
.map_or(Ok(Value::Null), |bytes| Ok(to_value(&RpcU256::from(BlockView::new(&bytes).transactions_count())))))
|
||||
}
|
||||
|
||||
fn block_transaction_count_by_number(&self, params: Params) -> Result<Value, Error> {
|
||||
try!(self.active());
|
||||
from_params::<(BlockNumber,)>(params)
|
||||
.and_then(|(block_number,)| match block_number {
|
||||
BlockNumber::Pending => to_value(
|
||||
BlockNumber::Pending => Ok(to_value(
|
||||
&RpcU256::from(take_weak!(self.miner).status().transactions_in_pending_block)
|
||||
),
|
||||
)),
|
||||
_ => take_weak!(self.client).block(block_number.into())
|
||||
.map_or(Ok(Value::Null), |bytes| to_value(&RpcU256::from(BlockView::new(&bytes).transactions_count())))
|
||||
.map_or(Ok(Value::Null), |bytes| Ok(to_value(&RpcU256::from(BlockView::new(&bytes).transactions_count()))))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -390,16 +390,16 @@ impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
|
||||
from_params::<(RpcH256,)>(params)
|
||||
.and_then(|(hash,)|
|
||||
take_weak!(self.client).block(BlockID::Hash(hash.into()))
|
||||
.map_or(Ok(Value::Null), |bytes| to_value(&RpcU256::from(BlockView::new(&bytes).uncles_count()))))
|
||||
.map_or(Ok(Value::Null), |bytes| Ok(to_value(&RpcU256::from(BlockView::new(&bytes).uncles_count())))))
|
||||
}
|
||||
|
||||
fn block_uncles_count_by_number(&self, params: Params) -> Result<Value, Error> {
|
||||
try!(self.active());
|
||||
from_params::<(BlockNumber,)>(params)
|
||||
.and_then(|(block_number,)| match block_number {
|
||||
BlockNumber::Pending => to_value(&RpcU256::from(0)),
|
||||
BlockNumber::Pending => Ok(to_value(&RpcU256::from(0))),
|
||||
_ => take_weak!(self.client).block(block_number.into())
|
||||
.map_or(Ok(Value::Null), |bytes| to_value(&RpcU256::from(BlockView::new(&bytes).uncles_count())))
|
||||
.map_or(Ok(Value::Null), |bytes| Ok(to_value(&RpcU256::from(BlockView::new(&bytes).uncles_count()))))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -409,9 +409,9 @@ impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
|
||||
.and_then(|(address, block_number,)| {
|
||||
let address: Address = RpcH160::into(address);
|
||||
match block_number {
|
||||
BlockNumber::Pending => to_value(&take_weak!(self.miner).code(&*take_weak!(self.client), &address).map_or_else(Bytes::default, Bytes::new)),
|
||||
BlockNumber::Pending => Ok(to_value(&take_weak!(self.miner).code(&*take_weak!(self.client), &address).map_or_else(Bytes::default, Bytes::new))),
|
||||
_ => match take_weak!(self.client).code(&address, block_number.into()) {
|
||||
Some(code) => to_value(&code.map_or_else(Bytes::default, Bytes::new)),
|
||||
Some(code) => Ok(to_value(&code.map_or_else(Bytes::default, Bytes::new))),
|
||||
None => Err(errors::state_pruned()),
|
||||
},
|
||||
}
|
||||
@@ -437,7 +437,7 @@ impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
|
||||
let miner = take_weak!(self.miner);
|
||||
let hash: H256 = hash.into();
|
||||
match miner.transaction(&hash) {
|
||||
Some(pending_tx) => to_value(&Transaction::from(pending_tx)),
|
||||
Some(pending_tx) => Ok(to_value(&Transaction::from(pending_tx))),
|
||||
None => self.transaction(TransactionID::Hash(hash))
|
||||
}
|
||||
})
|
||||
@@ -462,11 +462,11 @@ impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
|
||||
let miner = take_weak!(self.miner);
|
||||
let hash: H256 = hash.into();
|
||||
match (miner.pending_receipt(&hash), self.options.allow_pending_receipt_query) {
|
||||
(Some(receipt), true) => to_value(&Receipt::from(receipt)),
|
||||
(Some(receipt), true) => Ok(to_value(&Receipt::from(receipt))),
|
||||
_ => {
|
||||
let client = take_weak!(self.client);
|
||||
let receipt = client.transaction_receipt(TransactionID::Hash(hash));
|
||||
to_value(&receipt.map(Receipt::from))
|
||||
Ok(to_value(&receipt.map(Receipt::from)))
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -492,7 +492,7 @@ impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
|
||||
if Command::new(SOLC).output().is_ok() {
|
||||
compilers.push("solidity".to_owned())
|
||||
}
|
||||
to_value(&compilers)
|
||||
Ok(to_value(&compilers))
|
||||
}
|
||||
|
||||
fn logs(&self, params: Params) -> Result<Value, Error> {
|
||||
@@ -511,7 +511,7 @@ impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
|
||||
logs.extend(pending);
|
||||
}
|
||||
|
||||
to_value(&logs)
|
||||
Ok(to_value(&logs))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -550,9 +550,9 @@ impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
|
||||
Err(errors::no_new_work())
|
||||
} else if self.options.send_block_number_in_get_work {
|
||||
let block_number = RpcU256::from(b.block().header().number());
|
||||
to_value(&(RpcH256::from(pow_hash), RpcH256::from(seed_hash), RpcH256::from(target), block_number))
|
||||
Ok(to_value(&(RpcH256::from(pow_hash), RpcH256::from(seed_hash), RpcH256::from(target), block_number)))
|
||||
} else {
|
||||
to_value(&(RpcH256::from(pow_hash), RpcH256::from(seed_hash), RpcH256::from(target)))
|
||||
Ok(to_value(&(RpcH256::from(pow_hash), RpcH256::from(seed_hash), RpcH256::from(target))))
|
||||
}
|
||||
}).unwrap_or(Err(Error::internal_error())) // no work found.
|
||||
}
|
||||
@@ -568,7 +568,7 @@ impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
|
||||
let client = take_weak!(self.client);
|
||||
let seal = vec![encode(&mix_hash).to_vec(), encode(&nonce).to_vec()];
|
||||
let r = miner.submit_seal(&*client, pow_hash, seal);
|
||||
to_value(&r.is_ok())
|
||||
Ok(to_value(&r.is_ok()))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -576,7 +576,7 @@ impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
|
||||
try!(self.active());
|
||||
from_params::<(RpcU256, RpcH256)>(params).and_then(|(rate, id)| {
|
||||
self.external_miner.submit_hashrate(rate.into(), id.into());
|
||||
to_value(&true)
|
||||
Ok(to_value(&true))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -587,7 +587,7 @@ impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
|
||||
let raw_transaction = raw_transaction.to_vec();
|
||||
match UntrustedRlp::new(&raw_transaction).as_val() {
|
||||
Ok(signed_transaction) => dispatch_transaction(&*take_weak!(self.client), &*take_weak!(self.miner), signed_transaction),
|
||||
Err(_) => to_value(&RpcH256::from(H256::from(0))),
|
||||
Err(_) => Ok(to_value(&RpcH256::from(H256::from(0)))),
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -602,7 +602,7 @@ impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
|
||||
BlockNumber::Pending => take_weak!(self.miner).call(&*take_weak!(self.client), &signed, Default::default()),
|
||||
block_number => take_weak!(self.client).call(&signed, block_number.into(), Default::default()),
|
||||
};
|
||||
to_value(&r.map(|e| Bytes(e.output)).unwrap_or(Bytes::new(vec![])))
|
||||
Ok(to_value(&r.map(|e| Bytes(e.output)).unwrap_or(Bytes::new(vec![]))))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -616,7 +616,7 @@ impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
|
||||
BlockNumber::Pending => take_weak!(self.miner).call(&*take_weak!(self.client), &signed, Default::default()),
|
||||
block => take_weak!(self.client).call(&signed, block.into(), Default::default()),
|
||||
};
|
||||
to_value(&RpcU256::from(r.map(|res| res.gas_used + res.refunded).unwrap_or(From::from(0))))
|
||||
Ok(to_value(&RpcU256::from(r.map(|res| res.gas_used + res.refunded).unwrap_or(From::from(0)))))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -653,7 +653,7 @@ impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
|
||||
|
||||
let s = String::from_utf8_lossy(&output.stdout);
|
||||
if let Some(hex) = s.lines().skip_while(|ref l| !l.contains("Binary")).skip(1).next() {
|
||||
to_value(&Bytes::new(hex.from_hex().unwrap_or(vec![])))
|
||||
Ok(to_value(&Bytes::new(hex.from_hex().unwrap_or(vec![]))))
|
||||
} else {
|
||||
Err(errors::compilation("Unexpected output."))
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ impl<C, M> EthFilter for EthFilterClient<C, M> where
|
||||
let mut polls = self.polls.lock();
|
||||
let block_number = take_weak!(self.client).chain_info().best_block_number;
|
||||
let id = polls.create_poll(PollFilter::Logs(block_number, Default::default(), filter));
|
||||
to_value(&RpcU256::from(id))
|
||||
Ok(to_value(&RpcU256::from(id)))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ impl<C, M> EthFilter for EthFilterClient<C, M> where
|
||||
|
||||
let mut polls = self.polls.lock();
|
||||
let id = polls.create_poll(PollFilter::Block(take_weak!(self.client).chain_info().best_block_number));
|
||||
to_value(&RpcU256::from(id))
|
||||
Ok(to_value(&RpcU256::from(id)))
|
||||
}
|
||||
|
||||
fn new_pending_transaction_filter(&self, params: Params) -> Result<Value, Error> {
|
||||
@@ -91,7 +91,7 @@ impl<C, M> EthFilter for EthFilterClient<C, M> where
|
||||
let pending_transactions = take_weak!(self.miner).pending_transactions_hashes();
|
||||
let id = polls.create_poll(PollFilter::PendingTransaction(pending_transactions));
|
||||
|
||||
to_value(&RpcU256::from(id))
|
||||
Ok(to_value(&RpcU256::from(id)))
|
||||
}
|
||||
|
||||
fn filter_changes(&self, params: Params) -> Result<Value, Error> {
|
||||
@@ -114,7 +114,7 @@ impl<C, M> EthFilter for EthFilterClient<C, M> where
|
||||
|
||||
*block_number = current_number;
|
||||
|
||||
to_value(&hashes)
|
||||
Ok(to_value(&hashes))
|
||||
},
|
||||
PollFilter::PendingTransaction(ref mut previous_hashes) => {
|
||||
// get hashes of pending transactions
|
||||
@@ -137,7 +137,7 @@ impl<C, M> EthFilter for EthFilterClient<C, M> where
|
||||
*previous_hashes = current_hashes;
|
||||
|
||||
// return new hashes
|
||||
to_value(&new_hashes)
|
||||
Ok(to_value(&new_hashes))
|
||||
},
|
||||
PollFilter::Logs(ref mut block_number, ref mut previous_logs, ref filter) => {
|
||||
// retrive the current block number
|
||||
@@ -178,7 +178,7 @@ impl<C, M> EthFilter for EthFilterClient<C, M> where
|
||||
// we want to get logs
|
||||
*block_number = current_number + 1;
|
||||
|
||||
to_value(&logs)
|
||||
Ok(to_value(&logs))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -203,7 +203,7 @@ impl<C, M> EthFilter for EthFilterClient<C, M> where
|
||||
logs.extend(pending_logs(&*take_weak!(self.miner), &filter));
|
||||
}
|
||||
|
||||
to_value(&logs)
|
||||
Ok(to_value(&logs))
|
||||
},
|
||||
// just empty array
|
||||
_ => Ok(Value::Array(vec![] as Vec<Value>)),
|
||||
@@ -214,7 +214,7 @@ impl<C, M> EthFilter for EthFilterClient<C, M> where
|
||||
fn uninstall_filter(&self, params: Params) -> Result<Value, Error> {
|
||||
try!(self.active());
|
||||
from_params::<(Index,)>(params)
|
||||
.and_then(|(index,)| {
|
||||
.map(|(index,)| {
|
||||
self.polls.lock().remove_poll(&index.value());
|
||||
to_value(&true)
|
||||
})
|
||||
|
||||
@@ -53,6 +53,11 @@ pub struct EthSigningQueueClient<C, M> where C: MiningBlockChainClient, M: Miner
|
||||
|
||||
const MAX_PENDING_DURATION: u64 = 60 * 60;
|
||||
|
||||
pub enum DispatchResult {
|
||||
Promise(ConfirmationPromise),
|
||||
Value(Value),
|
||||
}
|
||||
|
||||
impl<C, M> EthSigningQueueClient<C, M> where C: MiningBlockChainClient, M: MinerService {
|
||||
/// Creates a new signing queue client given shared signing queue.
|
||||
pub fn new(queue: &Arc<ConfirmationsQueue>, client: &Arc<C>, miner: &Arc<M>, accounts: &Arc<AccountProvider>) -> Self {
|
||||
@@ -71,23 +76,24 @@ impl<C, M> EthSigningQueueClient<C, M> where C: MiningBlockChainClient, M: Miner
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn dispatch_sign<F: FnOnce(ConfirmationPromise) -> Result<Value, Error>>(&self, params: Params, f: F) -> Result<Value, Error> {
|
||||
fn dispatch_sign(&self, params: Params) -> Result<DispatchResult, Error> {
|
||||
from_params::<(RpcH160, RpcH256)>(params).and_then(|(address, msg)| {
|
||||
let address: Address = address.into();
|
||||
let msg: H256 = msg.into();
|
||||
|
||||
let accounts = take_weak!(self.accounts);
|
||||
if accounts.is_unlocked(address) {
|
||||
return to_value(&accounts.sign(address, msg).ok().map_or_else(RpcH520::default, Into::into));
|
||||
return Ok(DispatchResult::Value(to_value(&accounts.sign(address, msg).ok().map_or_else(RpcH520::default, Into::into))))
|
||||
}
|
||||
|
||||
let queue = take_weak!(self.queue);
|
||||
let promise = queue.add_request(ConfirmationPayload::Sign(address, msg));
|
||||
f(promise)
|
||||
queue.add_request(ConfirmationPayload::Sign(address, msg))
|
||||
.map(DispatchResult::Promise)
|
||||
.map_err(|_| errors::request_rejected_limit())
|
||||
})
|
||||
}
|
||||
|
||||
fn dispatch_transaction<F: FnOnce(ConfirmationPromise) -> Result<Value, Error>>(&self, params: Params, f: F) -> Result<Value, Error> {
|
||||
fn dispatch_transaction(&self, params: Params) -> Result<DispatchResult, Error> {
|
||||
from_params::<(TransactionRequest, )>(params)
|
||||
.and_then(|(request, )| {
|
||||
let request: TRequest = request.into();
|
||||
@@ -96,13 +102,14 @@ impl<C, M> EthSigningQueueClient<C, M> where C: MiningBlockChainClient, M: Miner
|
||||
|
||||
if accounts.is_unlocked(request.from) {
|
||||
let sender = request.from;
|
||||
return sign_and_dispatch(&*client, &*miner, request, &*accounts, sender);
|
||||
return sign_and_dispatch(&*client, &*miner, request, &*accounts, sender).map(DispatchResult::Value);
|
||||
}
|
||||
|
||||
let queue = take_weak!(self.queue);
|
||||
let request = fill_optional_fields(request, &*client, &*miner);
|
||||
let promise = queue.add_request(ConfirmationPayload::Transaction(request));
|
||||
f(promise)
|
||||
queue.add_request(ConfirmationPayload::Transaction(request))
|
||||
.map(DispatchResult::Promise)
|
||||
.map_err(|_| errors::request_rejected_limit())
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -111,35 +118,53 @@ impl<C, M> EthSigning for EthSigningQueueClient<C, M>
|
||||
where C: MiningBlockChainClient + 'static, M: MinerService + 'static
|
||||
{
|
||||
|
||||
fn sign(&self, params: Params) -> Result<Value, Error> {
|
||||
try!(self.active());
|
||||
self.dispatch_sign(params, |promise| {
|
||||
promise.wait_with_timeout().unwrap_or_else(|| to_value(&RpcH520::default()))
|
||||
})
|
||||
fn sign(&self, params: Params, ready: Ready) {
|
||||
let res = self.active().and_then(|_| self.dispatch_sign(params));
|
||||
match res {
|
||||
Ok(DispatchResult::Promise(promise)) => {
|
||||
promise.wait_for_result(move |result| {
|
||||
ready.ready(result.unwrap_or_else(|| Err(errors::request_rejected())))
|
||||
})
|
||||
},
|
||||
Ok(DispatchResult::Value(v)) => ready.ready(Ok(v)),
|
||||
Err(e) => ready.ready(Err(e)),
|
||||
}
|
||||
}
|
||||
|
||||
fn post_sign(&self, params: Params) -> Result<Value, Error> {
|
||||
try!(self.active());
|
||||
self.dispatch_sign(params, |promise| {
|
||||
let id = promise.id();
|
||||
self.pending.lock().insert(id, promise);
|
||||
to_value(&RpcU256::from(id))
|
||||
self.dispatch_sign(params).map(|result| match result {
|
||||
DispatchResult::Value(v) => v,
|
||||
DispatchResult::Promise(promise) => {
|
||||
let id = promise.id();
|
||||
self.pending.lock().insert(id, promise);
|
||||
to_value(&RpcU256::from(id))
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
fn send_transaction(&self, params: Params) -> Result<Value, Error> {
|
||||
try!(self.active());
|
||||
self.dispatch_transaction(params, |promise| {
|
||||
promise.wait_with_timeout().unwrap_or_else(|| to_value(&RpcH256::default()))
|
||||
})
|
||||
fn send_transaction(&self, params: Params, ready: Ready) {
|
||||
let res = self.active().and_then(|_| self.dispatch_transaction(params));
|
||||
match res {
|
||||
Ok(DispatchResult::Promise(promise)) => {
|
||||
promise.wait_for_result(move |result| {
|
||||
ready.ready(result.unwrap_or_else(|| Err(errors::request_rejected())))
|
||||
})
|
||||
},
|
||||
Ok(DispatchResult::Value(v)) => ready.ready(Ok(v)),
|
||||
Err(e) => ready.ready(Err(e)),
|
||||
}
|
||||
}
|
||||
|
||||
fn post_transaction(&self, params: Params) -> Result<Value, Error> {
|
||||
try!(self.active());
|
||||
self.dispatch_transaction(params, |promise| {
|
||||
let id = promise.id();
|
||||
self.pending.lock().insert(id, promise);
|
||||
to_value(&RpcU256::from(id))
|
||||
self.dispatch_transaction(params).map(|result| match result {
|
||||
DispatchResult::Value(v) => v,
|
||||
DispatchResult::Promise(promise) => {
|
||||
let id = promise.id();
|
||||
self.pending.lock().insert(id, promise);
|
||||
to_value(&RpcU256::from(id))
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -196,23 +221,24 @@ impl<C, M> EthSigning for EthSigningUnsafeClient<C, M> where
|
||||
C: MiningBlockChainClient + 'static,
|
||||
M: MinerService + 'static {
|
||||
|
||||
fn sign(&self, params: Params) -> Result<Value, Error> {
|
||||
try!(self.active());
|
||||
from_params::<(RpcH160, RpcH256)>(params).and_then(|(address, msg)| {
|
||||
let address: Address = address.into();
|
||||
let msg: H256 = msg.into();
|
||||
to_value(&take_weak!(self.accounts).sign(address, msg).ok().map_or_else(RpcH520::default, Into::into))
|
||||
})
|
||||
fn sign(&self, params: Params, ready: Ready) {
|
||||
ready.ready(self.active()
|
||||
.and_then(|_| from_params::<(RpcH160, RpcH256)>(params))
|
||||
.and_then(|(address, msg)| {
|
||||
let address: Address = address.into();
|
||||
let msg: H256 = msg.into();
|
||||
Ok(to_value(&take_weak!(self.accounts).sign(address, msg).ok().map_or_else(RpcH520::default, Into::into)))
|
||||
}))
|
||||
}
|
||||
|
||||
fn send_transaction(&self, params: Params) -> Result<Value, Error> {
|
||||
try!(self.active());
|
||||
from_params::<(TransactionRequest, )>(params)
|
||||
fn send_transaction(&self, params: Params, ready: Ready) {
|
||||
ready.ready(self.active()
|
||||
.and_then(|_| from_params::<(TransactionRequest, )>(params))
|
||||
.and_then(|(request, )| {
|
||||
let request: TRequest = request.into();
|
||||
let sender = request.from;
|
||||
sign_and_dispatch(&*take_weak!(self.client), &*take_weak!(self.miner), request, &*take_weak!(self.accounts), sender)
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
fn post_sign(&self, _: Params) -> Result<Value, Error> {
|
||||
|
||||
@@ -82,50 +82,50 @@ impl<C, M, S: ?Sized> Ethcore for EthcoreClient<C, M, S> where M: MinerService +
|
||||
fn transactions_limit(&self, params: Params) -> Result<Value, Error> {
|
||||
try!(self.active());
|
||||
try!(expect_no_params(params));
|
||||
to_value(&take_weak!(self.miner).transactions_limit())
|
||||
Ok(to_value(&take_weak!(self.miner).transactions_limit()))
|
||||
}
|
||||
|
||||
fn min_gas_price(&self, params: Params) -> Result<Value, Error> {
|
||||
try!(self.active());
|
||||
try!(expect_no_params(params));
|
||||
to_value(&U256::from(take_weak!(self.miner).minimal_gas_price()))
|
||||
Ok(to_value(&U256::from(take_weak!(self.miner).minimal_gas_price())))
|
||||
}
|
||||
|
||||
fn extra_data(&self, params: Params) -> Result<Value, Error> {
|
||||
try!(self.active());
|
||||
try!(expect_no_params(params));
|
||||
to_value(&Bytes::new(take_weak!(self.miner).extra_data()))
|
||||
Ok(to_value(&Bytes::new(take_weak!(self.miner).extra_data())))
|
||||
}
|
||||
|
||||
fn gas_floor_target(&self, params: Params) -> Result<Value, Error> {
|
||||
try!(self.active());
|
||||
try!(expect_no_params(params));
|
||||
to_value(&U256::from(take_weak!(self.miner).gas_floor_target()))
|
||||
Ok(to_value(&U256::from(take_weak!(self.miner).gas_floor_target())))
|
||||
}
|
||||
|
||||
fn gas_ceil_target(&self, params: Params) -> Result<Value, Error> {
|
||||
try!(self.active());
|
||||
try!(expect_no_params(params));
|
||||
to_value(&U256::from(take_weak!(self.miner).gas_ceil_target()))
|
||||
Ok(to_value(&U256::from(take_weak!(self.miner).gas_ceil_target())))
|
||||
}
|
||||
|
||||
fn dev_logs(&self, params: Params) -> Result<Value, Error> {
|
||||
try!(self.active());
|
||||
try!(expect_no_params(params));
|
||||
let logs = self.logger.logs();
|
||||
to_value(&logs.as_slice())
|
||||
Ok(to_value(&logs.as_slice()))
|
||||
}
|
||||
|
||||
fn dev_logs_levels(&self, params: Params) -> Result<Value, Error> {
|
||||
try!(self.active());
|
||||
try!(expect_no_params(params));
|
||||
to_value(&self.logger.levels())
|
||||
Ok(to_value(&self.logger.levels()))
|
||||
}
|
||||
|
||||
fn net_chain(&self, params: Params) -> Result<Value, Error> {
|
||||
try!(self.active());
|
||||
try!(expect_no_params(params));
|
||||
to_value(&self.settings.chain)
|
||||
Ok(to_value(&self.settings.chain))
|
||||
}
|
||||
|
||||
fn net_peers(&self, params: Params) -> Result<Value, Error> {
|
||||
@@ -135,23 +135,23 @@ impl<C, M, S: ?Sized> Ethcore for EthcoreClient<C, M, S> where M: MinerService +
|
||||
let sync_status = take_weak!(self.sync).status();
|
||||
let net_config = take_weak!(self.net).network_config();
|
||||
|
||||
to_value(&Peers {
|
||||
Ok(to_value(&Peers {
|
||||
active: sync_status.num_active_peers,
|
||||
connected: sync_status.num_peers,
|
||||
max: sync_status.current_max_peers(net_config.min_peers, net_config.max_peers),
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
fn net_port(&self, params: Params) -> Result<Value, Error> {
|
||||
try!(self.active());
|
||||
try!(expect_no_params(params));
|
||||
to_value(&self.settings.network_port)
|
||||
Ok(to_value(&self.settings.network_port))
|
||||
}
|
||||
|
||||
fn node_name(&self, params: Params) -> Result<Value, Error> {
|
||||
try!(self.active());
|
||||
try!(expect_no_params(params));
|
||||
to_value(&self.settings.name)
|
||||
Ok(to_value(&self.settings.name))
|
||||
}
|
||||
|
||||
fn registry_address(&self, params: Params) -> Result<Value, Error> {
|
||||
@@ -162,7 +162,7 @@ impl<C, M, S: ?Sized> Ethcore for EthcoreClient<C, M, S> where M: MinerService +
|
||||
.get("registrar")
|
||||
.and_then(|s| Address::from_str(s).ok())
|
||||
.map(|s| H160::from(s));
|
||||
to_value(&r)
|
||||
Ok(to_value(&r))
|
||||
}
|
||||
|
||||
fn rpc_settings(&self, params: Params) -> Result<Value, Error> {
|
||||
@@ -178,7 +178,7 @@ impl<C, M, S: ?Sized> Ethcore for EthcoreClient<C, M, S> where M: MinerService +
|
||||
fn default_extra_data(&self, params: Params) -> Result<Value, Error> {
|
||||
try!(self.active());
|
||||
try!(expect_no_params(params));
|
||||
to_value(&Bytes::new(version_data()))
|
||||
Ok(to_value(&Bytes::new(version_data())))
|
||||
}
|
||||
|
||||
fn gas_price_statistics(&self, params: Params) -> Result<Value, Error> {
|
||||
@@ -186,10 +186,10 @@ impl<C, M, S: ?Sized> Ethcore for EthcoreClient<C, M, S> where M: MinerService +
|
||||
try!(expect_no_params(params));
|
||||
|
||||
match take_weak!(self.client).gas_price_statistics(100, 8) {
|
||||
Ok(stats) => to_value(&stats
|
||||
Ok(stats) => Ok(to_value(&stats
|
||||
.into_iter()
|
||||
.map(|x| to_value(&U256::from(x)).expect("x must be U256; qed"))
|
||||
.collect::<Vec<_>>()),
|
||||
.map(|x| to_value(&U256::from(x)))
|
||||
.collect::<Vec<_>>())),
|
||||
_ => Err(Error::internal_error()),
|
||||
}
|
||||
}
|
||||
@@ -200,7 +200,7 @@ impl<C, M, S: ?Sized> Ethcore for EthcoreClient<C, M, S> where M: MinerService +
|
||||
|
||||
match self.confirmations_queue {
|
||||
None => Err(errors::signer_disabled()),
|
||||
Some(ref queue) => to_value(&queue.len()),
|
||||
Some(ref queue) => Ok(to_value(&queue.len())),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,12 +208,12 @@ impl<C, M, S: ?Sized> Ethcore for EthcoreClient<C, M, S> where M: MinerService +
|
||||
try!(self.active());
|
||||
try!(expect_no_params(params));
|
||||
|
||||
to_value(&random_phrase(12))
|
||||
Ok(to_value(&random_phrase(12)))
|
||||
}
|
||||
|
||||
fn phrase_to_address(&self, params: Params) -> Result<Value, Error> {
|
||||
try!(self.active());
|
||||
from_params::<(String,)>(params).and_then(|(phrase,)|
|
||||
from_params::<(String,)>(params).map(|(phrase,)|
|
||||
to_value(&H160::from(Brain::new(phrase).generate().unwrap().address()))
|
||||
)
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ impl<C, M> EthcoreSet for EthcoreSetClient<C, M> where
|
||||
try!(self.active());
|
||||
from_params::<(U256,)>(params).and_then(|(gas_price,)| {
|
||||
take_weak!(self.miner).set_minimal_gas_price(gas_price.into());
|
||||
to_value(&true)
|
||||
Ok(to_value(&true))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ impl<C, M> EthcoreSet for EthcoreSetClient<C, M> where
|
||||
try!(self.active());
|
||||
from_params::<(U256,)>(params).and_then(|(target,)| {
|
||||
take_weak!(self.miner).set_gas_floor_target(target.into());
|
||||
to_value(&true)
|
||||
Ok(to_value(&true))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ impl<C, M> EthcoreSet for EthcoreSetClient<C, M> where
|
||||
try!(self.active());
|
||||
from_params::<(U256,)>(params).and_then(|(target,)| {
|
||||
take_weak!(self.miner).set_gas_ceil_target(target.into());
|
||||
to_value(&true)
|
||||
Ok(to_value(&true))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ impl<C, M> EthcoreSet for EthcoreSetClient<C, M> where
|
||||
try!(self.active());
|
||||
from_params::<(Bytes,)>(params).and_then(|(extra_data,)| {
|
||||
take_weak!(self.miner).set_extra_data(extra_data.to_vec());
|
||||
to_value(&true)
|
||||
Ok(to_value(&true))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ impl<C, M> EthcoreSet for EthcoreSetClient<C, M> where
|
||||
try!(self.active());
|
||||
from_params::<(H160,)>(params).and_then(|(author,)| {
|
||||
take_weak!(self.miner).set_author(author.into());
|
||||
to_value(&true)
|
||||
Ok(to_value(&true))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ impl<C, M> EthcoreSet for EthcoreSetClient<C, M> where
|
||||
try!(self.active());
|
||||
from_params::<(usize,)>(params).and_then(|(limit,)| {
|
||||
take_weak!(self.miner).set_transactions_limit(limit);
|
||||
to_value(&true)
|
||||
Ok(to_value(&true))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ impl<C, M> EthcoreSet for EthcoreSetClient<C, M> where
|
||||
try!(self.active());
|
||||
from_params::<(U256,)>(params).and_then(|(limit,)| {
|
||||
take_weak!(self.miner).set_tx_gas_limit(limit.into());
|
||||
to_value(&true)
|
||||
Ok(to_value(&true))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ impl<C, M> EthcoreSet for EthcoreSetClient<C, M> where
|
||||
try!(self.active());
|
||||
from_params::<(String,)>(params).and_then(|(peer,)| {
|
||||
match take_weak!(self.net).add_reserved_peer(peer) {
|
||||
Ok(()) => to_value(&true),
|
||||
Ok(()) => Ok(to_value(&true)),
|
||||
Err(e) => Err(errors::invalid_params("Peer address", e)),
|
||||
}
|
||||
})
|
||||
@@ -128,7 +128,7 @@ impl<C, M> EthcoreSet for EthcoreSetClient<C, M> where
|
||||
try!(self.active());
|
||||
from_params::<(String,)>(params).and_then(|(peer,)| {
|
||||
match take_weak!(self.net).remove_reserved_peer(peer) {
|
||||
Ok(()) => to_value(&true),
|
||||
Ok(()) => Ok(to_value(&true)),
|
||||
Err(e) => Err(errors::invalid_params("Peer address", e)),
|
||||
}
|
||||
})
|
||||
@@ -138,14 +138,14 @@ impl<C, M> EthcoreSet for EthcoreSetClient<C, M> where
|
||||
try!(self.active());
|
||||
try!(expect_no_params(params));
|
||||
take_weak!(self.net).deny_unreserved_peers();
|
||||
to_value(&true)
|
||||
Ok(to_value(&true))
|
||||
}
|
||||
|
||||
fn accept_non_reserved_peers(&self, params: Params) -> Result<Value, Error> {
|
||||
try!(self.active());
|
||||
try!(expect_no_params(params));
|
||||
take_weak!(self.net).accept_unreserved_peers();
|
||||
to_value(&true)
|
||||
Ok(to_value(&true))
|
||||
}
|
||||
|
||||
fn start_network(&self, params: Params) -> Result<Value, Error> {
|
||||
|
||||
@@ -63,9 +63,9 @@ impl<C: 'static, M: 'static> Personal for PersonalClient<C, M> where C: MiningBl
|
||||
try!(self.active());
|
||||
try!(expect_no_params(params));
|
||||
|
||||
self.signer_port
|
||||
Ok(self.signer_port
|
||||
.map(|v| to_value(&v))
|
||||
.unwrap_or_else(|| to_value(&false))
|
||||
.unwrap_or_else(|| to_value(&false)))
|
||||
}
|
||||
|
||||
fn accounts(&self, params: Params) -> Result<Value, Error> {
|
||||
@@ -74,7 +74,7 @@ impl<C: 'static, M: 'static> Personal for PersonalClient<C, M> where C: MiningBl
|
||||
|
||||
let store = take_weak!(self.accounts);
|
||||
let accounts = try!(store.accounts().map_err(|e| errors::internal("Could not fetch accounts.", e)));
|
||||
to_value(&accounts.into_iter().map(Into::into).collect::<Vec<RpcH160>>())
|
||||
Ok(to_value(&accounts.into_iter().map(Into::into).collect::<Vec<RpcH160>>()))
|
||||
}
|
||||
|
||||
fn new_account(&self, params: Params) -> Result<Value, Error> {
|
||||
@@ -83,7 +83,7 @@ impl<C: 'static, M: 'static> Personal for PersonalClient<C, M> where C: MiningBl
|
||||
|(pass, )| {
|
||||
let store = take_weak!(self.accounts);
|
||||
match store.new_account(&pass) {
|
||||
Ok(address) => to_value(&RpcH160::from(address)),
|
||||
Ok(address) => Ok(to_value(&RpcH160::from(address))),
|
||||
Err(e) => Err(errors::account("Could not create account.", e)),
|
||||
}
|
||||
}
|
||||
@@ -96,7 +96,7 @@ impl<C: 'static, M: 'static> Personal for PersonalClient<C, M> where C: MiningBl
|
||||
|(phrase, pass, )| {
|
||||
let store = take_weak!(self.accounts);
|
||||
match store.insert_account(*Brain::new(phrase).generate().unwrap().secret(), &pass) {
|
||||
Ok(address) => to_value(&RpcH160::from(address)),
|
||||
Ok(address) => Ok(to_value(&RpcH160::from(address))),
|
||||
Err(e) => Err(errors::account("Could not create account.", e)),
|
||||
}
|
||||
}
|
||||
@@ -109,7 +109,7 @@ impl<C: 'static, M: 'static> Personal for PersonalClient<C, M> where C: MiningBl
|
||||
|(json, pass, )| {
|
||||
let store = take_weak!(self.accounts);
|
||||
match store.import_presale(json.as_bytes(), &pass).or_else(|_| store.import_wallet(json.as_bytes(), &pass)) {
|
||||
Ok(address) => to_value(&RpcH160::from(address)),
|
||||
Ok(address) => Ok(to_value(&RpcH160::from(address))),
|
||||
Err(e) => Err(errors::account("Could not create account.", e)),
|
||||
}
|
||||
}
|
||||
@@ -174,10 +174,10 @@ impl<C: 'static, M: 'static> Personal for PersonalClient<C, M> where C: MiningBl
|
||||
let other = store.addresses_info().expect("addresses_info always returns Ok; qed");
|
||||
Ok(Value::Object(info.into_iter().chain(other.into_iter()).map(|(a, v)| {
|
||||
let m = map![
|
||||
"name".to_owned() => to_value(&v.name).unwrap(),
|
||||
"meta".to_owned() => to_value(&v.meta).unwrap(),
|
||||
"name".to_owned() => to_value(&v.name),
|
||||
"meta".to_owned() => to_value(&v.meta),
|
||||
"uuid".to_owned() => if let &Some(ref uuid) = &v.uuid {
|
||||
to_value(uuid).unwrap()
|
||||
to_value(uuid)
|
||||
} else {
|
||||
Value::Null
|
||||
}
|
||||
@@ -190,16 +190,16 @@ impl<C: 'static, M: 'static> Personal for PersonalClient<C, M> where C: MiningBl
|
||||
try!(self.active());
|
||||
try!(expect_no_params(params));
|
||||
let store = take_weak!(self.accounts);
|
||||
to_value(&store.list_geth_accounts(false).into_iter().map(Into::into).collect::<Vec<RpcH160>>())
|
||||
Ok(to_value(&store.list_geth_accounts(false).into_iter().map(Into::into).collect::<Vec<RpcH160>>()))
|
||||
}
|
||||
|
||||
fn import_geth_accounts(&self, params: Params) -> Result<Value, Error> {
|
||||
from_params::<(Vec<RpcH160>,)>(params).and_then(|(addresses,)| {
|
||||
let store = take_weak!(self.accounts);
|
||||
to_value(&try!(store
|
||||
Ok(to_value(&try!(store
|
||||
.import_geth_accounts(addresses.into_iter().map(Into::into).collect(), false)
|
||||
.map_err(|e| errors::account("Couldn't import Geth accounts", e))
|
||||
).into_iter().map(Into::into).collect::<Vec<RpcH160>>())
|
||||
).into_iter().map(Into::into).collect::<Vec<RpcH160>>()))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ impl<C: 'static, M: 'static> PersonalSigner for SignerClient<C, M> where C: Mini
|
||||
try!(self.active());
|
||||
try!(expect_no_params(params));
|
||||
let queue = take_weak!(self.queue);
|
||||
to_value(&queue.requests().into_iter().map(From::from).collect::<Vec<ConfirmationRequest>>())
|
||||
Ok(to_value(&queue.requests().into_iter().map(From::from).collect::<Vec<ConfirmationRequest>>()))
|
||||
}
|
||||
|
||||
fn confirm_request(&self, params: Params) -> Result<Value, Error> {
|
||||
@@ -104,7 +104,7 @@ impl<C: 'static, M: 'static> PersonalSigner for SignerClient<C, M> where C: Mini
|
||||
|(id, )| {
|
||||
let queue = take_weak!(self.queue);
|
||||
let res = queue.request_rejected(id.into());
|
||||
to_value(&res.is_some())
|
||||
Ok(to_value(&res.is_some()))
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ impl<C, M> Traces for TracesClient<C, M> where C: BlockChainClient + 'static, M:
|
||||
let client = take_weak!(self.client);
|
||||
let traces = client.filter_traces(filter.into());
|
||||
let traces = traces.map_or_else(Vec::new, |traces| traces.into_iter().map(LocalizedTrace::from).collect());
|
||||
to_value(&traces)
|
||||
Ok(to_value(&traces))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ impl<C, M> Traces for TracesClient<C, M> where C: BlockChainClient + 'static, M:
|
||||
let client = take_weak!(self.client);
|
||||
let traces = client.block_traces(block_number.into());
|
||||
let traces = traces.map_or_else(Vec::new, |traces| traces.into_iter().map(LocalizedTrace::from).collect());
|
||||
to_value(&traces)
|
||||
Ok(to_value(&traces))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ impl<C, M> Traces for TracesClient<C, M> where C: BlockChainClient + 'static, M:
|
||||
let client = take_weak!(self.client);
|
||||
let traces = client.transaction_traces(TransactionID::Hash(transaction_hash.into()));
|
||||
let traces = traces.map_or_else(Vec::new, |traces| traces.into_iter().map(LocalizedTrace::from).collect());
|
||||
to_value(&traces)
|
||||
Ok(to_value(&traces))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ impl<C, M> Traces for TracesClient<C, M> where C: BlockChainClient + 'static, M:
|
||||
};
|
||||
let trace = client.trace(id);
|
||||
let trace = trace.map(LocalizedTrace::from);
|
||||
to_value(&trace)
|
||||
Ok(to_value(&trace))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ impl<C, M> Traces for TracesClient<C, M> where C: BlockChainClient + 'static, M:
|
||||
let request = CallRequest::into(request);
|
||||
let signed = try!(self.sign_call(request));
|
||||
match take_weak!(self.client).call(&signed, block.into(), to_call_analytics(flags)) {
|
||||
Ok(e) => to_value(&TraceResults::from(e)),
|
||||
Ok(e) => Ok(to_value(&TraceResults::from(e))),
|
||||
_ => Ok(Value::Null),
|
||||
}
|
||||
})
|
||||
@@ -141,7 +141,7 @@ impl<C, M> Traces for TracesClient<C, M> where C: BlockChainClient + 'static, M:
|
||||
let raw_transaction = Bytes::to_vec(raw_transaction);
|
||||
match UntrustedRlp::new(&raw_transaction).as_val() {
|
||||
Ok(signed) => match take_weak!(self.client).call(&signed, block.into(), to_call_analytics(flags)) {
|
||||
Ok(e) => to_value(&TraceResults::from(e)),
|
||||
Ok(e) => Ok(to_value(&TraceResults::from(e))),
|
||||
_ => Ok(Value::Null),
|
||||
},
|
||||
Err(e) => Err(errors::invalid_params("Transaction is not valid RLP", e)),
|
||||
@@ -154,7 +154,7 @@ impl<C, M> Traces for TracesClient<C, M> where C: BlockChainClient + 'static, M:
|
||||
from_params::<(H256, _)>(params)
|
||||
.and_then(|(transaction_hash, flags)| {
|
||||
match take_weak!(self.client).replay(TransactionID::Hash(transaction_hash.into()), to_call_analytics(flags)) {
|
||||
Ok(e) => to_value(&TraceResults::from(e)),
|
||||
Ok(e) => Ok(to_value(&TraceResults::from(e))),
|
||||
_ => Ok(Value::Null),
|
||||
}
|
||||
})
|
||||
|
||||
@@ -37,7 +37,7 @@ impl Web3 for Web3Client {
|
||||
}
|
||||
|
||||
fn sha3(&self, params: Params) -> Result<Value, Error> {
|
||||
from_params::<(Bytes,)>(params).and_then(
|
||||
from_params::<(Bytes,)>(params).map(
|
||||
|(data,)| {
|
||||
let Bytes(ref vec) = data;
|
||||
let sha3 = vec.sha3();
|
||||
|
||||
Reference in New Issue
Block a user