Documentation ¶
Overview ¶
Package state manages the main accounts trie. It follows the flow as bellow:
o | [ revert-able state ] | [ stacked map ] -> [ journal ] -> [ playback(staging) ] -> [ updated trie ] | [ trie cache ] | [ read-only trie ]
It's much simpler than Ethereum's stateDB. An important difference with stateDB is the logic of account suicide. TODO: explain more
Index ¶
- Constants
- func StorageTrieName(sid []byte) string
- type Account
- type AccountMetadata
- type Error
- type Stage
- type State
- func (s *State) BuildStorageTrie(addr thor.Address) (trie *muxdb.Trie, err error)
- func (s *State) Checkout(root thor.Bytes32, blockNum, blockConflicts, steadyBlockNum uint32) *State
- func (s *State) DecodeStorage(addr thor.Address, key thor.Bytes32, dec func([]byte) error) error
- func (s *State) Delete(addr thor.Address)
- func (s *State) EncodeStorage(addr thor.Address, key thor.Bytes32, enc func() ([]byte, error)) error
- func (s *State) Exists(addr thor.Address) (bool, error)
- func (s *State) GetBalance(addr thor.Address) (*big.Int, error)
- func (s *State) GetCode(addr thor.Address) ([]byte, error)
- func (s *State) GetCodeHash(addr thor.Address) (thor.Bytes32, error)
- func (s *State) GetEnergy(addr thor.Address, blockTime uint64) (*big.Int, error)
- func (s *State) GetMaster(addr thor.Address) (thor.Address, error)
- func (s *State) GetRawStorage(addr thor.Address, key thor.Bytes32) (rlp.RawValue, error)
- func (s *State) GetStorage(addr thor.Address, key thor.Bytes32) (thor.Bytes32, error)
- func (s *State) NewCheckpoint() int
- func (s *State) RevertTo(revision int)
- func (s *State) SetBalance(addr thor.Address, balance *big.Int) error
- func (s *State) SetCode(addr thor.Address, code []byte) error
- func (s *State) SetEnergy(addr thor.Address, energy *big.Int, blockTime uint64) error
- func (s *State) SetMaster(addr thor.Address, master thor.Address) error
- func (s *State) SetRawStorage(addr thor.Address, key thor.Bytes32, raw rlp.RawValue)
- func (s *State) SetStorage(addr thor.Address, key, value thor.Bytes32)
- func (s *State) Stage(newBlockNum, newBlockConflicts uint32) (*Stage, error)
- type Stater
Constants ¶
const ( // AccountTrieName is the name of account trie. AccountTrieName = "a" StorageTrieNamePrefix = "s" )
Variables ¶
This section is empty.
Functions ¶
func StorageTrieName ¶
StorageTrieName converts the storage id into the name of storage trie. It'll panic when empty sid passed.
Types ¶
type Account ¶
type Account struct { Balance *big.Int Energy *big.Int BlockTime uint64 Master []byte // master address CodeHash []byte // hash of code StorageRoot []byte // merkle root of the storage trie }
Account is the Thor consensus representation of an account. RLP encoded objects are stored in main account trie.
func (*Account) CalcEnergy ¶
CalcEnergy calculates energy based on current block time.
type AccountMetadata ¶
type AccountMetadata struct { StorageID []byte // the unique id of the storage trie. StorageCommitNum uint32 // the commit number of the last storage update. StorageDistinctNum uint32 // the distinct number of the last storage update. }
AccountMetadata is the account metadata.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error is the error caused by state access failure.
type Stage ¶
type Stage struct {
// contains filtered or unexported fields
}
Stage abstracts changes on the main accounts trie.
type State ¶
type State struct {
// contains filtered or unexported fields
}
State manages the world state.
func New ¶
func New(db *muxdb.MuxDB, root thor.Bytes32, blockNum, blockConflicts, steadyBlockNum uint32) *State
New create state object.
func (*State) BuildStorageTrie ¶
BuildStorageTrie build up storage trie for given address with cumulative changes.
func (*State) DecodeStorage ¶
DecodeStorage get and decode storage value. Error returned by dec will be absorbed by State instance.
func (*State) Delete ¶
Delete delete an account at the given address. That's set balance, energy and code to zero value.
func (*State) EncodeStorage ¶
func (s *State) EncodeStorage(addr thor.Address, key thor.Bytes32, enc func() ([]byte, error)) error
EncodeStorage set storage value encoded by given enc method. Error returned by end will be absorbed by State instance.
func (*State) Exists ¶
Exists returns whether an account exists at the given address. See Account.IsEmpty()
func (*State) GetBalance ¶
GetBalance returns balance for the given address.
func (*State) GetCodeHash ¶
GetCodeHash returns code hash for the given address.
func (*State) GetMaster ¶
GetMaster get master for the given address. Master can move energy, manage users...
func (*State) GetRawStorage ¶
GetRawStorage returns storage value in rlp raw for given address and key.
func (*State) GetStorage ¶
GetStorage returns storage value for the given address and key.
func (*State) NewCheckpoint ¶
NewCheckpoint makes a checkpoint of current state. It returns revision of the checkpoint.
func (*State) SetBalance ¶
SetBalance set balance for the given address.
func (*State) SetRawStorage ¶
SetRawStorage set storage value in rlp raw.
func (*State) SetStorage ¶
SetStorage set storage value for the given address and key.