3 #include <validation.h> 12 State(_accountStartNonce, _db, _bs) {
32 bool voutLimit =
false;
36 if (isChannelVisible<VMTraceChannel>())
37 onOp = Executive::simpleTrace();
53 startGasUsed = _envInfo.
gasUsed();
62 if (_p == Permanence::Reverted) {
67 if(res.
excepted == TransactionException::None) {
76 std::unordered_map<dev::Address, Vin>
vins = ctx.
createVin(*tx);
85 commit(removeEmptyAccounts ? State::CommitBehaviour::RemoveEmptyAccounts : State::CommitBehaviour::KeepEmptyAccounts);
132 std::unordered_map<dev::Address, Vin> ret;
135 ret[i.first] = i.second;
137 for (
auto& i : addrs) {
138 if (cacheUTXO.find(i.first) == cacheUTXO.end() &&
vin(i.first))
139 ret[i.first] = *
vin(i.first);
148 transfers.push_back({_from, _to, _value});
160 std::string stateBack =
stateUTXO.at(_addr);
161 if (stateBack.empty())
166 std::piecewise_construct,
167 std::forward_as_tuple(_addr),
168 std::forward_as_tuple(
Vin{state[0].
toHash<
dev::h256>(), state[1].toInt<uint32_t>(), state[2].toInt<dev::u256>(), state[3].toInt<uint8_t>()})
170 return &i.first->second;
194 if (
auto v =
vin(_addr))
208 if (!
a->isDirty() &&
a->isEmpty())
214 a->addBalance(_amount);
231 std::vector<unsigned char> txIdAndVout(hashTXid.
begin(), hashTXid.
end());
232 std::vector<unsigned char> voutNumberChrs;
233 if (voutNumberChrs.size() <
sizeof(voutNumber))voutNumberChrs.resize(
sizeof(voutNumber));
234 std::memcpy(voutNumberChrs.data(), &voutNumber,
sizeof(voutNumber));
235 txIdAndVout.insert(txIdAndVout.end(),voutNumberChrs.begin(),voutNumberChrs.end());
237 std::vector<unsigned char> SHA256TxVout(32);
238 CSHA256().
Write(txIdAndVout.data(), txIdAndVout.size()).Finalize(SHA256TxVout.data());
240 std::vector<unsigned char> hashTxIdAndVout(20);
241 CRIPEMD160().
Write(SHA256TxVout.data(), SHA256TxVout.size()).Finalize(hashTxIdAndVout.data());
258 for(
auto& v : vins) {
259 Vin* vi =
const_cast<Vin*
>(
vin(v.first));
262 vi->
hash = v.second.hash;
263 vi->
nVout = v.second.nVout;
264 vi->
value = v.second.value;
265 vi->
alive = v.second.alive;
266 }
else if(v.second.alive > 0) {
273 std::stringstream ss;
281 calculatePlusAndMinus();
282 if(!createNewBalances())
285 tx.
vin = createVins();;
286 tx.
vout = createVout();
291 std::unordered_map<dev::Address, Vin>
vins;
292 for(
auto&
b : balances) {
293 if(
b.first == transaction.sender())
307 if(!
vins.count(ti.from)) {
308 if(
auto a = state->vin(ti.from))
310 if(ti.from == transaction.sender() && transaction.value() > 0) {
311 vins[ti.from] =
Vin{transaction.getHashWith(), transaction.getNVout(), transaction.
value(), 1};
315 if(!
vins.count(ti.to)) {
316 if(
auto a = state->vin(ti.to))
324 if(!plusMinusInfo.count(ti.from)) {
325 plusMinusInfo[ti.from] = std::make_pair(0, ti.value);
327 plusMinusInfo[ti.from] = std::make_pair(plusMinusInfo[ti.from].first, plusMinusInfo[ti.from].second + ti.value);
330 if(!plusMinusInfo.count(ti.to)) {
331 plusMinusInfo[ti.to] = std::make_pair(ti.value, 0);
333 plusMinusInfo[ti.to] = std::make_pair(plusMinusInfo[ti.to].first + ti.value, plusMinusInfo[ti.to].second);
339 for(
auto& p : plusMinusInfo) {
341 if((
vins.count(p.first) &&
vins[p.first].alive) || (!
vins[p.first].alive && !checkDeleteAddress(p.first))) {
342 balance =
vins[p.first].value;
344 balance += p.second.first;
345 if(balance < p.second.second)
347 balance -= p.second.second;
354 std::vector<CTxIn> ins;
355 for(
auto& v :
vins) {
356 if((v.second.value > 0 && v.second.alive) || (v.second.value > 0 && !vins[v.first].alive && !checkDeleteAddress(v.first)))
364 std::vector<CTxOut> outs;
365 for(
auto&
b : balances) {
368 auto*
a = state->account(
b.first);
369 if(
a &&
a->isAlive()) {
379 if(count > MAX_CONTRACT_VOUTS) {
388 return deleteAddresses.count(addr) != 0;
bool addressInUse(Address const &_address) const
Check if the address is in use.
u256 balance(Address const &_id) const
Get an account's balance.
CSHA256 & Write(const unsigned char *data, size_t len)
void updateUTXO(const std::unordered_map< dev::Address, Vin > &vins)
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
void commit(CommitBehaviour _commitBehaviour)
Commit all changes waiting in the address cache to the DB.
ChainOperationParams const & chainParams() const
bytes rlp(_T _t)
Export a single item in RLP format, returning a byte array.
Vin const * vin(dev::Address const &_a) const
static OverlayDB openDB(std::string const &_path, h256 const &_genesisHash, WithExisting _we=WithExisting::Trust)
Open a DB - useful for passing into the constructor & keeping for other states that are necessary...
Models the state of a single Ethereum account.
static VersionVM GetEVMDefault()
const Consensus::Params & GetConsensus() const
h160 Address
An Ethereum address: 20 bytes.
Address const & author() const
void addBalance(dev::Address const &_id, dev::u256 const &_amount)
Add some amount to balance.
Address const & sender() const
std::hash for asio::adress
assert(len-trim+(2 *lenIndices)<=WIDTH)
void kill(dev::Address _addr)
Delete an account (used for processing suicides).
Different view on a GenericTrieDB that can use different key types.
u256 const & gasUsed() const
std::vector< CTxIn > createVins()
Description of the result of executing a transaction.
u256 const & number() const
Model of an Ethereum state, essentially a facade for the trie.
std::shared_ptr< const CTransaction > CTransactionRef
bool go(OnOpFunc const &_onOp=OnOpFunc())
Executes (or continues execution of) the VM.
u256 const & requireAccountStartNonce() const
void revert()
Revert all changes made to the state by this execution.
int nFixUTXOCacheHFHeight
void removeEmptyAccounts()
Turns all "touched" empty accounts into non-alive accounts.
void createAccount(Address const &_address, Account const &&_account)
int64_t CAmount
Amount in lius (Can be negative)
dev::Address createFascAddress(dev::h256 hashTx, uint32_t voutNumber)
std::vector< TransferInfo > transfers
std::unordered_map< dev::Address, Vin > createVin(const CTransaction &tx)
_N toHash(int _flags=Strict) const
int Height() const
Return the maximal height in the chain.
Base class for all exceptions.
dev::h256 uintToh256(const uint256 &in)
An input of a transaction.
void deleteAccounts(std::set< dev::Address > &addrs)
void finalize()
Finalise a transaction previously set up with initialize().
std::vector< detail::Change > m_changeLog
std::unordered_map< dev::Address, Vin > cacheUTXO
Fixed-size raw-byte array container type, with an API optimised for storing hashes.
std::function< void(uint64_t, uint64_t, Instruction, bigint, bigint, bigint, VM *, ExtVMFace const *)> OnOpFunc
std::unordered_map< Address, u256 > addresses() const
An output of a transaction.
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
Message-call/contract-creation executor; useful for executing transactions.
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
Parameters that influence chain consensus.
std::unordered_map< Address, Account > m_cache
Our address cache. This stores the states of each address that has (or at least might have) been chan...
std::vector< CTxOut > vout
LogEntries const & logs() const
TransactionException excepted
CRIPEMD160 & Write(const unsigned char *data, size_t len)
h256 rootHash() const
The hash of the root of our state tree.
std::unordered_map< dev::Address, Vin > vins() const
void kill()
Kill this account. Useful for the suicide opcode. Following this call, isAlive() returns false...
void initialize(bytesConstRef _transaction)
Initializes the executive for evaluating a transaction. You must call finalize() at some point follow...
u256 u256Param(std::string const &_name) const
Convenience method to get an otherParam as a u256 int.
std::vector< CTxOut > createVout()
std::set< Address > deleteAddresses
bool execute()
Begins execution of a transaction.
const CChainParams & Params()
Return the currently selected parameters.
Serialized script, used inside transaction inputs and outputs.
void * memcpy(void *a, const void *b, size_t c)
CTransaction createCondensingTX()
void calculatePlusAndMinus()
dev::eth::SecureTrieDB< dev::Address, dev::OverlayDB > stateUTXO
ResultExecute execute(dev::eth::EnvInfo const &_envInfo, dev::eth::SealEngineFace const &_sealEngine, FascTransaction const &_t, dev::eth::Permanence _p=dev::eth::Permanence::Committed, dev::eth::OnOpFunc const &_onOp=OnOpFunc())
bool sha3(bytesConstRef _input, bytesRef o_output)
Calculate SHA3-256 hash of the given input and load it into the given output.
VersionVM getVersion() const
void transferBalance(dev::Address const &_from, dev::Address const &_to, dev::u256 const &_value)
Transfers "the balance _value between two accounts.
A mutable version of CTransaction.
const uint256 & GetHash() const
std::vector< unsigned char > valtype
The basic transaction that is broadcasted on the network and contained in blocks. ...
Account const * account(Address const &_addr) const
Account was touched for the first time.
A hasher class for SHA-256.
dev::h256 getHashWith() const
void printfErrorLog(const dev::eth::TransactionException er)
Class for interpreting Recursive Linear-Prefix Data.
void subBalance(Address const &_addr, u256 const &_value)
Subtract the _value amount from the balance of _addr account.
uint256 h256Touint(const dev::h256 &in)
uint32_t getNVout() const
dev::AddressHash commit(std::unordered_map< dev::Address, Vin > const &_cache, dev::eth::SecureTrieDB< dev::Address, DB > &_state, std::unordered_map< dev::Address, dev::eth::Account > const &_cacheAcc)
std::vector< LogEntry > LogEntries
A hasher class for RIPEMD-160.
void setResultRecipient(ExecutionResult &_res)
Collect execution results in the result storage provided.
Address receiveAddress() const
bool checkDeleteAddress(dev::Address addr)
TransactionException toTransactionException(Exception const &_e)