Browse Source

Merge pull request #2791 from LefterisJP/web3DefaultGasPrice

Properly set default Gas Price in Web3 server
cl-refactor
Gav Wood 9 years ago
parent
commit
eef8bfe6aa
  1. 2
      libethereum/Client.h
  2. 1
      libethereum/ClientBase.h
  3. 2
      libethereum/Interface.h
  4. 38
      libweb3jsonrpc/WebThreeStubServerBase.cpp
  5. 1
      libweb3jsonrpc/WebThreeStubServerBase.h

2
libethereum/Client.h

@ -98,6 +98,8 @@ public:
/// Get the remaining gas limit in this block.
virtual u256 gasLimitRemaining() const override { return m_postMine.gasLimitRemaining(); }
/// Get the gas bid price
virtual u256 gasBidPrice() const override { return m_gp->bid(); }
// [PRIVATE API - only relevant for base clients, not available in general]
/// Get the block.

1
libethereum/ClientBase.h

@ -148,6 +148,7 @@ public:
using Interface::addresses;
virtual Addresses addresses(BlockNumber _block) const override;
virtual u256 gasLimitRemaining() const override;
virtual u256 gasBidPrice() const override { return c_defaultGasPrice; }
/// Get the coinbase address
virtual Address address() const override;

2
libethereum/Interface.h

@ -190,6 +190,8 @@ public:
/// Get the remaining gas limit in this block.
virtual u256 gasLimitRemaining() const = 0;
// Get the gas bidding price
virtual u256 gasBidPrice() const = 0;
// [MINING API]:

38
libweb3jsonrpc/WebThreeStubServerBase.cpp

@ -239,19 +239,22 @@ string WebThreeStubServerBase::eth_getCode(string const& _address, string const&
}
}
void WebThreeStubServerBase::setTransactionDefaults(TransactionSkeleton & _t)
{
if (!_t.from)
_t.from = m_ethAccounts->defaultTransactAccount();
if (_t.gasPrice == UndefinedU256)
_t.gasPrice = client()->gasBidPrice();
if (_t.gas == UndefinedU256)
_t.gas = min<u256>(client()->gasLimitRemaining() / 5, client()->balanceAt(_t.from) / _t.gasPrice);
}
string WebThreeStubServerBase::eth_sendTransaction(Json::Value const& _json)
{
try
{
TransactionSkeleton t = toTransactionSkeleton(_json);
if (!t.from)
t.from = m_ethAccounts->defaultTransactAccount();
if (t.gasPrice == UndefinedU256)
t.gasPrice = 10 * dev::eth::szabo; // TODO: should be determined by user somehow.
if (t.gas == UndefinedU256)
t.gas = min<u256>(client()->gasLimitRemaining() / 5, client()->balanceAt(t.from) / t.gasPrice);
setTransactionDefaults(t);
return toJS(m_ethAccounts->authenticate(t));
}
catch (...)
@ -265,14 +268,7 @@ string WebThreeStubServerBase::eth_signTransaction(Json::Value const& _json)
try
{
TransactionSkeleton t = toTransactionSkeleton(_json);
if (!t.from)
t.from = m_ethAccounts->defaultTransactAccount();
if (t.gasPrice == UndefinedU256)
t.gasPrice = 10 * dev::eth::szabo; // TODO: should be determined by user somehow.
if (t.gas == UndefinedU256)
t.gas = min<u256>(client()->gasLimitRemaining() / 5, client()->balanceAt(t.from) / t.gasPrice);
setTransactionDefaults(t);
m_ethAccounts->authenticate(t);
return toJS((t.creation ? Transaction(t.value, t.gasPrice, t.gas, t.data) : Transaction(t.value, t.gasPrice, t.gas, t.to, t.data)).sha3(WithoutSignature));
@ -312,15 +308,7 @@ string WebThreeStubServerBase::eth_call(Json::Value const& _json, string const&
try
{
TransactionSkeleton t = toTransactionSkeleton(_json);
if (!t.from)
t.from = m_ethAccounts->defaultTransactAccount();
// if (!m_accounts->isRealAccount(t.from))
// return ret;
if (t.gasPrice == UndefinedU256)
t.gasPrice = 10 * dev::eth::szabo;
if (t.gas == UndefinedU256)
t.gas = client()->gasLimitRemaining();
setTransactionDefaults(t);
return toJS(client()->call(t.from, t.value, t.to, t.data, t.gas, t.gasPrice, jsToBlockNumber(_blockNumber), FudgeFactor::Lenient).output);
}
catch (...)

1
libweb3jsonrpc/WebThreeStubServerBase.h

@ -193,6 +193,7 @@ public:
protected:
void requires(std::string const& _session, Privilege _l) const { if (!hasPrivilegeLevel(_session, _l)) throw jsonrpc::JsonRpcException("Invalid privileges"); }
void setTransactionDefaults(eth::TransactionSkeleton & _t);
virtual bool hasPrivilegeLevel(std::string const& _session, Privilege _l) const { (void)_session; (void)_l; return false; }
virtual dev::eth::Interface* client() = 0;

Loading…
Cancel
Save