Documentation ¶
Index ¶
- Variables
- func RegisterAccount(Name string, Factory AccountFactory, Validator AccountValidator) error
- func RegisterEvent(Name string, Factory EventFactory) error
- func RegisterTransaction(Name string, Factory TransactionFactory, Validator TransactionValidator, ...) error
- type AccountFactory
- type AccountValidator
- type Accounter
- func (act *Accounter) ChainCoord() *common.Coordinate
- func (act *Accounter) NameByType(t account.Type) (string, error)
- func (act *Accounter) NewByType(t account.Type) (account.Account, error)
- func (act *Accounter) NewByTypeName(name string) (account.Account, error)
- func (act *Accounter) RegisterType(Name string, t account.Type) error
- func (act *Accounter) TypeByName(name string) (account.Type, error)
- func (act *Accounter) Validate(loader Loader, acc account.Account, signers []common.PublicHash) error
- type Context
- func (ctx *Context) Account(addr common.Address) (account.Account, error)
- func (ctx *Context) AccountData(addr common.Address, name []byte) []byte
- func (ctx *Context) AccountDataKeys(addr common.Address, Prefix []byte) ([][]byte, error)
- func (ctx *Context) Accounter() *Accounter
- func (ctx *Context) AddLockedBalance(Address common.Address, Amount *amount.Amount, UnlockHeight uint32)
- func (ctx *Context) AddSeq(addr common.Address)
- func (ctx *Context) AddressByName(Name string) (common.Address, error)
- func (ctx *Context) ChainCoord() *common.Coordinate
- func (ctx *Context) Commit(sn int)
- func (ctx *Context) CreateAccount(acc account.Account) error
- func (ctx *Context) CreateUTXO(id uint64, vout *transaction.TxOut) error
- func (ctx *Context) DeleteAccount(acc account.Account) error
- func (ctx *Context) DeleteUTXO(id uint64) error
- func (ctx *Context) Dump() string
- func (ctx *Context) EmitEvent(e event.Event) error
- func (ctx *Context) Eventer() *Eventer
- func (ctx *Context) Hash() hash.Hash256
- func (ctx *Context) IsExistAccount(addr common.Address) (bool, error)
- func (ctx *Context) IsExistAccountName(Name string) (bool, error)
- func (ctx *Context) IsExistUTXO(id uint64) (bool, error)
- func (ctx *Context) LastHash() hash.Hash256
- func (ctx *Context) NextContext(NextHash hash.Hash256) *Context
- func (ctx *Context) Provider() chain.Provider
- func (ctx *Context) RemoveLockedBalance(lb *LockedBalance)
- func (ctx *Context) Revert(sn int)
- func (ctx *Context) Seq(addr common.Address) uint64
- func (ctx *Context) SetAccountData(addr common.Address, name []byte, value []byte)
- func (ctx *Context) Snapshot() int
- func (ctx *Context) StackSize() int
- func (ctx *Context) TargetHeight() uint32
- func (ctx *Context) Top() *ContextData
- func (ctx *Context) Transactor() *Transactor
- func (ctx *Context) UTXO(id uint64) (*transaction.UTXO, error)
- type ContextData
- func (ctd *ContextData) Account(addr common.Address) (account.Account, error)
- func (ctd *ContextData) AccountData(addr common.Address, name []byte) []byte
- func (ctd *ContextData) AccountDataKeys(addr common.Address, Prefix []byte) ([][]byte, error)
- func (ctd *ContextData) AddLockedBalance(Address common.Address, Amount *amount.Amount, UnlockHeight uint32)
- func (ctd *ContextData) AddSeq(addr common.Address)
- func (ctd *ContextData) AddressByName(Name string) (common.Address, error)
- func (ctd *ContextData) CreateAccount(acc account.Account) error
- func (ctd *ContextData) CreateUTXO(id uint64, vout *transaction.TxOut) error
- func (ctd *ContextData) DeleteAccount(acc account.Account) error
- func (ctd *ContextData) DeleteUTXO(id uint64) error
- func (ctd *ContextData) Dump() string
- func (ctd *ContextData) EmitEvent(e event.Event) error
- func (ctd *ContextData) Hash() hash.Hash256
- func (ctd *ContextData) IsExistAccount(addr common.Address) (bool, error)
- func (ctd *ContextData) IsExistAccountName(Name string) (bool, error)
- func (ctd *ContextData) IsExistUTXO(id uint64) (bool, error)
- func (ctd *ContextData) RemoveLockedBalance(lb *LockedBalance)
- func (ctd *ContextData) Seq(addr common.Address) uint64
- func (ctd *ContextData) SetAccountData(addr common.Address, name []byte, value []byte)
- func (ctd *ContextData) UTXO(id uint64) (*transaction.UTXO, error)
- type EventFactory
- type EventHandler
- type EventTypeItem
- type Eventer
- func (act *Eventer) ChainCoord() *common.Coordinate
- func (act *Eventer) NameByType(t event.Type) (string, error)
- func (act *Eventer) NewByType(t event.Type) (event.Event, error)
- func (act *Eventer) NewByTypeName(name string) (event.Event, error)
- func (act *Eventer) RegisterType(Name string, t event.Type) error
- func (act *Eventer) TypeByName(name string) (event.Type, error)
- type Loader
- type LockedBalance
- type TransactionExecutor
- type TransactionFactory
- type TransactionValidator
- type Transactor
- func (tran *Transactor) ChainCoord() *common.Coordinate
- func (tran *Transactor) Execute(ctx *Context, tx transaction.Transaction, coord *common.Coordinate) (interface{}, error)
- func (tran *Transactor) NameByType(t transaction.Type) (string, error)
- func (tran *Transactor) NewByType(t transaction.Type) (transaction.Transaction, error)
- func (tran *Transactor) NewByTypeName(name string) (transaction.Transaction, error)
- func (tran *Transactor) RegisterType(Name string, t transaction.Type, Fee *amount.Amount) error
- func (tran *Transactor) TypeByName(name string) (transaction.Type, error)
- func (tran *Transactor) Validate(loader Loader, tx transaction.Transaction, signers []common.PublicHash) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrExistAccount = errors.New("exist account") ErrNotExistAccount = errors.New("not exist account") ErrExistUTXO = errors.New("exist utxo") ErrNotExistUTXO = errors.New("not exist utxo") ErrNotExistEvent = errors.New("not exist event") ErrDoubleSpent = errors.New("double spent") ErrUnknownAccountType = errors.New("unknown account type") ErrNotExistHandler = errors.New("not exist handler") ErrExistHandler = errors.New("exist handler") ErrNotExistAccounter = errors.New("not exist accounter") ErrUnknownTransactionType = errors.New("unknown transaction type") ErrNotExistTransactor = errors.New("not exist transactor") ErrInvalidChainCoordinate = errors.New("invalid chain coordinate") ErrUnknownEventType = errors.New("unknown event type") ErrInvalidAccountName = errors.New("invalid account name") )
data errors
var EventerHandlerMap = map[string]*EventHandler{}
Functions ¶
func RegisterAccount ¶
func RegisterAccount(Name string, Factory AccountFactory, Validator AccountValidator) error
RegisterAccount register account handlers to the global account registry
func RegisterEvent ¶
func RegisterEvent(Name string, Factory EventFactory) error
RegisterEvent register Event handlers to the global Event registry
func RegisterTransaction ¶
func RegisterTransaction(Name string, Factory TransactionFactory, Validator TransactionValidator, Executor TransactionExecutor) error
RegisterTransaction register transaction handlers to the global account registry
Types ¶
type AccountFactory ¶
AccountFactory is a function type to generate an account instance by the type
type AccountValidator ¶
TransactionValidator is a function type to support the validation of the account with signers
type Accounter ¶
type Accounter struct {
// contains filtered or unexported fields
}
Accounter provide account's handlers of the target chain
func NewAccounter ¶
func NewAccounter(ChainCoord *common.Coordinate) *Accounter
NewAccounter returns a Accounter
func (*Accounter) ChainCoord ¶
func (act *Accounter) ChainCoord() *common.Coordinate
ChainCoord returns the coordinate of the target chain
func (*Accounter) NameByType ¶
NameByType returns the name by the type
func (*Accounter) NewByTypeName ¶
NewByTypeName generate an account instance by the name
func (*Accounter) RegisterType ¶
RegisterType add the account type with handler loaded by the name from the global account registry
func (*Accounter) TypeByName ¶
TypeByName returns the type by the name
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context is an intermediate in-memory state using the context data stack between blocks
func (*Context) AccountData ¶
AccountData returns the account data from the top snapshot
func (*Context) AccountDataKeys ¶
AccountDataKeys returns all data keys of the account in the context
func (*Context) AddLockedBalance ¶
func (ctx *Context) AddLockedBalance(Address common.Address, Amount *amount.Amount, UnlockHeight uint32)
AddLockedBalance adds locked balance until the unlock height to the account of the address
func (*Context) AddressByName ¶
AddressByName returns the account address of the name
func (*Context) ChainCoord ¶
func (ctx *Context) ChainCoord() *common.Coordinate
ChainCoord returns the coordinate of the target chain
func (*Context) CreateAccount ¶
CreateAccount inserts the account to the top snapshot
func (*Context) CreateUTXO ¶
func (ctx *Context) CreateUTXO(id uint64, vout *transaction.TxOut) error
CreateUTXO inserts the UTXO to the top snapshot
func (*Context) DeleteAccount ¶
DeleteAccount deletes the account from the top snapshot
func (*Context) DeleteUTXO ¶
DeleteUTXO deletes the UTXO from the top snapshot
func (*Context) IsExistAccount ¶
IsExistAccount checks that the account of the address is exist or not
func (*Context) IsExistAccountName ¶
IsExistAccountName checks that the account of the name is exist or not
func (*Context) IsExistUTXO ¶
IsExistUTXO checks that the utxo of the id is exist or not
func (*Context) NextContext ¶
NextContext returns the next Context of the Context
func (*Context) RemoveLockedBalance ¶
func (ctx *Context) RemoveLockedBalance(lb *LockedBalance)
RemoveLockedBalance removes locked balance to the account of the address
func (*Context) SetAccountData ¶
SetAccountData inserts the account data to the top snapshot
func (*Context) TargetHeight ¶
TargetHeight returns the recorded target height when context generation
func (*Context) Transactor ¶
func (ctx *Context) Transactor() *Transactor
Transactor returns the transactor of the target chain
type ContextData ¶
type ContextData struct { Parent *ContextData SeqMap map[common.Address]uint64 LockedBalances []*LockedBalance DeletedLockedBalances []*LockedBalance AccountMap map[common.Address]account.Account CreatedAccountMap map[common.Address]account.Account DeletedAccountMap map[common.Address]account.Account AccountNameMap map[string]common.Address CreatedAccountNameMap map[string]common.Address DeletedAccountNameMap map[string]common.Address AccountDataMap map[string][]byte DeletedAccountDataMap map[string]bool UTXOMap map[uint64]*transaction.UTXO CreatedUTXOMap map[uint64]*transaction.TxOut DeletedUTXOMap map[uint64]bool Events []event.Event EventIndex uint16 // contains filtered or unexported fields }
ContextData is a state data of the context
func NewContextData ¶
func NewContextData(loader Loader, Parent *ContextData) *ContextData
NewContextData returns a ContextData
func (*ContextData) AccountData ¶
func (ctd *ContextData) AccountData(addr common.Address, name []byte) []byte
AccountData returns the account data
func (*ContextData) AccountDataKeys ¶
AccountDataKeys returns all data keys of the account in the context
func (*ContextData) AddLockedBalance ¶
func (ctd *ContextData) AddLockedBalance(Address common.Address, Amount *amount.Amount, UnlockHeight uint32)
AddLockedBalance adds locked balance until the unlock height to the account of the address
func (*ContextData) AddSeq ¶
func (ctd *ContextData) AddSeq(addr common.Address)
AddSeq update the sequence of the target account
func (*ContextData) AddressByName ¶
func (ctd *ContextData) AddressByName(Name string) (common.Address, error)
AddressByName returns the account address of the name
func (*ContextData) CreateAccount ¶
func (ctd *ContextData) CreateAccount(acc account.Account) error
CreateAccount inserts the account
func (*ContextData) CreateUTXO ¶
func (ctd *ContextData) CreateUTXO(id uint64, vout *transaction.TxOut) error
CreateUTXO inserts the UTXO
func (*ContextData) DeleteAccount ¶
func (ctd *ContextData) DeleteAccount(acc account.Account) error
DeleteAccount deletes the account
func (*ContextData) DeleteUTXO ¶
func (ctd *ContextData) DeleteUTXO(id uint64) error
DeleteUTXO deletes the UTXO
func (*ContextData) EmitEvent ¶
func (ctd *ContextData) EmitEvent(e event.Event) error
EmitEvent creates the event to the top snapshot
func (*ContextData) Hash ¶
func (ctd *ContextData) Hash() hash.Hash256
Hash returns the hash value of it
func (*ContextData) IsExistAccount ¶
func (ctd *ContextData) IsExistAccount(addr common.Address) (bool, error)
IsExistAccount checks that the account of the address is exist or not
func (*ContextData) IsExistAccountName ¶
func (ctd *ContextData) IsExistAccountName(Name string) (bool, error)
IsExistAccountName checks that the account of the address is exist or not
func (*ContextData) IsExistUTXO ¶
func (ctd *ContextData) IsExistUTXO(id uint64) (bool, error)
IsExistUTXO checks that the utxo of the id is exist or not
func (*ContextData) RemoveLockedBalance ¶
func (ctd *ContextData) RemoveLockedBalance(lb *LockedBalance)
RemoveLockedBalance removes locked balance to the account of the address
func (*ContextData) Seq ¶
func (ctd *ContextData) Seq(addr common.Address) uint64
Seq returns the sequence of the account
func (*ContextData) SetAccountData ¶
func (ctd *ContextData) SetAccountData(addr common.Address, name []byte, value []byte)
SetAccountData inserts the account data
func (*ContextData) UTXO ¶
func (ctd *ContextData) UTXO(id uint64) (*transaction.UTXO, error)
UTXO returns the UTXO
type EventFactory ¶
EventFactory is a function type to generate an Event instance by the type
type EventHandler ¶
type EventHandler struct {
Factory EventFactory
}
type EventTypeItem ¶
type EventTypeItem struct { Type event.Type Name string Factory EventFactory }
type Eventer ¶
type Eventer struct {
// contains filtered or unexported fields
}
Eventer provide Event's handlers of the target chain
func NewEventer ¶
func NewEventer(ChainCoord *common.Coordinate) *Eventer
NewEventer returns a Eventer
func (*Eventer) ChainCoord ¶
func (act *Eventer) ChainCoord() *common.Coordinate
ChainCoord returns the coordinate of the target chain
func (*Eventer) NameByType ¶
NameByType returns the name by the type
func (*Eventer) NewByTypeName ¶
NewByTypeName generate an Event instance by the name
func (*Eventer) RegisterType ¶
RegisterType add the Event type with handler loaded by the name from the global Event registry
type Loader ¶
type Loader interface { ChainCoord() *common.Coordinate Accounter() *Accounter Transactor() *Transactor Provider() chain.Provider Eventer() *Eventer TargetHeight() uint32 LastHash() hash.Hash256 Seq(addr common.Address) uint64 Account(addr common.Address) (account.Account, error) AddressByName(Name string) (common.Address, error) IsExistAccount(addr common.Address) (bool, error) IsExistAccountName(Name string) (bool, error) AccountData(addr common.Address, name []byte) []byte AccountDataKeys(addr common.Address, Prefix []byte) ([][]byte, error) IsExistUTXO(id uint64) (bool, error) UTXO(id uint64) (*transaction.UTXO, error) }
Loader is an interface to provide data from the target chain
func NewEmptyLoader ¶
func NewEmptyLoader(coord *common.Coordinate, act *Accounter, tran *Transactor, evt *Eventer) Loader
NewEmptyLoader is used for generating genesis state
type LockedBalance ¶
LockedBalance defines locked balance
func (*LockedBalance) MarshalJSON ¶
func (lb *LockedBalance) MarshalJSON() ([]byte, error)
MarshalJSON is a marshaler function
type TransactionExecutor ¶
type TransactionExecutor func(ctx *Context, Fee *amount.Amount, tx transaction.Transaction, coord *common.Coordinate) (interface{}, error)
TransactionExecutor is a function type to update the context using the transaction and the coordinate of it
type TransactionFactory ¶
type TransactionFactory func(t transaction.Type) transaction.Transaction
TransactionFactory is a function type to generate an account instance by the type
type TransactionValidator ¶
type TransactionValidator func(loader Loader, tx transaction.Transaction, signers []common.PublicHash) error
TransactionValidator is a function type to support the validation of the transaction with signers
type Transactor ¶
type Transactor struct {
// contains filtered or unexported fields
}
Transactor provide transaction's handlers of the target chain
func NewTransactor ¶
func NewTransactor(ChainCoord *common.Coordinate) *Transactor
NewTransactor returns a Transactor
func (*Transactor) ChainCoord ¶
func (tran *Transactor) ChainCoord() *common.Coordinate
ChainCoord returns the coordinate of the target chain
func (*Transactor) Execute ¶
func (tran *Transactor) Execute(ctx *Context, tx transaction.Transaction, coord *common.Coordinate) (interface{}, error)
Execute updates the context using the transaction and the coordinate of it
func (*Transactor) NameByType ¶
func (tran *Transactor) NameByType(t transaction.Type) (string, error)
NameByType returns the name by the type
func (*Transactor) NewByType ¶
func (tran *Transactor) NewByType(t transaction.Type) (transaction.Transaction, error)
NewByType generate an transaction instance by the type
func (*Transactor) NewByTypeName ¶
func (tran *Transactor) NewByTypeName(name string) (transaction.Transaction, error)
NewByTypeName generate an transaction instance by the name
func (*Transactor) RegisterType ¶
func (tran *Transactor) RegisterType(Name string, t transaction.Type, Fee *amount.Amount) error
RegisterType add the transaction type with handler loaded by the name from the global transaction registry
func (*Transactor) TypeByName ¶
func (tran *Transactor) TypeByName(name string) (transaction.Type, error)
TypeByName returns the type by the name
func (*Transactor) Validate ¶
func (tran *Transactor) Validate(loader Loader, tx transaction.Transaction, signers []common.PublicHash) error
Validate supports the validation of the transaction with signers