worldstate

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2019 License: MIT Imports: 18 Imported by: 0

Documentation

Index

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 Code

type Code []byte

Code ...

func (Code) String

func (s Code) String() string

type Mockdb

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

Mockdb is used instead of StateDb for test.

func NewMockdb

func NewMockdb() *Mockdb

NewMockdb new Mockdb instead of StateDb.

func (*Mockdb) AddBalance

func (mock *Mockdb) AddBalance(address types.AddressHash, amount *big.Int)

AddBalance add balance.

func (*Mockdb) AddLog

func (mock *Mockdb) AddLog(log *types.Log)

AddLog add log.

func (*Mockdb) AddPreimage

func (mock *Mockdb) AddPreimage(hash crypto.HashType, data []byte)

AddPreimage add preimage.

func (*Mockdb) AddRefund

func (mock *Mockdb) AddRefund(refund uint64)

AddRefund add refund.

func (*Mockdb) CreateAccount

func (mock *Mockdb) CreateAccount(address types.AddressHash)

CreateAccount create account.

func (*Mockdb) Empty

func (mock *Mockdb) Empty(address types.AddressHash) bool

Empty judge empty.

func (*Mockdb) Exist

func (mock *Mockdb) Exist(address types.AddressHash) bool

Exist judge exist.

func (*Mockdb) ForEachStorage

func (mock *Mockdb) ForEachStorage(types.AddressHash, func(crypto.HashType, crypto.HashType) bool)

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) GetRefund

func (mock *Mockdb) GetRefund() uint64

GetRefund get refund.

func (*Mockdb) GetState

func (mock *Mockdb) GetState(address types.AddressHash, key crypto.HashType) crypto.HashType

GetState get state.

func (*Mockdb) HasSuicided

func (mock *Mockdb) HasSuicided(address types.AddressHash) bool

HasSuicided judge suicided.

func (*Mockdb) RevertToSnapshot

func (mock *Mockdb) RevertToSnapshot(i int)

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) Snapshot

func (mock *Mockdb) Snapshot() int

Snapshot record snap.

func (*Mockdb) SubBalance

func (mock *Mockdb) SubBalance(address types.AddressHash, amount *big.Int)

SubBalance sub balance.

func (*Mockdb) SubRefund

func (mock *Mockdb) SubRefund(refund uint64)

SubRefund sub refund.

func (*Mockdb) Suicide

func (mock *Mockdb) Suicide(address types.AddressHash) bool

Suicide suicide.

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 New

func New(rootHash, utxoRootHash *corecrypto.HashType, db storage.Table) (*StateDB, error)

New a new state from a given trie.

func (*StateDB) AddBalance

func (s *StateDB) AddBalance(addr types.AddressHash, amount *big.Int)

AddBalance adds amount to the account associated with addr

func (*StateDB) AddLog

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

AddLog add log

func (*StateDB) AddPreimage

func (s *StateDB) AddPreimage(hash corecrypto.HashType, preimage []byte)

AddPreimage records a SHA3 preimage seen by the VM.

func (*StateDB) AddRefund

func (s *StateDB) AddRefund(gas uint64)

AddRefund add refund

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

func (s *StateDB) Copy() *StateDB

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:

  1. sends funds to sha(account ++ (nonce + 1))
  2. 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

func (s *StateDB) Database() storage.Table

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) Error

func (s *StateDB) Error() error

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) GetRefund

func (s *StateDB) GetRefund() uint64

GetRefund returns the current value of the refund counter.

func (*StateDB) GetState

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) Logs

func (s *StateDB) Logs() []*types.Log

Logs logs

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

func (s *StateDB) Reset() error

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

func (s *StateDB) RevertToSnapshot(revid int)

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) Snapshot

func (s *StateDB) Snapshot() int

Snapshot returns an identifier for the current revision of the 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) String

func (s *StateDB) String() string

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

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(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

type Storage

Storage ...

func (Storage) Copy

func (s Storage) Copy() Storage

Copy new a new storage by last one.

func (Storage) String

func (s Storage) String() (str string)

Jump to

Keyboard shortcuts

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