Use sensible gas price.

This commit is contained in:
Gav Wood
2016-03-28 18:53:33 +02:00
parent 9592ccc0df
commit 5d626c7dd3
4 changed files with 25 additions and 14 deletions

View File

@@ -31,7 +31,6 @@ use ethcore::client::*;
use ethcore::block::IsBlock;
use ethcore::views::*;
use ethcore::ethereum::Ethash;
use ethcore::ethereum::denominations::shannon;
use ethcore::transaction::{Transaction as EthTransaction, SignedTransaction, Action};
use self::ethash::SeedHashCompute;
use v1::traits::{Eth, EthFilter};
@@ -44,10 +43,6 @@ fn default_gas() -> U256 {
U256::from(21_000)
}
fn default_gas_price() -> U256 {
shannon() * U256::from(20)
}
/// Eth rpc implementation.
pub struct EthClient<C, S, A, M, EM = ExternalMiner>
where C: BlockChainClient,
@@ -173,16 +168,18 @@ impl<C, S, A, M, EM> EthClient<C, S, A, M, EM>
}
}
fn sign_call(client: &Arc<C>, request: CallRequest) -> SignedTransaction {
fn sign_call(&self, request: CallRequest) -> Result<SignedTransaction, Error> {
let client = take_weak!(self.client);
let miner = take_weak!(self.miner);
let from = request.from.unwrap_or(Address::zero());
EthTransaction {
Ok(EthTransaction {
nonce: request.nonce.unwrap_or_else(|| client.nonce(&from)),
action: request.to.map_or(Action::Create, Action::Call),
gas: request.gas.unwrap_or_else(default_gas),
gas_price: request.gas_price.unwrap_or_else(default_gas_price),
gas_price: request.gas_price.unwrap_or_else(|| miner.sensible_gas_price()),
value: request.value.unwrap_or_else(U256::zero),
data: request.data.map_or_else(Vec::new, |d| d.to_vec())
}.fake_sign(from)
}.fake_sign(from))
}
fn dispatch_transaction(&self, signed_transaction: SignedTransaction, raw_transaction: Vec<u8>) -> Result<Value, Error> {
@@ -290,7 +287,7 @@ impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM>
fn gas_price(&self, params: Params) -> Result<Value, Error> {
match params {
Params::None => to_value(&default_gas_price()),
Params::None => to_value(&take_weak!(self.miner).sensible_gas_price()),
_ => Err(Error::invalid_params())
}
}
@@ -485,11 +482,12 @@ impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM>
Ok(secret) => {
let signed_transaction = {
let client = take_weak!(self.client);
let miner = take_weak!(self.miner);
EthTransaction {
nonce: request.nonce.unwrap_or_else(|| client.nonce(&request.from)),
action: request.to.map_or(Action::Create, Action::Call),
gas: request.gas.unwrap_or_else(default_gas),
gas_price: request.gas_price.unwrap_or_else(default_gas_price),
gas_price: request.gas_price.unwrap_or_else(|| miner.sensible_gas_price()),
value: request.value.unwrap_or_else(U256::zero),
data: request.data.map_or_else(Vec::new, |d| d.to_vec()),
}.sign(&secret)
@@ -515,8 +513,8 @@ impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM>
fn call(&self, params: Params) -> Result<Value, Error> {
from_params_discard_second(params).and_then(|(request, )| {
let signed = try!(self.sign_call(request));
let client = take_weak!(self.client);
let signed = Self::sign_call(&client, request);
let output = client.call(&signed).map(|e| Bytes(e.output)).unwrap_or(Bytes::new(vec![]));
to_value(&output)
})
@@ -524,8 +522,8 @@ 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_discard_second(params).and_then(|(request, )| {
let signed = try!(self.sign_call(request));
let client = take_weak!(self.client);
let signed = Self::sign_call(&client, request);
let used = client.call(&signed).map(|res| res.gas_used + res.refunded).unwrap_or(From::from(0));
to_value(&used)
})