Documentation
¶
Overview ¶
Package ethStatedb
@author: xwc1125
Package ethStatedb ¶
@author: xwc1125
Package ethStatedb ¶
@author: xwc1125
Package ethStatedb ¶
@author: xwc1125
Index ¶
- func NewDatabase(db kvstore.Database) basedb.Database
- func NewDatabaseWithCache(db kvstore.Database, cache int) basedb.Database
- func NewStateSync(root types.Hash, database kvstore.KeyValueReader, bloom *tree.SyncBloom) *tree.Sync
- type StateDB
- func (s *StateDB) AddBalance(addr types.Address, amount *big.Int)
- func (s *StateDB) AddKV(addr types.Address, namespace string, key string, val interface{}) error
- func (s *StateDB) AddLog(logger *statetype.Log)
- func (s *StateDB) AddPreimage(hash types.Hash, preimage []byte)
- func (s *StateDB) AddRefund(gas uint64)
- func (s *StateDB) BlockHash() types.Hash
- func (s *StateDB) Commit(deleteEmptyObjects bool) (types.Hash, error)
- func (s *StateDB) Copy() *StateDB
- func (s *StateDB) CreateAccount(addr types.Address)
- func (s *StateDB) Database() basedb.Database
- func (s *StateDB) Empty(addr types.Address) bool
- func (s *StateDB) Error() error
- func (s *StateDB) Exist(addr types.Address) bool
- func (s *StateDB) Finalise(deleteEmptyObjects bool)
- func (db *StateDB) ForEachStorage(addr types.Address, cb func(key, value types.Hash) bool) error
- func (s *StateDB) GetBalance(addr types.Address) *big.Int
- func (s *StateDB) GetCode(addr types.Address) []byte
- func (s *StateDB) GetCodeHash(addr types.Address) types.Hash
- func (s *StateDB) GetCodeSize(addr types.Address) int
- func (s *StateDB) GetCommittedState(addr types.Address, hash types.Hash) types.Hash
- func (s *StateDB) GetKV(addr types.Address, namespace string, key string) (interface{}, error)
- func (s *StateDB) GetKVNP(addr types.Address, namespace string) (*linkedHashMap.LinkedHashMap, error)
- func (s *StateDB) GetKVS(addr types.Address) *linkedHashMap.LinkedHashMap
- func (s *StateDB) GetLogs(hash types.Hash) []*statetype.Log
- func (s *StateDB) GetNonce(addr types.Address) uint64
- func (s *StateDB) GetOrNewStateObject(addr types.Address) *stateObject
- func (s *StateDB) GetProof(a types.Address) ([][]byte, error)
- func (s *StateDB) GetRefund() uint64
- func (s *StateDB) GetState(addr types.Address, hash types.Hash) types.Hash
- func (s *StateDB) GetStorageProof(a types.Address, key types.Hash) ([][]byte, error)
- func (s *StateDB) HasSuicided(addr types.Address) bool
- func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) types.Hash
- func (s *StateDB) KVExist(addr types.Address, namespace string, key string) bool
- func (s *StateDB) Logs() []*statetype.Log
- func (s *StateDB) Preimages() map[types.Hash][]byte
- func (s *StateDB) Prepare(thash, bhash types.Hash, ti int)
- func (s *StateDB) Reset(root types.Hash) error
- func (s *StateDB) RevertToSnapshot(revid int)
- func (s *StateDB) SetBalance(addr types.Address, amount *big.Int)
- func (s *StateDB) SetCode(addr types.Address, code []byte)
- func (s *StateDB) SetNonce(addr types.Address, nonce uint64)
- func (s *StateDB) SetState(addr types.Address, key, value types.Hash)
- func (s *StateDB) Snapshot() int
- func (s *StateDB) StorageTree(addr types.Address) basedb.Tree
- func (s *StateDB) SubBalance(addr types.Address, amount *big.Int)
- func (s *StateDB) SubRefund(gas uint64)
- func (s *StateDB) Suicide(addr types.Address) bool
- func (s *StateDB) TxIndex() int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewDatabaseWithCache ¶
NewDatabaseWithCache creates a backing store for state. The returned database is safe for concurrent use and retains a lot of collapsed RLP trie nodes in a large memory cache.
func NewStateSync ¶
func NewStateSync(root types.Hash, database kvstore.KeyValueReader, bloom *tree.SyncBloom) *tree.Sync
NewStateSync create a new state trie download scheduler.
Types ¶
type StateDB ¶
type StateDB struct { // Measurements gathered during execution for debugging purposes AccountReads time.Duration AccountHashes time.Duration AccountUpdates time.Duration AccountCommits time.Duration StorageReads time.Duration StorageHashes time.Duration StorageUpdates time.Duration StorageCommits time.Duration // contains filtered or unexported fields }
StateDBs 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 ¶
AddBalance adds amount to the account associated with addr.
func (*StateDB) AddPreimage ¶
AddPreimage records a SHA3 preimage seen by the VM.
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 ¶
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 ¶
Empty returns whether the state object is either non-existent or empty according to the EIP161 specification (balance = nonce = code = 0)
func (*StateDB) Exist ¶
AddressExist reports whether the given account address exists in the state. Notably this also returns true for suicided accounts.
func (*StateDB) Finalise ¶
Finalise finalises the state by removing the s destructed objects and clears the journal as well as the refunds. Finalise, however, will not push any updates into the tries just yet. Only IntermediateRoot or Commit will do that.
func (*StateDB) ForEachStorage ¶
func (*StateDB) GetBalance ¶
Retrieve the balance from the given address or 0 if object not found
func (*StateDB) GetCommittedState ¶
GetCommittedState retrieves a value from the given account's committed storage trie.
func (*StateDB) GetKVNP ¶
func (s *StateDB) GetKVNP(addr types.Address, namespace string) (*linkedHashMap.LinkedHashMap, error)
func (*StateDB) GetKVS ¶
func (s *StateDB) GetKVS(addr types.Address) *linkedHashMap.LinkedHashMap
kvs
func (*StateDB) GetOrNewStateObject ¶
Retrieve a state object or create a new state object if nil.
func (*StateDB) GetStorageProof ¶
GetProof returns the StorageProof for given key
func (*StateDB) IntermediateRoot ¶
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) Prepare ¶
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) StorageTree ¶
StorageTrie returns the storage trie of an account. The return value is a copy and is nil for non-existent accounts.
func (*StateDB) SubBalance ¶
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