Documentation ¶
Overview ¶
Package state manages the main accounts trie. It follows the flow as bellow:
o | [ revertable 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(addressHash luckyshare.Bytes32) string
- type Account
- type Error
- type Stage
- type State
- func (s *State) BuildStorageTrie(addr luckyshare.Address) (*muxdb.Trie, error)
- func (s *State) DecodeStorage(addr luckyshare.Address, key luckyshare.Bytes32, dec func([]byte) error) error
- func (s *State) Delete(addr luckyshare.Address)
- func (s *State) EncodeStorage(addr luckyshare.Address, key luckyshare.Bytes32, enc func() ([]byte, error)) error
- func (s *State) Exists(addr luckyshare.Address) (bool, error)
- func (s *State) GetBalance(addr luckyshare.Address) (*big.Int, error)
- func (s *State) GetCode(addr luckyshare.Address) ([]byte, error)
- func (s *State) GetCodeHash(addr luckyshare.Address) (luckyshare.Bytes32, error)
- func (s *State) GetEnergy(addr luckyshare.Address, blockTime uint64) (*big.Int, error)
- func (s *State) GetMaster(addr luckyshare.Address) (luckyshare.Address, error)
- func (s *State) GetRawStorage(addr luckyshare.Address, key luckyshare.Bytes32) (rlp.RawValue, error)
- func (s *State) GetStorage(addr luckyshare.Address, key luckyshare.Bytes32) (luckyshare.Bytes32, error)
- func (s *State) NewCheckpoint() int
- func (s *State) NewStater() *Stater
- func (s *State) RevertTo(revision int)
- func (s *State) SetBalance(addr luckyshare.Address, balance *big.Int) error
- func (s *State) SetCode(addr luckyshare.Address, code []byte) error
- func (s *State) SetEnergy(addr luckyshare.Address, energy *big.Int, blockTime uint64) error
- func (s *State) SetMaster(addr luckyshare.Address, master luckyshare.Address) error
- func (s *State) SetRawStorage(addr luckyshare.Address, key luckyshare.Bytes32, raw rlp.RawValue)
- func (s *State) SetStorage(addr luckyshare.Address, key, value luckyshare.Bytes32)
- func (s *State) Stage() (*Stage, error)
- type Stater
Constants ¶
const (
// AccountTrieName is the name of account trie.
AccountTrieName = "a"
)
Variables ¶
This section is empty.
Functions ¶
func StorageTrieName ¶
func StorageTrieName(addressHash luckyshare.Bytes32) string
StorageTrieName returns the name of storage trie.
Each storage trie has a unique name, which can improve IO performance.
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 Luckyshare 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 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.
func (*Stage) Commit ¶
func (s *Stage) Commit() (luckyshare.Bytes32, error)
Commit commits all changes into main accounts trie and storage tries.
func (*Stage) Hash ¶
func (s *Stage) Hash() luckyshare.Bytes32
Hash computes hash of the main accounts trie.
type State ¶
type State struct {
// contains filtered or unexported fields
}
State manages the world state.
func (*State) BuildStorageTrie ¶
BuildStorageTrie build up storage trie for given address with cumulative changes.
func (*State) DecodeStorage ¶
func (s *State) DecodeStorage(addr luckyshare.Address, key luckyshare.Bytes32, dec func([]byte) error) error
DecodeStorage get and decode storage value. Error returned by dec will be absorbed by State instance.
func (*State) Delete ¶
func (s *State) Delete(addr luckyshare.Address)
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 luckyshare.Address, key luckyshare.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 ¶
func (s *State) Exists(addr luckyshare.Address) (bool, error)
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) GetCode ¶
func (s *State) GetCode(addr luckyshare.Address) ([]byte, error)
GetCode returns code for the given address.
func (*State) GetCodeHash ¶
func (s *State) GetCodeHash(addr luckyshare.Address) (luckyshare.Bytes32, error)
GetCodeHash returns code hash for the given address.
func (*State) GetMaster ¶
func (s *State) GetMaster(addr luckyshare.Address) (luckyshare.Address, error)
GetMaster get master for the given address. Master can move energy, manage users...
func (*State) GetRawStorage ¶
func (s *State) GetRawStorage(addr luckyshare.Address, key luckyshare.Bytes32) (rlp.RawValue, error)
GetRawStorage returns storage value in rlp raw for given address and key.
func (*State) GetStorage ¶
func (s *State) GetStorage(addr luckyshare.Address, key luckyshare.Bytes32) (luckyshare.Bytes32, error)
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) SetCode ¶
func (s *State) SetCode(addr luckyshare.Address, code []byte) error
SetCode set code for the given address.
func (*State) SetMaster ¶
func (s *State) SetMaster(addr luckyshare.Address, master luckyshare.Address) error
SetMaster set master for the given address.
func (*State) SetRawStorage ¶
func (s *State) SetRawStorage(addr luckyshare.Address, key luckyshare.Bytes32, raw rlp.RawValue)
SetRawStorage set storage value in rlp raw.
func (*State) SetStorage ¶
func (s *State) SetStorage(addr luckyshare.Address, key, value luckyshare.Bytes32)
SetStorage set storage value for the given address and key.