implementation of eth_estimateGas

This commit is contained in:
debris 2016-03-20 10:29:21 +01:00
parent fef8237701
commit 7c6f0e472d
1 changed files with 20 additions and 0 deletions

View File

@ -418,6 +418,26 @@ impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM>
}
})
}
fn estimate_gas(&self, params: Params) -> Result<Value, Error> {
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.