statedb

package
v2.5.2 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StateName   = "state"
	StateLatest = StateName + ".latest"
)

Variables

View Source
var (
	EmptyHashID    = types.HashID{}
	EmptyBlockID   = types.BlockID{}
	EmptyAccountID = types.AccountID{}
)
View Source
var (
	StateMarker = []byte{0x54, 0x45} // marker: tail end
)

Functions

func Marshal

func Marshal(data interface{}) ([]byte, error)

func StageContractState

func StageContractState(st *ContractState, states *StateDB) error

Types

type ContractState

type ContractState struct {
	*types.State
	// contains filtered or unexported fields
}

func GetEnterpriseAccountState

func GetEnterpriseAccountState(states *StateDB) (*ContractState, error)

GetEnterpriseAccountState returns the ContractState of the AERGO enterprise account.

func GetNameAccountState

func GetNameAccountState(states *StateDB) (*ContractState, error)

GetNameAccountState returns the ContractState of the AERGO name account.

func GetSystemAccountState

func GetSystemAccountState(states *StateDB) (*ContractState, error)

GetSystemAccountState returns the ContractState of the AERGO system account.

func OpenContractState

func OpenContractState(id []byte, st *types.State, states *StateDB) (*ContractState, error)

func OpenContractStateAccount

func OpenContractStateAccount(id []byte, states *StateDB) (*ContractState, error)

func (*ContractState) DeleteData

func (cs *ContractState) DeleteData(key []byte) error

DeleteData remove key and value pair from the storage.

func (*ContractState) GetAccountID

func (cs *ContractState) GetAccountID() types.AccountID

func (*ContractState) GetCode

func (cs *ContractState) GetCode() ([]byte, error)

func (*ContractState) GetData

func (cs *ContractState) GetData(key []byte) ([]byte, error)

GetData returns the value corresponding to the key from the buffered storage.

func (*ContractState) GetID

func (cs *ContractState) GetID() []byte

func (*ContractState) GetInitialData

func (cs *ContractState) GetInitialData(key []byte) ([]byte, error)

GetInitialData returns the value corresponding to the key from the contract storage.

func (*ContractState) GetRawKV

func (cs *ContractState) GetRawKV(key []byte) ([]byte, error)

GetRawKV loads (key, value) from st.store.

func (*ContractState) HasKey

func (cs *ContractState) HasKey(key []byte) bool

HasKey returns existence of the key

func (*ContractState) Hash

func (cs *ContractState) Hash() []byte

Hash implements types.ImplHashBytes

func (*ContractState) Marshal

func (cs *ContractState) Marshal() ([]byte, error)

Marshal implements types.ImplMarshal

func (*ContractState) Rollback

func (cs *ContractState) Rollback(revision Snapshot) error

Rollback discards changes of storage buffer to revision number

func (*ContractState) SetCode

func (cs *ContractState) SetCode(code []byte) error

func (*ContractState) SetData

func (cs *ContractState) SetData(key, value []byte) error

SetData store key and value pair to the storage.

func (*ContractState) SetRawKV

func (cs *ContractState) SetRawKV(key []byte, value []byte) error

SetRawKV saves (key, value) to st.store without any kind of encoding.

func (*ContractState) Snapshot

func (cs *ContractState) Snapshot() Snapshot

Snapshot returns revision number of storage buffer

type Dump

type Dump struct {
	Root     []byte                          `json:"root"`
	Accounts map[types.AccountID]DumpAccount `json:"accounts"`
}

func (Dump) MarshalJSON

func (d Dump) MarshalJSON() ([]byte, error)

type DumpAccount

type DumpAccount struct {
	State   *types.State
	Code    []byte
	Storage map[types.AccountID][]byte
}

func (DumpAccount) MarshalJSON

func (d DumpAccount) MarshalJSON() ([]byte, error)

type Snapshot

type Snapshot int

Snapshot represents revision number of statedb

type StateDB

type StateDB struct {
	Buffer   *stateBuffer
	Cache    *storageCache
	Trie     *trie.Trie
	Store    db.DB
	Testmode bool
	// contains filtered or unexported fields
}

StateDB manages trie of states

func NewStateDB

func NewStateDB(dbstore db.DB, root []byte, test bool) *StateDB

NewStateDB craete StateDB instance

func (*StateDB) Clone

func (states *StateDB) Clone() *StateDB

Clone returns a new StateDB which has same store and Root

func (*StateDB) Commit

func (states *StateDB) Commit() error

Commit writes state buffer and trie to db

func (*StateDB) Dump

func (sdb *StateDB) Dump() ([]byte, error)

func (*StateDB) GetAccountAndProof

func (states *StateDB) GetAccountAndProof(id []byte, root []byte, compressed bool) (*types.AccountProof, error)

GetAccountAndProof gets the state and associated proof of an account in the given trie root. If the account doesnt exist, a proof of non existence is returned.

func (*StateDB) GetAccountState

func (states *StateDB) GetAccountState(id types.AccountID) (*types.State, error)

GetAccountState gets state of account id from statedb. empty state is returned when there is no state corresponding to account id.

func (*StateDB) GetRoot

func (states *StateDB) GetRoot() []byte

GetRoot returns root hash of trie

func (*StateDB) GetState

func (states *StateDB) GetState(id types.AccountID) (*types.State, error)

GetState gets state of account id from state buffer and trie. nil value is returned when there is no state corresponding to account id.

func (*StateDB) GetVarAndProof

func (states *StateDB) GetVarAndProof(id []byte, root []byte, compressed bool) (*types.ContractVarProof, error)

GetVarAndProof gets the value of a variable in the given contract trie root.

func (*StateDB) HasMarker

func (states *StateDB) HasMarker(root []byte) bool

HasMarker represents that the state root is finalized or not.

func (*StateDB) IsLegacyTrieKey

func (states *StateDB) IsLegacyTrieKey() bool

func (*StateDB) LoadCache

func (states *StateDB) LoadCache(root []byte) error

LoadCache reads first layer of trie given root hash and also updates root node of trie as a given root hash

func (*StateDB) PutState

func (states *StateDB) PutState(id types.AccountID, state *types.State) error

PutState puts account id and its state into state buffer.

func (*StateDB) RawDump

func (sdb *StateDB) RawDump() (Dump, error)

func (*StateDB) Revert

func (states *StateDB) Revert(root types.HashID) error

Revert rollbacks trie to previous root hash

func (*StateDB) Rollback

func (states *StateDB) Rollback(revision Snapshot) error

Rollback discards changes of state buffer to revision number

func (*StateDB) SetRoot

func (states *StateDB) SetRoot(root []byte) error

SetRoot updates root node of trie as a given root hash

func (*StateDB) Snapshot

func (states *StateDB) Snapshot() Snapshot

Snapshot returns revision number of state buffer

func (*StateDB) TrieQuery

func (states *StateDB) TrieQuery(id []byte, root []byte, compressed bool) ([]byte, [][]byte, int, bool, []byte, []byte, error)

func (*StateDB) Update

func (states *StateDB) Update() error

Update applies changes of state buffer to trie

Jump to

Keyboard shortcuts

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