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 ¶
- type Account
- type Creator
- type Stage
- type State
- func (s *State) BuildStorageTrie(addr powerplay.Address) (*trie.SecureTrie, error)
- func (s *State) DecodeStorage(addr powerplay.Address, key powerplay.Bytes32, dec func([]byte) error)
- func (s *State) Delete(addr powerplay.Address)
- func (s *State) EncodeStorage(addr powerplay.Address, key powerplay.Bytes32, enc func() ([]byte, error))
- func (s *State) Err() error
- func (s *State) Exists(addr powerplay.Address) bool
- func (s *State) GetBalance(addr powerplay.Address) *big.Int
- func (s *State) GetCode(addr powerplay.Address) []byte
- func (s *State) GetCodeHash(addr powerplay.Address) powerplay.Bytes32
- func (s *State) GetEnergy(addr powerplay.Address, blockTime uint64) *big.Int
- func (s *State) GetMaster(addr powerplay.Address) powerplay.Address
- func (s *State) GetRawStorage(addr powerplay.Address, key powerplay.Bytes32) rlp.RawValue
- func (s *State) GetStorage(addr powerplay.Address, key powerplay.Bytes32) powerplay.Bytes32
- func (s *State) NewCheckpoint() int
- func (s *State) RevertTo(revision int)
- func (s *State) SetBalance(addr powerplay.Address, balance *big.Int)
- func (s *State) SetCode(addr powerplay.Address, code []byte)
- func (s *State) SetEnergy(addr powerplay.Address, energy *big.Int, blockTime uint64)
- func (s *State) SetMaster(addr powerplay.Address, master powerplay.Address)
- func (s *State) SetRawStorage(addr powerplay.Address, key powerplay.Bytes32, raw rlp.RawValue)
- func (s *State) SetStorage(addr powerplay.Address, key, value powerplay.Bytes32)
- func (s *State) Spawn(root powerplay.Bytes32) *State
- func (s *State) Stage() *Stage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
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 PowerPlay 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 Creator ¶
type Creator struct {
// contains filtered or unexported fields
}
Creator state creator to cut-off kv dependency.
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 main accounts trie.
func (*State) BuildStorageTrie ¶
BuildStorageTrie build up storage trie for given address with cumulative changes.
func (*State) DecodeStorage ¶
func (s *State) DecodeStorage(addr powerplay.Address, key powerplay.Bytes32, dec func([]byte) error)
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 powerplay.Address, key powerplay.Bytes32, enc func() ([]byte, 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.