From 7c6f0e472d8feaa3642e886cb3bbea8e340171d9 Mon Sep 17 00:00:00 2001 From: debris Date: Sun, 20 Mar 2016 10:29:21 +0100 Subject: [PATCH] implementation of eth_estimateGas --- rpc/src/v1/impls/eth.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index 3daa6275c..c66f04355 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -418,6 +418,26 @@ impl Eth for EthClient } }) } + + fn estimate_gas(&self, params: Params) -> Result { + from_params::<(TransactionRequest, BlockNumber)>(params) + .and_then(|(transaction_request, _block_number)| { + let accounts = take_weak!(self.accounts); + match accounts.account_secret(&transaction_request.from) { + Ok(secret) => { + let client = take_weak!(self.client); + + let transaction: EthTransaction = transaction_request.into(); + let signed_transaction = transaction.sign(&secret); + + to_value(&client.call(&signed_transaction) + .map(|e| e.gas_used) + .unwrap_or(U256::zero())) + }, + Err(_) => { to_value(&U256::zero()) } + } + }) + } } /// Eth filter rpc implementation.