2019-05-27 13:51:49 +00:00
|
|
|
// Copyright 2019 The go-ethereum Authors
|
2015-07-22 16:48:40 +00:00
|
|
|
// This file is part of the go-ethereum library.
|
2015-07-07 00:54:22 +00:00
|
|
|
//
|
2015-07-23 16:35:11 +00:00
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
2015-07-07 00:54:22 +00:00
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
2015-07-22 16:48:40 +00:00
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
2015-07-07 00:54:22 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-07-22 16:48:40 +00:00
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2015-07-07 00:54:22 +00:00
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
2015-07-22 16:48:40 +00:00
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
2015-07-07 00:54:22 +00:00
|
|
|
|
2014-10-31 13:43:14 +00:00
|
|
|
package state
|
2014-07-22 09:54:48 +00:00
|
|
|
|
|
|
|
import (
|
2015-02-17 12:10:18 +00:00
|
|
|
"bytes"
|
2014-07-22 09:54:48 +00:00
|
|
|
"fmt"
|
2015-12-11 00:29:41 +00:00
|
|
|
"io"
|
2014-07-29 22:31:15 +00:00
|
|
|
"math/big"
|
|
|
|
|
2020-05-25 11:12:25 +00:00
|
|
|
"github.com/holiman/uint256"
|
2021-05-20 18:25:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/common"
|
|
|
|
"github.com/ledgerwatch/erigon/core/types/accounts"
|
|
|
|
"github.com/ledgerwatch/erigon/crypto"
|
|
|
|
"github.com/ledgerwatch/erigon/rlp"
|
|
|
|
"github.com/ledgerwatch/erigon/turbo/trie"
|
2014-07-22 09:54:48 +00:00
|
|
|
)
|
|
|
|
|
2016-02-21 18:40:27 +00:00
|
|
|
var emptyCodeHash = crypto.Keccak256(nil)
|
2019-05-27 13:51:49 +00:00
|
|
|
var emptyCodeHashH = common.BytesToHash(emptyCodeHash)
|
2015-12-11 00:29:41 +00:00
|
|
|
|
2014-07-22 09:54:48 +00:00
|
|
|
type Code []byte
|
|
|
|
|
2019-05-25 21:52:10 +00:00
|
|
|
func (c Code) String() string {
|
|
|
|
return string(c) //strings.Join(Disassemble(c), " ")
|
2014-07-22 09:54:48 +00:00
|
|
|
}
|
|
|
|
|
2020-05-25 11:12:25 +00:00
|
|
|
type Storage map[common.Hash]uint256.Int
|
2014-07-22 09:54:48 +00:00
|
|
|
|
2019-05-25 21:52:10 +00:00
|
|
|
func (s Storage) String() (str string) {
|
|
|
|
for key, value := range s {
|
2015-06-17 09:24:40 +00:00
|
|
|
str += fmt.Sprintf("%X : %X\n", key, value)
|
2015-02-26 17:39:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-05-25 21:52:10 +00:00
|
|
|
func (s Storage) Copy() Storage {
|
2014-07-22 09:54:48 +00:00
|
|
|
cpy := make(Storage)
|
2019-05-25 21:52:10 +00:00
|
|
|
for key, value := range s {
|
2014-07-22 09:54:48 +00:00
|
|
|
cpy[key] = value
|
|
|
|
}
|
|
|
|
|
|
|
|
return cpy
|
|
|
|
}
|
|
|
|
|
2017-02-22 22:29:59 +00:00
|
|
|
// stateObject represents an Ethereum account which is being modified.
|
2016-09-22 19:04:58 +00:00
|
|
|
//
|
|
|
|
// The usage pattern is as follows:
|
|
|
|
// First you need to obtain a state object.
|
|
|
|
// Account values can be accessed and modified through the object.
|
2017-02-22 22:29:59 +00:00
|
|
|
type stateObject struct {
|
2017-06-27 13:57:06 +00:00
|
|
|
address common.Address
|
2019-05-27 13:51:49 +00:00
|
|
|
data accounts.Account
|
|
|
|
original accounts.Account
|
|
|
|
db *IntraBlockState
|
2016-09-22 19:04:58 +00:00
|
|
|
|
|
|
|
// DB error.
|
|
|
|
// State objects are used by the consensus core and VM which are
|
|
|
|
// unable to deal with database-level errors. Any error that occurs
|
|
|
|
// during a database read is memoized here and will eventually be returned
|
2019-05-27 13:51:49 +00:00
|
|
|
// by IntraBlockState.Commit.
|
2016-09-22 19:04:58 +00:00
|
|
|
dbErr error
|
|
|
|
|
|
|
|
// Write caches.
|
2019-05-27 13:51:49 +00:00
|
|
|
//trie Trie // storage trie, which becomes non-nil on first access
|
2017-06-27 13:57:06 +00:00
|
|
|
code Code // contract bytecode, which gets set when code is loaded
|
2016-10-03 07:48:01 +00:00
|
|
|
|
2020-02-10 17:05:32 +00:00
|
|
|
originStorage Storage // Storage cache of original entries to dedup rewrites
|
|
|
|
// blockOriginStorage keeps the values of storage items at the beginning of the block
|
|
|
|
// Used to make decision on whether to make a write to the
|
|
|
|
// database (value != origin) or not (value == origin)
|
2019-05-27 13:51:49 +00:00
|
|
|
blockOriginStorage Storage
|
|
|
|
dirtyStorage Storage // Storage entries that need to be flushed to disk
|
|
|
|
fakeStorage Storage // Fake storage which constructed by caller for debugging purpose.
|
2018-09-18 13:24:35 +00:00
|
|
|
|
2016-09-22 19:04:58 +00:00
|
|
|
// Cache flags.
|
2016-10-05 20:22:31 +00:00
|
|
|
// When an object is marked suicided it will be delete from the trie
|
|
|
|
// during the "update" phase of the state transition.
|
2016-09-22 19:04:58 +00:00
|
|
|
dirtyCode bool // true if the code was updated
|
2016-10-05 20:22:31 +00:00
|
|
|
suicided bool
|
2019-05-27 13:51:49 +00:00
|
|
|
deleted bool // true if account was deleted during the lifetime of this object
|
|
|
|
created bool // true if this object represents a newly created contract
|
2014-07-22 09:54:48 +00:00
|
|
|
}
|
|
|
|
|
2016-10-20 11:36:29 +00:00
|
|
|
// empty returns whether the account is considered empty.
|
2019-05-27 13:51:49 +00:00
|
|
|
func (so *stateObject) empty() bool {
|
|
|
|
return so.data.Nonce == 0 && so.data.Balance.Sign() == 0 && bytes.Equal(so.data.CodeHash[:], emptyCodeHash)
|
2016-10-20 11:36:29 +00:00
|
|
|
}
|
|
|
|
|
2016-10-04 10:36:02 +00:00
|
|
|
// newObject creates a state object.
|
2019-05-27 13:51:49 +00:00
|
|
|
func newObject(db *IntraBlockState, address common.Address, data, original *accounts.Account) *stateObject {
|
|
|
|
var so = stateObject{
|
|
|
|
db: db,
|
|
|
|
address: address,
|
|
|
|
originStorage: make(Storage),
|
|
|
|
blockOriginStorage: make(Storage),
|
|
|
|
dirtyStorage: make(Storage),
|
2016-09-22 19:04:58 +00:00
|
|
|
}
|
2019-05-27 13:51:49 +00:00
|
|
|
so.data.Copy(data)
|
|
|
|
if !so.data.Initialised {
|
|
|
|
so.data.Balance.SetUint64(0)
|
|
|
|
so.data.Initialised = true
|
2015-04-04 10:40:11 +00:00
|
|
|
}
|
2019-05-27 13:51:49 +00:00
|
|
|
if so.data.CodeHash == (common.Hash{}) {
|
|
|
|
so.data.CodeHash = emptyCodeHashH
|
2019-08-12 19:56:07 +00:00
|
|
|
}
|
2019-05-27 13:51:49 +00:00
|
|
|
if so.data.Root == (common.Hash{}) {
|
|
|
|
so.data.Root = trie.EmptyRoot
|
2017-06-27 13:57:06 +00:00
|
|
|
}
|
2019-05-27 13:51:49 +00:00
|
|
|
so.original.Copy(original)
|
|
|
|
|
|
|
|
return &so
|
2014-07-22 09:54:48 +00:00
|
|
|
}
|
|
|
|
|
2016-09-22 19:04:58 +00:00
|
|
|
// EncodeRLP implements rlp.Encoder.
|
2019-05-27 13:51:49 +00:00
|
|
|
func (so *stateObject) EncodeRLP(w io.Writer) error {
|
|
|
|
return rlp.Encode(w, so.data)
|
2014-07-22 09:54:48 +00:00
|
|
|
}
|
|
|
|
|
2016-09-22 19:04:58 +00:00
|
|
|
// setError remembers the first non-nil error it is called with.
|
2019-05-27 13:51:49 +00:00
|
|
|
func (so *stateObject) setError(err error) {
|
|
|
|
if so.dbErr == nil {
|
|
|
|
so.dbErr = err
|
2015-06-17 09:24:40 +00:00
|
|
|
}
|
2014-07-22 09:54:48 +00:00
|
|
|
}
|
|
|
|
|
2019-05-27 13:51:49 +00:00
|
|
|
func (so *stateObject) markSuicided() {
|
|
|
|
so.suicided = true
|
2014-10-16 11:38:21 +00:00
|
|
|
}
|
|
|
|
|
2019-05-27 13:51:49 +00:00
|
|
|
func (so *stateObject) touch() {
|
|
|
|
so.db.journal.append(touchChange{
|
|
|
|
account: &so.address,
|
2016-11-24 15:24:04 +00:00
|
|
|
})
|
2019-05-27 13:51:49 +00:00
|
|
|
if so.address == ripemd {
|
2018-03-27 12:13:30 +00:00
|
|
|
// Explicitly put it in the dirty-cache, which is otherwise generated from
|
|
|
|
// flattened journals.
|
2019-05-27 13:51:49 +00:00
|
|
|
so.db.journal.dirty(so.address)
|
2014-07-22 09:54:48 +00:00
|
|
|
}
|
2016-09-22 19:04:58 +00:00
|
|
|
}
|
2014-07-22 09:54:48 +00:00
|
|
|
|
2019-05-27 13:51:49 +00:00
|
|
|
// GetState returns a value from account storage.
|
2020-05-25 11:12:25 +00:00
|
|
|
func (so *stateObject) GetState(key *common.Hash, out *uint256.Int) {
|
2020-05-24 16:43:54 +00:00
|
|
|
value, dirty := so.dirtyStorage[*key]
|
2018-09-18 13:24:35 +00:00
|
|
|
if dirty {
|
2020-05-24 16:43:54 +00:00
|
|
|
*out = value
|
|
|
|
return
|
2018-09-18 13:24:35 +00:00
|
|
|
}
|
|
|
|
// Otherwise return the entry's original value
|
2020-05-24 16:43:54 +00:00
|
|
|
so.GetCommittedState(key, out)
|
2018-09-18 13:24:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetCommittedState retrieves a value from the committed account storage trie.
|
2020-05-25 11:12:25 +00:00
|
|
|
func (so *stateObject) GetCommittedState(key *common.Hash, out *uint256.Int) {
|
2019-05-27 13:51:49 +00:00
|
|
|
// If we have the original value cached, return that
|
|
|
|
{
|
2020-05-24 16:43:54 +00:00
|
|
|
value, cached := so.originStorage[*key]
|
2019-05-27 13:51:49 +00:00
|
|
|
if cached {
|
2020-05-24 16:43:54 +00:00
|
|
|
*out = value
|
|
|
|
return
|
2019-05-27 13:51:49 +00:00
|
|
|
}
|
2019-03-25 08:01:18 +00:00
|
|
|
}
|
2019-12-17 11:56:38 +00:00
|
|
|
if so.created {
|
2020-05-24 16:43:54 +00:00
|
|
|
out.Clear()
|
|
|
|
return
|
2019-12-17 11:56:38 +00:00
|
|
|
}
|
2019-05-27 13:51:49 +00:00
|
|
|
// Load from DB in case it is missing.
|
2020-05-24 16:43:54 +00:00
|
|
|
enc, err := so.db.stateReader.ReadAccountStorage(so.address, so.data.GetIncarnation(), key)
|
2017-06-27 13:57:06 +00:00
|
|
|
if err != nil {
|
2019-05-27 13:51:49 +00:00
|
|
|
so.setError(err)
|
2020-05-24 16:43:54 +00:00
|
|
|
out.Clear()
|
|
|
|
return
|
2017-06-27 13:57:06 +00:00
|
|
|
}
|
2019-05-27 13:51:49 +00:00
|
|
|
if enc != nil {
|
2020-05-24 16:43:54 +00:00
|
|
|
out.SetBytes(enc)
|
|
|
|
} else {
|
|
|
|
out.Clear()
|
2016-10-05 20:56:07 +00:00
|
|
|
}
|
2020-05-24 16:43:54 +00:00
|
|
|
so.originStorage[*key] = *out
|
|
|
|
so.blockOriginStorage[*key] = *out
|
2014-07-22 09:54:48 +00:00
|
|
|
}
|
|
|
|
|
2016-09-22 19:04:58 +00:00
|
|
|
// SetState updates a value in account storage.
|
2020-05-25 11:12:25 +00:00
|
|
|
func (so *stateObject) SetState(key *common.Hash, value uint256.Int) {
|
2018-09-18 13:24:35 +00:00
|
|
|
// If the new value is the same as old, don't set
|
2020-05-25 11:12:25 +00:00
|
|
|
var prev uint256.Int
|
|
|
|
so.GetState(key, &prev)
|
2018-09-18 13:24:35 +00:00
|
|
|
if prev == value {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// New value is different, update and journal the change
|
2019-05-27 13:51:49 +00:00
|
|
|
so.db.journal.append(storageChange{
|
|
|
|
account: &so.address,
|
2020-05-25 11:12:25 +00:00
|
|
|
key: *key,
|
2018-08-11 21:03:54 +00:00
|
|
|
prevalue: prev,
|
2016-10-04 10:36:02 +00:00
|
|
|
})
|
2019-05-27 13:51:49 +00:00
|
|
|
so.setState(key, value)
|
2016-10-04 10:36:02 +00:00
|
|
|
}
|
|
|
|
|
2019-08-08 13:44:11 +00:00
|
|
|
// SetStorage replaces the entire state storage with the given one.
|
|
|
|
//
|
|
|
|
// After this function is called, all original state will be ignored and state
|
|
|
|
// lookup only happens in the fake state storage.
|
|
|
|
//
|
|
|
|
// Note this function should only be used for debugging purpose.
|
2020-05-25 11:12:25 +00:00
|
|
|
func (so *stateObject) SetStorage(storage Storage) {
|
2019-08-08 13:44:11 +00:00
|
|
|
// Allocate fake storage if it's nil.
|
2019-05-27 13:51:49 +00:00
|
|
|
if so.fakeStorage == nil {
|
|
|
|
so.fakeStorage = make(Storage)
|
2019-08-08 13:44:11 +00:00
|
|
|
}
|
|
|
|
for key, value := range storage {
|
2019-05-27 13:51:49 +00:00
|
|
|
so.fakeStorage[key] = value
|
2019-08-08 13:44:11 +00:00
|
|
|
}
|
|
|
|
// Don't bother journal since this function should only be used for
|
|
|
|
// debugging and the `fake` storage won't be committed to database.
|
|
|
|
}
|
|
|
|
|
2020-05-25 11:12:25 +00:00
|
|
|
func (so *stateObject) setState(key *common.Hash, value uint256.Int) {
|
|
|
|
so.dirtyStorage[*key] = value
|
2014-07-22 09:54:48 +00:00
|
|
|
}
|
|
|
|
|
2016-09-22 19:04:58 +00:00
|
|
|
// updateTrie writes cached storage modifications into the object's storage trie.
|
2021-07-05 08:42:44 +00:00
|
|
|
func (so *stateObject) updateTrie(stateWriter StateWriter) error {
|
2019-05-27 13:51:49 +00:00
|
|
|
for key, value := range so.dirtyStorage {
|
2021-04-13 14:48:20 +00:00
|
|
|
value := value
|
2019-05-27 13:51:49 +00:00
|
|
|
original := so.blockOriginStorage[key]
|
|
|
|
so.originStorage[key] = value
|
2021-07-05 08:42:44 +00:00
|
|
|
if err := stateWriter.WriteAccountStorage(so.address, so.data.GetIncarnation(), &key, &original, &value); err != nil {
|
2019-05-27 13:51:49 +00:00
|
|
|
return err
|
2014-07-22 09:54:48 +00:00
|
|
|
}
|
2019-08-12 19:56:07 +00:00
|
|
|
}
|
2019-05-27 13:51:49 +00:00
|
|
|
return nil
|
2014-07-22 09:54:48 +00:00
|
|
|
}
|
2021-07-12 15:27:25 +00:00
|
|
|
func (so *stateObject) printTrie() {
|
|
|
|
for key, value := range so.dirtyStorage {
|
|
|
|
fmt.Printf("WriteAccountStorage: %x,%x,%s\n", so.address, key, value.Hex())
|
|
|
|
}
|
|
|
|
}
|
2014-07-22 09:54:48 +00:00
|
|
|
|
2019-05-27 13:51:49 +00:00
|
|
|
// AddBalance adds amount to so's balance.
|
2016-10-20 11:36:29 +00:00
|
|
|
// It is used to add funds to the destination account of a transfer.
|
2020-05-26 16:53:50 +00:00
|
|
|
func (so *stateObject) AddBalance(amount *uint256.Int) {
|
2020-08-19 06:54:21 +00:00
|
|
|
// EIP161: We must check emptiness for the objects such that the account
|
2016-10-20 11:36:29 +00:00
|
|
|
// clearing (0,0,0 objects) can take effect.
|
2020-05-26 16:53:50 +00:00
|
|
|
if amount.IsZero() {
|
2019-05-27 13:51:49 +00:00
|
|
|
if so.empty() {
|
|
|
|
so.touch()
|
2016-11-24 15:24:04 +00:00
|
|
|
}
|
|
|
|
|
2016-09-26 05:25:50 +00:00
|
|
|
return
|
|
|
|
}
|
2021-07-12 15:27:25 +00:00
|
|
|
|
2020-05-26 16:53:50 +00:00
|
|
|
so.SetBalance(new(uint256.Int).Add(so.Balance(), amount))
|
2014-07-22 09:54:48 +00:00
|
|
|
}
|
|
|
|
|
2019-05-27 13:51:49 +00:00
|
|
|
// SubBalance removes amount from so's balance.
|
2016-10-20 11:36:29 +00:00
|
|
|
// It is used to remove funds from the origin account of a transfer.
|
2020-05-26 16:53:50 +00:00
|
|
|
func (so *stateObject) SubBalance(amount *uint256.Int) {
|
|
|
|
if amount.IsZero() {
|
2016-09-26 05:25:50 +00:00
|
|
|
return
|
|
|
|
}
|
2020-05-26 16:53:50 +00:00
|
|
|
so.SetBalance(new(uint256.Int).Sub(so.Balance(), amount))
|
2014-07-22 09:54:48 +00:00
|
|
|
}
|
|
|
|
|
2020-05-26 16:53:50 +00:00
|
|
|
func (so *stateObject) SetBalance(amount *uint256.Int) {
|
2019-05-27 13:51:49 +00:00
|
|
|
so.db.journal.append(balanceChange{
|
|
|
|
account: &so.address,
|
2020-05-26 16:53:50 +00:00
|
|
|
prev: so.data.Balance,
|
2016-10-04 10:36:02 +00:00
|
|
|
})
|
2019-05-27 13:51:49 +00:00
|
|
|
so.setBalance(amount)
|
2016-10-04 10:36:02 +00:00
|
|
|
}
|
|
|
|
|
2020-05-26 16:53:50 +00:00
|
|
|
func (so *stateObject) setBalance(amount *uint256.Int) {
|
2019-05-27 13:51:49 +00:00
|
|
|
so.data.Balance.Set(amount)
|
|
|
|
so.data.Initialised = true
|
2015-02-26 17:39:05 +00:00
|
|
|
}
|
|
|
|
|
2014-07-22 09:54:48 +00:00
|
|
|
// Return the gas back to the origin. Used by the Virtual machine or Closures
|
2019-05-27 13:51:49 +00:00
|
|
|
func (so *stateObject) ReturnGas(gas *big.Int) {}
|
2014-07-22 09:54:48 +00:00
|
|
|
|
2019-05-27 13:51:49 +00:00
|
|
|
func (so *stateObject) setIncarnation(incarnation uint64) {
|
|
|
|
so.data.SetIncarnation(incarnation)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (so *stateObject) deepCopy(db *IntraBlockState) *stateObject {
|
|
|
|
stateObject := newObject(db, so.address, &so.data, &so.original)
|
|
|
|
stateObject.code = so.code
|
|
|
|
stateObject.dirtyStorage = so.dirtyStorage.Copy()
|
|
|
|
stateObject.originStorage = so.originStorage.Copy()
|
|
|
|
stateObject.blockOriginStorage = so.blockOriginStorage.Copy()
|
|
|
|
stateObject.suicided = so.suicided
|
|
|
|
stateObject.dirtyCode = so.dirtyCode
|
|
|
|
stateObject.deleted = so.deleted
|
2014-07-22 09:54:48 +00:00
|
|
|
return stateObject
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Attribute accessors
|
|
|
|
//
|
|
|
|
|
|
|
|
// Returns the address of the contract/account
|
2019-05-27 13:51:49 +00:00
|
|
|
func (so *stateObject) Address() common.Address {
|
|
|
|
return so.address
|
2014-07-22 09:54:48 +00:00
|
|
|
}
|
|
|
|
|
2016-09-22 19:04:58 +00:00
|
|
|
// Code returns the contract code associated with this object, if any.
|
2019-05-27 13:51:49 +00:00
|
|
|
func (so *stateObject) Code() []byte {
|
|
|
|
if so.code != nil {
|
|
|
|
return so.code
|
2016-09-22 19:04:58 +00:00
|
|
|
}
|
2019-05-27 13:51:49 +00:00
|
|
|
if bytes.Equal(so.CodeHash(), emptyCodeHash) {
|
2016-09-22 19:04:58 +00:00
|
|
|
return nil
|
|
|
|
}
|
2020-12-08 09:44:29 +00:00
|
|
|
code, err := so.db.stateReader.ReadAccountCode(so.Address(), so.data.Incarnation, common.BytesToHash(so.CodeHash()))
|
2016-09-22 19:04:58 +00:00
|
|
|
if err != nil {
|
2019-05-27 13:51:49 +00:00
|
|
|
so.setError(fmt.Errorf("can't load code hash %x: %v", so.CodeHash(), err))
|
2016-09-22 19:04:58 +00:00
|
|
|
}
|
2019-05-27 13:51:49 +00:00
|
|
|
so.code = code
|
2016-09-22 19:04:58 +00:00
|
|
|
return code
|
2014-11-03 22:45:44 +00:00
|
|
|
}
|
|
|
|
|
2019-05-27 13:51:49 +00:00
|
|
|
func (so *stateObject) SetCode(codeHash common.Hash, code []byte) {
|
|
|
|
prevcode := so.Code()
|
|
|
|
so.db.journal.append(codeChange{
|
|
|
|
account: &so.address,
|
|
|
|
prevhash: so.data.CodeHash,
|
2016-10-04 10:36:02 +00:00
|
|
|
prevcode: prevcode,
|
|
|
|
})
|
2019-05-27 13:51:49 +00:00
|
|
|
so.setCode(codeHash, code)
|
2016-10-04 10:36:02 +00:00
|
|
|
}
|
|
|
|
|
2019-05-27 13:51:49 +00:00
|
|
|
func (so *stateObject) setCode(codeHash common.Hash, code []byte) {
|
|
|
|
so.code = code
|
|
|
|
so.data.CodeHash = codeHash
|
|
|
|
so.dirtyCode = true
|
2015-02-20 13:19:34 +00:00
|
|
|
}
|
|
|
|
|
2019-05-27 13:51:49 +00:00
|
|
|
func (so *stateObject) SetNonce(nonce uint64) {
|
|
|
|
so.db.journal.append(nonceChange{
|
|
|
|
account: &so.address,
|
|
|
|
prev: so.data.Nonce,
|
2016-10-04 10:36:02 +00:00
|
|
|
})
|
2019-05-27 13:51:49 +00:00
|
|
|
so.setNonce(nonce)
|
2016-10-04 10:36:02 +00:00
|
|
|
}
|
|
|
|
|
2019-05-27 13:51:49 +00:00
|
|
|
func (so *stateObject) setNonce(nonce uint64) {
|
|
|
|
so.data.Nonce = nonce
|
|
|
|
}
|
|
|
|
|
|
|
|
func (so *stateObject) CodeHash() []byte {
|
|
|
|
return so.data.CodeHash[:]
|
|
|
|
}
|
|
|
|
|
2020-05-26 16:53:50 +00:00
|
|
|
func (so *stateObject) Balance() *uint256.Int {
|
2019-05-27 13:51:49 +00:00
|
|
|
return &so.data.Balance
|
2015-02-20 13:19:34 +00:00
|
|
|
}
|
|
|
|
|
2019-05-27 13:51:49 +00:00
|
|
|
func (so *stateObject) Nonce() uint64 {
|
|
|
|
return so.data.Nonce
|
2014-12-03 16:06:54 +00:00
|
|
|
}
|
|
|
|
|
2017-02-22 22:29:59 +00:00
|
|
|
// Never called, but must be present to allow stateObject to be used
|
2015-11-27 14:40:29 +00:00
|
|
|
// as a vm.Account interface that also satisfies the vm.ContractRef
|
|
|
|
// interface. Interfaces are awesome.
|
2019-05-27 13:51:49 +00:00
|
|
|
func (so *stateObject) Value() *big.Int {
|
2017-02-22 22:29:59 +00:00
|
|
|
panic("Value on stateObject should never be called")
|
2015-06-10 10:57:37 +00:00
|
|
|
}
|