Documentation ¶
Index ¶
- type Account
- type Code
- type Mockdb
- func (mock *Mockdb) AddBalance(address types.AddressHash, amount *big.Int)
- func (mock *Mockdb) AddLog(log *types.Log)
- func (mock *Mockdb) AddPreimage(hash crypto.HashType, data []byte)
- func (mock *Mockdb) AddRefund(refund uint64)
- func (mock *Mockdb) CreateAccount(address types.AddressHash)
- func (mock *Mockdb) Empty(address types.AddressHash) bool
- func (mock *Mockdb) Exist(address types.AddressHash) bool
- func (mock *Mockdb) ForEachStorage(types.AddressHash, func(crypto.HashType, crypto.HashType) bool)
- func (mock *Mockdb) GetBalance(address types.AddressHash) *big.Int
- func (mock *Mockdb) GetCode(address types.AddressHash) []byte
- func (mock *Mockdb) GetCodeHash(address types.AddressHash) crypto.HashType
- func (mock *Mockdb) GetCodeSize(address types.AddressHash) int
- func (mock *Mockdb) GetCommittedState(address types.AddressHash, key crypto.HashType) crypto.HashType
- func (mock *Mockdb) GetNonce(address types.AddressHash) uint64
- func (mock *Mockdb) GetRefund() uint64
- func (mock *Mockdb) GetState(address types.AddressHash, key crypto.HashType) crypto.HashType
- func (mock *Mockdb) HasSuicided(address types.AddressHash) bool
- func (mock *Mockdb) RevertToSnapshot(i int)
- func (mock *Mockdb) SetCode(address types.AddressHash, code []byte)
- func (mock *Mockdb) SetNonce(address types.AddressHash, nonce uint64)
- func (mock *Mockdb) SetState(address types.AddressHash, key, value crypto.HashType)
- func (mock *Mockdb) Snapshot() int
- func (mock *Mockdb) SubBalance(address types.AddressHash, amount *big.Int)
- func (mock *Mockdb) SubRefund(refund uint64)
- func (mock *Mockdb) Suicide(address types.AddressHash) bool
- type StateDB
- func (s *StateDB) AddBalance(addr types.AddressHash, amount *big.Int)
- func (s *StateDB) AddLog(log *types.Log)
- func (s *StateDB) AddPreimage(hash corecrypto.HashType, preimage []byte)
- func (s *StateDB) AddRefund(gas uint64)
- func (s *StateDB) Commit(deleteEmptyObjects bool) (*corecrypto.HashType, *corecrypto.HashType, error)
- func (s *StateDB) Copy() *StateDB
- func (s *StateDB) CreateAccount(addr types.AddressHash)
- func (s *StateDB) Database() storage.Table
- func (s *StateDB) Empty(addr types.AddressHash) bool
- func (s *StateDB) Error() error
- func (s *StateDB) Exist(addr types.AddressHash) bool
- func (s *StateDB) ForEachStorage(addr types.AddressHash, cb func(key, value corecrypto.HashType) bool)
- func (s *StateDB) GetBalance(addr types.AddressHash) *big.Int
- func (s *StateDB) GetCode(addr types.AddressHash) []byte
- func (s *StateDB) GetCodeHash(addr types.AddressHash) corecrypto.HashType
- func (s *StateDB) GetCodeSize(addr types.AddressHash) int
- func (s *StateDB) GetCommittedState(addr types.AddressHash, hash corecrypto.HashType) corecrypto.HashType
- func (s *StateDB) GetLogs(hash corecrypto.HashType) []*types.Log
- func (s *StateDB) GetNonce(addr types.AddressHash) uint64
- func (s *StateDB) GetRefund() uint64
- func (s *StateDB) GetState(a types.AddressHash, b corecrypto.HashType) corecrypto.HashType
- func (s *StateDB) GetUtxo(addr types.AddressHash) ([]byte, error)
- func (s *StateDB) HasSuicided(addr types.AddressHash) bool
- func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) corecrypto.HashType
- func (s *StateDB) Logs() []*types.Log
- func (s *StateDB) Preimages() map[corecrypto.HashType][]byte
- func (s *StateDB) Prepare(thash, bhash corecrypto.HashType, ti int)
- func (s *StateDB) Reset() error
- func (s *StateDB) RevertToSnapshot(revid int)
- func (s *StateDB) SetBalance(addr types.AddressHash, amount *big.Int)
- func (s *StateDB) SetCode(addr types.AddressHash, code []byte)
- func (s *StateDB) SetNonce(addr types.AddressHash, nonce uint64)
- func (s *StateDB) SetState(addr types.AddressHash, key corecrypto.HashType, value corecrypto.HashType)
- func (s *StateDB) Snapshot() int
- func (s *StateDB) StorageTrie(a types.AddressHash) *trie.Trie
- func (s *StateDB) String() string
- func (s *StateDB) SubBalance(addr types.AddressHash, amount *big.Int)
- func (s *StateDB) SubRefund(gas uint64)
- func (s *StateDB) Suicide(addr types.AddressHash) bool
- func (s *StateDB) UpdateUtxo(addr types.AddressHash, utxoBytes []byte) error
- type Storage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Account ¶
type Account struct { Nonce uint64 Balance *big.Int Root corecrypto.HashType // merkle root of the storage trie CodeHash []byte }
Account is the Ethereum consensus representation of accounts. These objects are stored in the main account trie.
type Mockdb ¶
type Mockdb struct {
// contains filtered or unexported fields
}
Mockdb is used instead of StateDb for test.
func (*Mockdb) AddBalance ¶
func (mock *Mockdb) AddBalance(address types.AddressHash, amount *big.Int)
AddBalance add balance.
func (*Mockdb) AddPreimage ¶
AddPreimage add preimage.
func (*Mockdb) CreateAccount ¶
func (mock *Mockdb) CreateAccount(address types.AddressHash)
CreateAccount create account.
func (*Mockdb) ForEachStorage ¶
ForEachStorage traverse storage.
func (*Mockdb) GetBalance ¶
func (mock *Mockdb) GetBalance(address types.AddressHash) *big.Int
GetBalance get balance.
func (*Mockdb) GetCode ¶
func (mock *Mockdb) GetCode(address types.AddressHash) []byte
GetCode get code.
func (*Mockdb) GetCodeHash ¶
func (mock *Mockdb) GetCodeHash(address types.AddressHash) crypto.HashType
GetCodeHash get code hash.
func (*Mockdb) GetCodeSize ¶
func (mock *Mockdb) GetCodeSize(address types.AddressHash) int
GetCodeSize get code size.
func (*Mockdb) GetCommittedState ¶
func (mock *Mockdb) GetCommittedState(address types.AddressHash, key crypto.HashType) crypto.HashType
GetCommittedState get committed state.
func (*Mockdb) GetNonce ¶
func (mock *Mockdb) GetNonce(address types.AddressHash) uint64
GetNonce get nonce.
func (*Mockdb) HasSuicided ¶
func (mock *Mockdb) HasSuicided(address types.AddressHash) bool
HasSuicided judge suicided.
func (*Mockdb) RevertToSnapshot ¶
RevertToSnapshot revert to snap.
func (*Mockdb) SetCode ¶
func (mock *Mockdb) SetCode(address types.AddressHash, code []byte)
SetCode set code.
func (*Mockdb) SetNonce ¶
func (mock *Mockdb) SetNonce(address types.AddressHash, nonce uint64)
SetNonce set nonce.
func (*Mockdb) SetState ¶
func (mock *Mockdb) SetState(address types.AddressHash, key, value crypto.HashType)
SetState set state.
func (*Mockdb) SubBalance ¶
func (mock *Mockdb) SubBalance(address types.AddressHash, amount *big.Int)
SubBalance sub balance.
type StateDB ¶
type StateDB struct {
// contains filtered or unexported fields
}
StateDB within the ethereum protocol are used to store anything within the merkle trie. StateDBs take care of caching and storing nested states. It's the general query interface to retrieve: * Contracts * Accounts
func (*StateDB) AddBalance ¶
func (s *StateDB) AddBalance(addr types.AddressHash, amount *big.Int)
AddBalance adds amount to the account associated with addr
func (*StateDB) AddPreimage ¶
func (s *StateDB) AddPreimage(hash corecrypto.HashType, preimage []byte)
AddPreimage records a SHA3 preimage seen by the VM.
func (*StateDB) Commit ¶
func (s *StateDB) Commit(deleteEmptyObjects bool) (*corecrypto.HashType, *corecrypto.HashType, error)
Commit writes the state to the underlying in-memory trie database.
func (*StateDB) Copy ¶
Copy creates a deep, independent copy of the state. Snapshots of the copied state cannot be applied to the copy.
func (*StateDB) CreateAccount ¶
func (s *StateDB) CreateAccount(addr types.AddressHash)
CreateAccount explicitly creates a state object. If a state object with the address already exists the balance is carried over to the new account.
CreateAccount is called during the EVM CREATE operation. The situation might arise that a contract does the following:
- sends funds to sha(account ++ (nonce + 1))
- tx_create(sha(account ++ nonce)) (note that this gets the address of 1)
Carrying over the balance ensures that Ether doesn't disappear.
func (*StateDB) Database ¶
Database retrieves the low level database supporting the lower level trie ops.
func (*StateDB) Empty ¶
func (s *StateDB) Empty(addr types.AddressHash) bool
Empty returns whether the state object is either non-existent or empty according to the EIP161 specification (balance = nonce = code = 0)
func (*StateDB) Exist ¶
func (s *StateDB) Exist(addr types.AddressHash) bool
Exist reports whether the given account address exists in the state. Notably this also returns true for suicided accounts.
func (*StateDB) ForEachStorage ¶
func (s *StateDB) ForEachStorage(addr types.AddressHash, cb func(key, value corecrypto.HashType) bool)
ForEachStorage traverse the storage.
func (*StateDB) GetBalance ¶
func (s *StateDB) GetBalance(addr types.AddressHash) *big.Int
GetBalance Retrieve the balance from the given address or 0 if object not found
func (*StateDB) GetCode ¶
func (s *StateDB) GetCode(addr types.AddressHash) []byte
GetCode get code.
func (*StateDB) GetCodeHash ¶
func (s *StateDB) GetCodeHash(addr types.AddressHash) corecrypto.HashType
GetCodeHash get code hash.
func (*StateDB) GetCodeSize ¶
func (s *StateDB) GetCodeSize(addr types.AddressHash) int
GetCodeSize get code size.
func (*StateDB) GetCommittedState ¶
func (s *StateDB) GetCommittedState(addr types.AddressHash, hash corecrypto.HashType) corecrypto.HashType
GetCommittedState retrieves a value from the given account's committed storage trie.
func (*StateDB) GetLogs ¶
func (s *StateDB) GetLogs(hash corecrypto.HashType) []*types.Log
GetLogs get logs
func (*StateDB) GetNonce ¶
func (s *StateDB) GetNonce(addr types.AddressHash) uint64
GetNonce get nonce
func (*StateDB) GetState ¶
func (s *StateDB) GetState(a types.AddressHash, b corecrypto.HashType) corecrypto.HashType
GetState get state.
func (*StateDB) GetUtxo ¶
func (s *StateDB) GetUtxo(addr types.AddressHash) ([]byte, error)
GetUtxo return contract address utxo at given contract addr
func (*StateDB) HasSuicided ¶
func (s *StateDB) HasSuicided(addr types.AddressHash) bool
HasSuicided judge hasSuicided.
func (*StateDB) IntermediateRoot ¶
func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) corecrypto.HashType
IntermediateRoot computes the current root hash of the state trie. It is called in between transactions to get the root hash that goes into transaction receipts.
func (*StateDB) Preimages ¶
func (s *StateDB) Preimages() map[corecrypto.HashType][]byte
Preimages returns a list of SHA3 preimages that have been submitted.
func (*StateDB) Prepare ¶
func (s *StateDB) Prepare(thash, bhash corecrypto.HashType, ti int)
Prepare sets the current transaction hash and index and block hash which is used when the EVM emits new state logs.
func (*StateDB) Reset ¶
Reset clears out all ephemeral state objects from the state db, but keeps the underlying state trie to avoid reloading data for the next operations.
func (*StateDB) RevertToSnapshot ¶
RevertToSnapshot reverts all state changes made since the given revision.
func (*StateDB) SetBalance ¶
func (s *StateDB) SetBalance(addr types.AddressHash, amount *big.Int)
SetBalance set balance.
func (*StateDB) SetCode ¶
func (s *StateDB) SetCode(addr types.AddressHash, code []byte)
SetCode set code.
func (*StateDB) SetNonce ¶
func (s *StateDB) SetNonce(addr types.AddressHash, nonce uint64)
SetNonce set nonce.
func (*StateDB) SetState ¶
func (s *StateDB) SetState(addr types.AddressHash, key corecrypto.HashType, value corecrypto.HashType)
SetState set state.
func (*StateDB) StorageTrie ¶
func (s *StateDB) StorageTrie(a types.AddressHash) *trie.Trie
StorageTrie returns the storage trie of an account. The return value is a copy and is nil for non-existent accounts.
func (*StateDB) SubBalance ¶
func (s *StateDB) SubBalance(addr types.AddressHash, amount *big.Int)
SubBalance subtracts amount from the account associated with addr
func (*StateDB) SubRefund ¶
SubRefund removes gas from the refund counter. This method will panic if the refund counter goes below zero
func (*StateDB) Suicide ¶
func (s *StateDB) Suicide(addr types.AddressHash) bool
Suicide marks the given account as suicided. This clears the account balance.
The account's state object is still available until the state is committed, getStateObject will return a non-nil account after Suicide.
func (*StateDB) UpdateUtxo ¶
func (s *StateDB) UpdateUtxo(addr types.AddressHash, utxoBytes []byte) error
UpdateUtxo updates statedb utxo at given contract addr