38 static const int64_t c_maxGasEstimate = 50000000;
42 prepareForTransaction();
47 ts.
nonce = max<u256>(postSeal().transactionsFrom(ts.
from), m_tq.maxNonce(ts.
from));
51 ts.
gas = min<u256>(gasLimitRemaining() / 5, balanceAt(ts.
from) / ts.
gasPrice);
65 Block temp = block(_blockNumber);
68 u256 gasPrice = _gasPrice ==
Invalid256 ? gasBidPrice() : _gasPrice;
69 Transaction t(_value, gasPrice, gas, _dest, _data, nonce);
71 if (_ff == FudgeFactor::Lenient)
87 Block temp = block(_blockNumber);
92 if (_ff == FudgeFactor::Lenient)
107 int64_t upperBound = _maxGas;
108 if (upperBound ==
Invalid256 || upperBound > c_maxGasEstimate)
109 upperBound = c_maxGasEstimate;
110 int64_t lowerBound = Transaction::baseGasRequired(!_dest, &_data,
EVMSchedule());
111 Block bk = block(_blockNumber);
112 u256 gasPrice = _gasPrice ==
Invalid256 ? gasBidPrice() : _gasPrice;
116 while (upperBound != lowerBound)
118 int64_t mid = (lowerBound + upperBound) / 2;
122 t =
Transaction(_value, gasPrice, mid, _dest, _data, n);
130 er = tempState.execute(env, *bc().sealEngine(), t, Permanence::Reverted).first;
131 if (er.
excepted == TransactionException::OutOfGas ||
132 er.
excepted == TransactionException::OutOfGasBase ||
133 er.
excepted == TransactionException::OutOfGasIntrinsic ||
135 er.
excepted == TransactionException::BadJumpDestination)
136 lowerBound = lowerBound == mid ? upperBound : mid;
140 upperBound = upperBound == mid ? lowerBound : mid;
149 return make_pair(upperBound, good ? lastGood : er);
160 return bc().attemptImport(_block, preSeal().db()).first;
165 return block(_block).balance(_a);
170 return block(_block).transactionsFrom(_a);
175 return block(_block).storage(_a, _l);
180 return block(_block).storageRoot(_a);
185 return block(_block).code(_a);
190 return block(_block).codeHash(_a);
195 return block(_block).storage(_a);
204 Guard l(x_filtersWatches);
205 f = m_filters.at(m_watches.at(_watchId).id).filter;
217 unsigned begin =
min(bc().number() + 1, (
unsigned)numberFromHash(_f.
latest()));
218 unsigned end =
min(bc().number(),
min(begin, (
unsigned)numberFromHash(_f.
earliest())));
221 if (begin > bc().number())
223 Block temp = postSeal();
224 for (
unsigned i = 0; i < temp.
pending().size(); ++i)
229 for (
unsigned j = 0; j < le.size(); ++j)
232 begin = bc().number();
239 unsigned ancestorIndex;
240 tie(blocks, ancestor, ancestorIndex) = bc().treeRoute(_f.
earliest(), _f.
latest(),
false);
242 for (
size_t i = 0; i < ancestorIndex; i++)
243 prependLogsFromBlock(_f, blocks[i], BlockPolarity::Dead, ret);
257 end =
min(end, (
unsigned)numberFromHash(ancestor) + 1);
260 set<unsigned> matchingBlocks;
263 for (
auto u: bc().withBlockBloom(i, end, begin))
264 matchingBlocks.insert(u);
267 for (
unsigned i = end; i <= begin; i++)
268 matchingBlocks.insert(i);
270 for (
auto n: matchingBlocks)
271 prependLogsFromBlock(_f, bc().numberHash(n), BlockPolarity::Live, ret);
273 reverse(ret.begin(), ret.end());
279 auto receipts = bc().receipts(_blockHash).receipts;
280 for (
size_t i = 0; i < receipts.size(); i++)
283 auto th = transaction(_blockHash, i).sha3();
285 for (
unsigned j = 0; j < le.size(); ++j)
294 Guard l(x_filtersWatches);
295 if (!m_filters.count(h))
298 m_filters.insert(make_pair(h, _f));
301 return installWatch(h, _r);
308 Guard l(x_filtersWatches);
309 ret = m_watches.size() ? m_watches.rbegin()->first + 1 : 0;
311 cwatch <<
"+++" << ret << _h;
313 #if INITIAL_STATE_AS_CHANGES 316 ch.push_back(InitialChange);
318 Guard l(x_filtersWatches);
319 swap(m_watches[ret].changes,
ch);
325 bool ClientBase::uninstallWatch(
unsigned _i)
329 Guard l(x_filtersWatches);
331 auto it = m_watches.find(_i);
332 if (it == m_watches.end())
334 auto id = it->second.id;
337 auto fit = m_filters.find(
id);
338 if (fit != m_filters.end())
339 if (!--fit->second.refCount)
341 cwatch <<
"*X*" << fit->first <<
":" << fit->second.filter;
342 m_filters.erase(fit);
349 Guard l(x_filtersWatches);
352 auto& w = m_watches.at(_watchId);
355 w.lastPoll = chrono::system_clock::now();
361 Guard l(x_filtersWatches);
365 auto& w = m_watches.at(_watchId);
369 w.lastPoll = chrono::system_clock::now();
376 if (_hash == PendingBlockHash)
377 return preSeal().info();
383 return bc().details(_hash);
388 return Transaction(bc().transaction(_transactionHash), CheckTransaction::Cheap);
393 std::pair<h256, unsigned> tl = bc().transactionLocation(_transactionHash);
394 return localisedTransaction(tl.first, tl.second);
399 auto bl = bc().block(_blockHash);
401 if (_i < b[1].itemCount())
415 return bc().transactionReceipt(_transactionHash);
420 std::pair<h256, unsigned> tl = bc().transactionLocation(_transactionHash);
427 numberFromHash(tl.first),
432 pair<h256, unsigned> ClientBase::transactionLocation(
h256 const& _transactionHash)
const 434 return bc().transactionLocation(_transactionHash);
439 auto bl = bc().block(_blockHash);
442 for (
unsigned i = 0; i < b[1].
itemCount(); i++)
443 res.emplace_back(b[1][i].
data(), CheckTransaction::Cheap);
449 return bc().transactionHashes(_blockHash);
454 auto bl = bc().block(_blockHash);
456 if (_i < b[2].itemCount())
464 return bc().uncleHashes(_blockHash);
467 unsigned ClientBase::transactionCount(
h256 _blockHash)
const 469 auto bl = bc().block(_blockHash);
474 unsigned ClientBase::uncleCount(
h256 _blockHash)
const 476 auto bl = bc().block(_blockHash);
481 unsigned ClientBase::number()
const 483 return bc().number();
488 return postSeal().pending();
491 h256s ClientBase::pendingHashes()
const 493 return h256s() + postSeal().pendingHashes();
498 return postSeal().info();
503 auto pm = postSeal().info();
504 auto li = Interface::blockDetails(LatestBlock);
505 return BlockDetails((
unsigned)pm.number(), li.totalDifficulty + pm.difficulty(), pm.parentHash(),
h256s{});
511 for (
auto const& i: block(_block).addresses())
512 ret.push_back(i.first);
516 u256 ClientBase::gasLimitRemaining()
const 518 return postSeal().gasLimitRemaining();
523 return preSeal().author();
528 if (_number == PendingBlock)
530 if (_number == LatestBlock)
531 return bc().currentHash();
532 return bc().numberHash(_number);
537 if (_blockHash == PendingBlockHash)
538 return bc().number() + 1;
539 else if (_blockHash == LatestBlockHash)
540 return bc().number();
541 else if (_blockHash == EarliestBlockHash)
543 return bc().number(_blockHash);
546 int ClientBase::compareBlockHashes(
h256 _h1,
h256 _h2)
const 558 bool ClientBase::isKnown(
h256 const& _hash)
const 560 return _hash == PendingBlockHash ||
561 _hash == LatestBlockHash ||
562 _hash == EarliestBlockHash ||
568 return _block == PendingBlock ||
569 _block == LatestBlock ||
570 bc().numberHash(_block) !=
h256();
573 bool ClientBase::isKnownTransaction(
h256 const& _transactionHash)
const 575 return bc().isKnownTransaction(_transactionHash);
578 bool ClientBase::isKnownTransaction(
h256 const& _blockHash,
unsigned _i)
const 580 return isKnown(_blockHash) && block(_blockHash).pending().size() > _i;
585 if (_h == PendingBlock)
587 else if (_h == LatestBlock)
589 return block(bc().numberHash(_h));
CodeDeposit codeDeposit
Failed if an attempted deposit failed due to lack of gas.
bool matches(LogBloom _bloom) const
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
State const & state() const
Get the backing state object.
Address from() const
Synonym for safeSender().
void swap(dev::eth::Watch &_a, dev::eth::Watch &_b)
bytesConstRef data() const
The bare data of the RLP.
std::vector< Transaction > Transactions
Nice name for vector of Transaction.
std::hash for asio::adress
u256 transactionsFrom(Address const &_address) const
Get the number of transactions a particular address has sent (used for the transaction nonce)...
void setGasLimit(int64_t _v)
Description of the result of executing a transaction.
Model of an Ethereum state, essentially a facade for the trie.
TransactionReceipt const & receipt(unsigned _i) const
Get the transaction receipt for the transaction of the given index.
std::vector< LocalisedLogEntry > LocalisedLogEntries
h256 latest() const
hash of latest block which should be filtered
Active model of a block within the block chain.
std::lock_guard< std::mutex > Guard
std::vector< byte > bytes
h256 earliest() const
hash of earliest block which should be filtered
Fixed-size raw-byte array container type, with an API optimised for storing hashes.
h256 sha3(IncludeSignature _sig=WithSignature) const
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
h160s Addresses
A vector of Ethereum addresses.
Transactions const & pending() const
Get the list of pending transactions.
Encodes a transaction, ready to be exported to or freshly imported from RLP.
Address toAddress(Public const &_public)
Convert a public key to address.
TransactionException excepted
std::function< void(GasEstimationProgress const &)> GasEstimationCallback
State & mutableState()
Get a mutable State object which is backing this block.
LastHashes lastHashes(u256 _currentBlockNumber)
void forceSender(Address const &_a)
Force the sender to a particular value. This will result in an invalid transaction RLP...
virtual void addBalance(Address const &_id, u256 const &_amount)
Add some amount to balance.
ExecutionResult execute(LastHashes const &_lh, Transaction const &_t, Permanence _p=Permanence::Committed, OnOpFunc const &_onOp=OnOpFunc())
Execute a given transaction.
bool isRangeFilter() const
Range filter is a filter which doesn't care about addresses or topics Matches are all entries from ea...
std::vector< h256 > h256s
uint32_t ch(uint32_t x, uint32_t y, uint32_t z)
Class for interpreting Recursive Linear-Prefix Data.
BlockHeader const & info() const
Get the header information on the present block.
std::vector< LogEntry > LogEntries
std::vector< LogBloom > bloomPossibilities() const