Version: v0.0.0-...-8d08d5c Latest Latest

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

Go to latest
Published: Feb 26, 2021 License: GPL-3.0 Imports: 15 Imported by: 0



Package ngstate provides a global account status manager which controls all accounts and balance besides that, the manager can do generating current sheet for fasy sync

ngstate can get init from genesis sheet or remote sheet.

To use ngstate, dev should init these modules first - ngblocks - storage



This section is empty.


This section is empty.


func CheckBlockTxs

func CheckBlockTxs(txn *badger.Txn, block *ngtypes.Block) error

CheckBlockTxs will check all requirements for txs in block

func CheckTx

func CheckTx(txn *badger.Txn, tx *ngtypes.Tx) error

CheckTx will check the requirements for one tx (except generate tx)


type State

type State struct {
	// 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

func InitStateFromGenesis(db *badger.DB, network ngtypes.NetworkType) *State

InitStateFromGenesis will initialize the state in the given db, with the default genesis sheet data

func InitStateFromSheet

func InitStateFromSheet(db *badger.DB, sheet *ngtypes.Sheet) *State

InitStateFromSheet will initialize the state in the given db, with the sheet data

func (*State) AccountIsRegistered

func (state *State) AccountIsRegistered(num uint64) bool

AccountIsRegistered checks whether the account is registered in state

func (*State) GetAccountByAddress

func (state *State) GetAccountByAddress(address ngtypes.Address) (*ngtypes.Account, error)

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

func (state *State) GetAccountByNum(num uint64) (account *ngtypes.Account, err error)

GetAccountByNum returns an ngtypes.Account obj by the account's number

func (*State) GetBalanceByAddress

func (state *State) GetBalanceByAddress(address ngtypes.Address) (*big.Int, error)

GetBalanceByAddress get the balance of account by the account's address

func (*State) GetBalanceByNum

func (state *State) GetBalanceByNum(num uint64) (*big.Int, error)

GetBalanceByNum get the balance of account by the account's num

func (*State) HandleTxs

func (state *State) HandleTxs(txn *badger.Txn, txs ...*ngtypes.Tx) (err error)

HandleTxs will apply the tx into the state if tx is VALID

func (*State) Regenerate

func (state *State) Regenerate() error

Regenerate works for doing fork and remove all

func (*State) ToSheet

func (state *State) ToSheet() *ngtypes.Sheet

ToSheet will conclude a sheet which has all status of all accounts & keys(if balance not nil)

func (*State) Upgrade

func (state *State) Upgrade(txn *badger.Txn, block *ngtypes.Block) error

Upgrade will apply block's txs on current state

type VM

type VM struct {
	// contains filtered or unexported fields

VM is a vm based on wasmtime, which acts as a sandbox env to exec native func

func NewVM

func NewVM(txn *badger.Txn, account *ngtypes.Account) (*VM, error)

NewVM creates a new Wasm call me when a assign or append tx

func (*VM) CallOnTx

func (vm *VM) CallOnTx(ins *wasman.Instance)

CallOnTx when applying new tx

func (*VM) InitBuiltInImports

func (vm *VM) InitBuiltInImports() error

InitBuiltInImports will bind go's host func with the contract module

func (*VM) Instantiate

func (vm *VM) Instantiate(tx *ngtypes.Tx) (*wasman.Instance, error)

Instantiate will generate a runnable instance from thr module before Instantiate, the caller should run Init

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL