state

package
v1.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2020 License: LGPL-3.0 Imports: 7 Imported by: 65

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// TrieDbPrefix is the key prefix of trie database in statedb.
	TrieDbPrefix = []byte("S")
)

Functions

This section is empty.

Types

type Statedb

type Statedb struct {
	// contains filtered or unexported fields
}

Statedb is used to store accounts into the MPT tree

func NewEmptyStatedb

func NewEmptyStatedb(db database.Database) *Statedb

NewEmptyStatedb creates an empty statedb instance.

func NewStatedb

func NewStatedb(root common.Hash, db database.Database) (*Statedb, error)

NewStatedb constructs and returns a statedb instance

func NewStatedbWithTrie

func NewStatedbWithTrie(trie Trie) *Statedb

NewStatedbWithTrie creates a statedb instance with specified trie.

func (*Statedb) AddBalance

func (s *Statedb) AddBalance(addr common.Address, amount *big.Int)

AddBalance adds the specified amount to the balance for the specified account if exists.

func (*Statedb) AddLog

func (s *Statedb) AddLog(log *types.Log)

AddLog adds a log.

func (*Statedb) AddRefund

func (s *Statedb) AddRefund(gas uint64)

AddRefund adds gas to the refund counter.AddRefund

func (*Statedb) Commit

func (s *Statedb) Commit(batch database.Batch) (common.Hash, error)

Commit persists the trie to the specified batch.

func (*Statedb) CreateAccount

func (s *Statedb) CreateAccount(address common.Address)

CreateAccount creates a new account in statedb.

func (*Statedb) Empty

func (s *Statedb) Empty(address common.Address) bool

Empty indicates whether the given account satisfies (balance = nonce = code = 0).

func (*Statedb) Exist

func (s *Statedb) Exist(address common.Address) bool

Exist indicates whether the given account exists in statedb. Note that it should also return true for suicided accounts.

func (*Statedb) GetBalance

func (s *Statedb) GetBalance(addr common.Address) *big.Int

GetBalance returns the balance of the specified account if exists. Otherwise, returns zero.

func (*Statedb) GetCode

func (s *Statedb) GetCode(address common.Address) []byte

GetCode returns the contract code associated with the specified address if any. Otherwise, return nil.

func (*Statedb) GetCodeHash

func (s *Statedb) GetCodeHash(address common.Address) common.Hash

GetCodeHash returns the hash of the contract code associated with the specified address if any. Otherwise, return an empty hash.

func (*Statedb) GetCodeSize

func (s *Statedb) GetCodeSize(address common.Address) int

GetCodeSize returns the size of the contract code associated with the specified address if any. Otherwise, return 0.

func (*Statedb) GetCommittedData

func (s *Statedb) GetCommittedData(addr common.Address, key common.Hash) []byte

GetCommittedData returns the account committed data of the specified key if exists.

func (*Statedb) GetCurrentLogs

func (s *Statedb) GetCurrentLogs() []*types.Log

GetCurrentLogs returns the current transaction logs.

func (*Statedb) GetData

func (s *Statedb) GetData(addr common.Address, key common.Hash) []byte

GetData returns the account data of the specified key if exists. Otherwise, return nil.

func (*Statedb) GetDbErr

func (s *Statedb) GetDbErr() error

GetDbErr returns with error.

func (*Statedb) GetNonce

func (s *Statedb) GetNonce(addr common.Address) uint64

GetNonce gets the nonce of the specified account if exists. Otherwise, return 0.

func (*Statedb) GetRefund

func (s *Statedb) GetRefund() uint64

GetRefund returns the current value of the refund counter.

func (*Statedb) HasSuicided

func (s *Statedb) HasSuicided(address common.Address) bool

HasSuicided returns true if the specified account exists and suicided, otherwise false.

func (*Statedb) Hash

func (s *Statedb) Hash() (common.Hash, error)

Hash flush the dirty data into trie and calculates the intermediate root hash.

func (*Statedb) Prepare

func (s *Statedb) Prepare(txIndex int) int

Prepare resets the logs and journal to process a new tx and return the statedb snapshot.

func (*Statedb) RevertToSnapshot

func (s *Statedb) RevertToSnapshot(revid int)

RevertToSnapshot reverts all state changes made since the given revision.

func (*Statedb) SetBalance

func (s *Statedb) SetBalance(addr common.Address, balance *big.Int)

SetBalance sets the balance of the specified account if exists.

func (*Statedb) SetCode

func (s *Statedb) SetCode(address common.Address, code []byte)

SetCode sets the contract code of the specified address if exists.

func (*Statedb) SetData

func (s *Statedb) SetData(addr common.Address, key common.Hash, value []byte)

SetData sets the key value pair for the specified account if exists.

func (*Statedb) SetNonce

func (s *Statedb) SetNonce(addr common.Address, nonce uint64)

SetNonce sets the nonce of the specified account if exists.

func (*Statedb) Snapshot

func (s *Statedb) Snapshot() int

Snapshot returns an identifier for the current revision of the statedb.

func (*Statedb) SubBalance

func (s *Statedb) SubBalance(addr common.Address, amount *big.Int)

SubBalance subtracts the specified amount from the balance for the specified account if exists.

func (*Statedb) SubRefund

func (s *Statedb) SubRefund(gas uint64)

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(address common.Address) bool

Suicide marks the given account as suicided and clears the account balance. Note the account's state object is still available until the state is committed. Return true if the specified account exists, otherwise false.

func (*Statedb) Trie

func (s *Statedb) Trie() Trie

Trie retrieves the low level trie of statedb to support low level trie ops.

type Trie

type Trie interface {
	Hash() common.Hash
	Commit(batch database.Batch) common.Hash
	Get(key []byte) ([]byte, bool, error)
	Put(key, value []byte) error
	DeletePrefix(prefix []byte) (bool, error)
	GetProof(key []byte) (map[string][]byte, error)
}

Trie is used for statedb to store key-value pairs. For full node, it's MPT based on levelDB. For light node, it's a ODR trie with limited functions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL