Documentation ¶
Overview ¶
Package ngstate provides a global account status manager which controls all accounts and balance besides that, the manager can do generating current sheet for fast sync
ngstate can get init from genesis sheet or remote sheet.
To use ngstate, dev should init these modules first - ngblocks - storage
Index ¶
- Variables
- func CheckBlockTxs(txn *bbolt.Tx, block *ngtypes.FullBlock) error
- func CheckTx(txn *bbolt.Tx, tx *ngtypes.FullTx) error
- type SnapshotManager
- func (sm *SnapshotManager) GetSnapshot(height uint64, hash []byte) *ngtypes.Sheet
- func (sm *SnapshotManager) GetSnapshotByHash(hash []byte) *ngtypes.Sheet
- func (sm *SnapshotManager) GetSnapshotByHeight(height uint64) *ngtypes.Sheet
- func (sm *SnapshotManager) PutSnapshot(height uint64, hash []byte, sheet *ngtypes.Sheet)
- type State
- func (state *State) AccountIsRegistered(num uint64) bool
- func (state *State) GetAccountByAddress(address ngtypes.Address) (*ngtypes.Account, error)
- func (state *State) GetAccountByNum(num uint64) (account *ngtypes.Account, err error)
- func (state *State) GetMatureBalanceByAddress(address ngtypes.Address) (*big.Int, error)
- func (state *State) GetMatureBalanceByNum(num uint64) (*big.Int, error)
- func (state *State) GetSnapshot(height uint64, hash []byte) *ngtypes.Sheet
- func (state *State) GetTotalBalanceByAddress(address ngtypes.Address) (*big.Int, error)
- func (state *State) GetTotalBalanceByNum(num uint64) (*big.Int, error)
- func (state *State) HandleTxs(txn *bbolt.Tx, txs ...*ngtypes.FullTx) (err error)
- func (state *State) RebuildFromBlockStore() error
- func (state *State) RebuildFromSheet(sheet *ngtypes.Sheet) error
- func (state *State) Upgrade(txn *bbolt.Tx, block *ngtypes.FullBlock) error
- type VM
Constants ¶
This section is empty.
Variables ¶
var ( ErrTxRegExcess = errors.New("one address can only register one accounts") ErrTxRegExist = errors.New("account is already registered by others") )
var ( ErrPosOutOfBound = errors.New("pos out of bound") ErrLenExcess = errors.New("length is excess") ErrLenInvalid = errors.New("length is invalid") )
var ErrDestroyAccountContractNotEmpty = errors.New("contract should be empty on destroy tx")
var ErrOutOfMem = errors.New("out of the allocated memory")
var ErrSnapshotNofFound = errors.New("cannot find the snapshot")
var ErrTxrBalanceInsufficient = errors.New("account's balance is not sufficient for the tx")
Functions ¶
func CheckBlockTxs ¶
CheckBlockTxs will check all requirements for txs in block
Types ¶
type SnapshotManager ¶
func (*SnapshotManager) GetSnapshot ¶
func (sm *SnapshotManager) GetSnapshot(height uint64, hash []byte) *ngtypes.Sheet
GetSnapshot return the snapshot in a balance sheet at a height, and doo hash check for external use with security ensure
func (*SnapshotManager) GetSnapshotByHash ¶
func (sm *SnapshotManager) GetSnapshotByHash(hash []byte) *ngtypes.Sheet
GetSnapshotByHash return the snapshot in a balance sheet with the hash for internal use only
func (*SnapshotManager) GetSnapshotByHeight ¶
func (sm *SnapshotManager) GetSnapshotByHeight(height uint64) *ngtypes.Sheet
GetSnapshotByHeight return the snapshot in a balance sheet at a height, without hash check for internal use only
func (*SnapshotManager) PutSnapshot ¶
func (sm *SnapshotManager) PutSnapshot(height uint64, hash []byte, sheet *ngtypes.Sheet)
type State ¶
type State struct { Network ngtypes.Network *bbolt.DB *SnapshotManager // contains filtered or unexported fields }
State is a global set of account & txs status (nil) --> B0(Prev: S0) --> B1(Prev: S1) -> B2(Prev: S2)
init (S0,S0) --> (S0,S1) --> (S1, S2)
func InitStateFromGenesis ¶
InitStateFromGenesis will initialize the state in the given db, with the default genesis sheet data
func InitStateFromSheet ¶
InitStateFromSheet will initialize the state in the given db, with the sheet data this func is written for snapshot sync/converging when initializing from non-genesis checkpoint
func (*State) AccountIsRegistered ¶
AccountIsRegistered checks whether the account is registered in state
func (*State) GetAccountByAddress ¶
GetAccountByAddress returns an ngtypes.Account obj by the account's address this is a heavy action, so dont called by any internal part like p2p and consensus
func (*State) GetAccountByNum ¶
GetAccountByNum returns an ngtypes.Account obj by the account's number
func (*State) GetMatureBalanceByAddress ¶
GetMatureBalanceByAddress get the locked balance of account by the account's address
func (*State) GetMatureBalanceByNum ¶
GetMatureBalanceByNum get the balance of account by the account's num
func (*State) GetSnapshot ¶
func (*State) GetTotalBalanceByAddress ¶
GetTotalBalanceByAddress get the total balance of account by the account's address
func (*State) GetTotalBalanceByNum ¶
GetTotalBalanceByNum get the balance of account by the account's num
func (*State) RebuildFromBlockStore ¶
RebuildFromBlockStore works for doing converge and remove all
func (*State) RebuildFromSheet ¶
RebuildFromSheet will overwrite a state from the given sheet