data

package
v0.0.0-...-4701ab3 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2019 License: LGPL-3.0 Imports: 15 Imported by: 19

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

View Source
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

type AccountFactory func(t account.Type) account.Account

AccountFactory is a function type to generate an account instance by the type

type AccountValidator

type AccountValidator func(loader Loader, acc account.Account, signers []common.PublicHash) error

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

func (act *Accounter) NameByType(t account.Type) (string, error)

NameByType returns the name by the type

func (*Accounter) NewByType

func (act *Accounter) NewByType(t account.Type) (account.Account, error)

NewByType generate an account instance by the type

func (*Accounter) NewByTypeName

func (act *Accounter) NewByTypeName(name string) (account.Account, error)

NewByTypeName generate an account instance by the name

func (*Accounter) RegisterType

func (act *Accounter) RegisterType(Name string, t account.Type) error

RegisterType add the account type with handler loaded by the name from the global account registry

func (*Accounter) TypeByName

func (act *Accounter) TypeByName(name string) (account.Type, error)

TypeByName returns the type by the name

func (*Accounter) Validate

func (act *Accounter) Validate(loader Loader, acc account.Account, signers []common.PublicHash) error

Validate supports the validation of the account with signers

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 NewContext

func NewContext(loader Loader) *Context

NewContext returns a Context

func (*Context) Account

func (ctx *Context) Account(addr common.Address) (account.Account, error)

Account returns the account instance of the address

func (*Context) AccountData

func (ctx *Context) AccountData(addr common.Address, name []byte) []byte

AccountData returns the account data from the top snapshot

func (*Context) AccountDataKeys

func (ctx *Context) AccountDataKeys(addr common.Address, Prefix []byte) ([][]byte, error)

AccountDataKeys returns all data keys of the account in the context

func (*Context) Accounter

func (ctx *Context) Accounter() *Accounter

Accounter returns the accounter of the target chain

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) AddSeq

func (ctx *Context) AddSeq(addr common.Address)

AddSeq update the sequence of the target account

func (*Context) AddressByName

func (ctx *Context) AddressByName(Name string) (common.Address, error)

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) Commit

func (ctx *Context) Commit(sn int)

Commit apply snapshots to the top after the snapshot number

func (*Context) CreateAccount

func (ctx *Context) CreateAccount(acc account.Account) error

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

func (ctx *Context) DeleteAccount(acc account.Account) error

DeleteAccount deletes the account from the top snapshot

func (*Context) DeleteUTXO

func (ctx *Context) DeleteUTXO(id uint64) error

DeleteUTXO deletes the UTXO from the top snapshot

func (*Context) Dump

func (ctx *Context) Dump() string

Dump prints the top context data of the context

func (*Context) EmitEvent

func (ctx *Context) EmitEvent(e event.Event) error

EmitEvent creates the event to the top snapshot

func (*Context) Eventer

func (ctx *Context) Eventer() *Eventer

Eventer returns the eventer of the target chain

func (*Context) Hash

func (ctx *Context) Hash() hash.Hash256

Hash returns the hash value of it

func (*Context) IsExistAccount

func (ctx *Context) IsExistAccount(addr common.Address) (bool, error)

IsExistAccount checks that the account of the address is exist or not

func (*Context) IsExistAccountName

func (ctx *Context) IsExistAccountName(Name string) (bool, error)

IsExistAccountName checks that the account of the name is exist or not

func (*Context) IsExistUTXO

func (ctx *Context) IsExistUTXO(id uint64) (bool, error)

IsExistUTXO checks that the utxo of the id is exist or not

func (*Context) LastHash

func (ctx *Context) LastHash() hash.Hash256

LastHash returns the recorded prev hash when context generation

func (*Context) NextContext

func (ctx *Context) NextContext(NextHash hash.Hash256) *Context

NextContext returns the next Context of the Context

func (*Context) Provider

func (ctx *Context) Provider() chain.Provider

Provider returns the provider of the target chain

func (*Context) RemoveLockedBalance

func (ctx *Context) RemoveLockedBalance(lb *LockedBalance)

RemoveLockedBalance removes locked balance to the account of the address

func (*Context) Revert

func (ctx *Context) Revert(sn int)

Revert removes snapshots after the snapshot number

func (*Context) Seq

func (ctx *Context) Seq(addr common.Address) uint64

Seq returns the sequence of the target account

func (*Context) SetAccountData

func (ctx *Context) SetAccountData(addr common.Address, name []byte, value []byte)

SetAccountData inserts the account data to the top snapshot

func (*Context) Snapshot

func (ctx *Context) Snapshot() int

Snapshot push a snapshot and returns the snapshot number of it

func (*Context) StackSize

func (ctx *Context) StackSize() int

StackSize returns the size of the context data stack

func (*Context) TargetHeight

func (ctx *Context) TargetHeight() uint32

TargetHeight returns the recorded target height when context generation

func (*Context) Top

func (ctx *Context) Top() *ContextData

Top returns the top snapshot

func (*Context) Transactor

func (ctx *Context) Transactor() *Transactor

Transactor returns the transactor of the target chain

func (*Context) UTXO

func (ctx *Context) UTXO(id uint64) (*transaction.UTXO, error)

UTXO returns the UTXO from the top snapshot

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) Account

func (ctd *ContextData) Account(addr common.Address) (account.Account, error)

Account returns the account instance of the address

func (*ContextData) AccountData

func (ctd *ContextData) AccountData(addr common.Address, name []byte) []byte

AccountData returns the account data

func (*ContextData) AccountDataKeys

func (ctd *ContextData) AccountDataKeys(addr common.Address, Prefix []byte) ([][]byte, error)

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) Dump

func (ctd *ContextData) Dump() string

Dump prints the context data

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

type EventFactory func(t event.Type) event.Event

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

func (act *Eventer) NameByType(t event.Type) (string, error)

NameByType returns the name by the type

func (*Eventer) NewByType

func (act *Eventer) NewByType(t event.Type) (event.Event, error)

NewByType generate an Event instance by the type

func (*Eventer) NewByTypeName

func (act *Eventer) NewByTypeName(name string) (event.Event, error)

NewByTypeName generate an Event instance by the name

func (*Eventer) RegisterType

func (act *Eventer) RegisterType(Name string, t event.Type) error

RegisterType add the Event type with handler loaded by the name from the global Event registry

func (*Eventer) TypeByName

func (act *Eventer) TypeByName(name string) (event.Type, error)

TypeByName returns the type by the name

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

type LockedBalance struct {
	Address      common.Address
	Amount       *amount.Amount
	UnlockHeight uint32
}

LockedBalance defines locked balance

func (*LockedBalance) MarshalJSON

func (lb *LockedBalance) MarshalJSON() ([]byte, error)

MarshalJSON is a marshaler function

func (*LockedBalance) ReadFrom

func (lb *LockedBalance) ReadFrom(r io.Reader) (int64, error)

ReadFrom is a deserialization function

func (*LockedBalance) WriteTo

func (lb *LockedBalance) WriteTo(w io.Writer) (int64, error)

WriteTo is a serialization 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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL