diff --git a/libethereum/Client.h b/libethereum/Client.h index c761e3d0f..1d6b072ce 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -235,6 +235,9 @@ public: /// Get the fee associated for a transaction with the given data. static u256 txGas(uint _dataCount, u256 _gas = 0) { return c_txDataGas * _dataCount + c_txGas + _gas; } + /// Get the remaining gas limit in this block. + u256 gasLimitRemaining() const { return m_postMine.gasLimitRemaining(); } + // [PRIVATE API - only relevant for base clients, not available in general] eth::State state(unsigned _txi, h256 _block) const; diff --git a/libethereum/State.h b/libethereum/State.h index 9f014f0ab..da8e099d1 100644 --- a/libethereum/State.h +++ b/libethereum/State.h @@ -192,6 +192,9 @@ public: u256 execute(bytes const& _rlp, bytes* o_output = nullptr, bool _commit = true) { return execute(&_rlp, o_output, _commit); } u256 execute(bytesConstRef _rlp, bytes* o_output = nullptr, bool _commit = true); + /// Get the remaining gas limit in this block. + u256 gasLimitRemaining() const { return m_currentBlock.gasLimit - gasUsed(); } + /// Check if the address is in use. bool addressInUse(Address _address) const; diff --git a/libqethereum/QEthereum.cpp b/libqethereum/QEthereum.cpp index 1ae2fef21..06a6a485b 100644 --- a/libqethereum/QEthereum.cpp +++ b/libqethereum/QEthereum.cpp @@ -413,7 +413,7 @@ void QEthereum::doTransact(QString _json) if (!t.gasPrice) t.gasPrice = 10 * eth::szabo; if (!t.gas) - t.gas = client()->balanceAt(KeyPair(t.from).address()) / t.gasPrice; + t.gas = min(client()->gasLimitRemaining(), client()->balanceAt(KeyPair(t.from).address()) / t.gasPrice); if (t.to) client()->transact(t.from, t.value, t.to, t.data, t.gas, t.gasPrice); else