types

package
v0.0.0-...-a8cc34e Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2020 License: LGPL-3.0, LGPL-3.0 Imports: 17 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidAccountName            = errors.New("invalid account name")
	ErrInvalidAccountType            = errors.New("invalid account type")
	ErrExistAddress                  = errors.New("exist address")
	ErrExistAccount                  = errors.New("exist account")
	ErrExistAccountName              = errors.New("exist account name")
	ErrNotExistAccount               = errors.New("not exist account")
	ErrDeletedAccount                = errors.New("deleted account")
	ErrInvalidProcess                = errors.New("invalid process")
	ErrExistProcessName              = errors.New("exist process name")
	ErrExistProcessID                = errors.New("exist process id")
	ErrNotExistProcess               = errors.New("not exist process")
	ErrExistUTXO                     = errors.New("exist utxo")
	ErrNotExistUTXO                  = errors.New("not exist utxo")
	ErrUsedUTXO                      = errors.New("used utxo")
	ErrInvalidTransactionCount       = errors.New("invalid transaction count")
	ErrNotAllowedEmptyAddressAccount = errors.New("not allowed empty address account")
	ErrNotAllowedAddressAccountName  = errors.New("not allowed address account name")
	ErrInvalidAddressHeight          = errors.New("invalid address height")
	ErrInvalidSignerCount            = errors.New("invalid signer count")
	ErrInvalidAccountSigner          = errors.New("invalid account signer")
	ErrInvalidUTXOSigner             = errors.New("invalid utxo signer")
	ErrInvalidTxInCount              = errors.New("invalid tx in count")
	ErrInvalidOutputAmount           = errors.New("invalid output amount")
	ErrDustAmount                    = errors.New("dust amount")
	ErrInvalidTransactionIDFormat    = errors.New("invalid transaction id format")
	ErrUsedTimeSlot                  = errors.New("used timeslot")
	ErrInvalidTransactionTimeSlot    = errors.New("invalid transaction timeslot")
)

transaction errors

Functions

func DefineHashedType

func DefineHashedType(Name string) uint16

DefineHashedType is return string hashed type

func EncodeTransaction

func EncodeTransaction(ChainID uint8, t uint16, tx Transaction) ([]byte, error)

EncodeTransaction returns the encoded transaction

func HashTransaction

func HashTransaction(ChainID uint8, tx Transaction) hash.Hash256

HashTransaction returns the hash of the transaction

func HashTransactionByType

func HashTransactionByType(ChainID uint8, t uint16, tx Transaction) hash.Hash256

HashTransactionByType returns the hash of the transaction using the type

func IsAllowedAccountName

func IsAllowedAccountName(Name string) bool

IsAllowedAccountName returns it is allowed account name or not

func MarshalID

func MarshalID(height uint32, index uint16, n uint16) uint64

MarshalID returns the packed id

func NameOfHashedType

func NameOfHashedType(t uint16) string

NameOfHashedType returns the name of the hashed type

func ParseTransactionID

func ParseTransactionID(TXID string) (uint32, uint16, error)

ParseTransactionID returns the id of the transaction

func ToTimeSlot

func ToTimeSlot(timestamp uint64) uint32

ToTimeSlot returns the timeslot of the timestamp

func TransactionID

func TransactionID(Height uint32, Index uint16) string

TransactionID returns the id of the transaction

func UnmarshalID

func UnmarshalID(id uint64) (uint32, uint16, uint16)

UnmarshalID returns the block height, the transaction index in the block, the output index in the transaction

Types

type Account

type Account interface {
	json.Marshaler
	Address() common.Address
	Name() string
	Clone() Account
	Validate(loader LoaderWrapper, signers []common.PublicHash) error
}

Account defines common account functions

type AddressAccountMap

type AddressAccountMap struct {
	// contains filtered or unexported fields
}

AddressAccountMap address and account map

func NewAddressAccountMap

func NewAddressAccountMap() *AddressAccountMap

NewAddressAccountMap returns a AddressAccountMap

func (*AddressAccountMap) Delete

func (sm *AddressAccountMap) Delete(addr common.Address)

Delete removes data of the key

func (*AddressAccountMap) EachAll

func (sm *AddressAccountMap) EachAll(fn func(common.Address, Account) bool)

EachAll iterates all elements

func (*AddressAccountMap) Get

func (sm *AddressAccountMap) Get(addr common.Address) (Account, bool)

Get returns data of the key

func (*AddressAccountMap) Has

func (sm *AddressAccountMap) Has(addr common.Address) bool

Has returns data of the key is exist or not

func (*AddressAccountMap) Len

func (sm *AddressAccountMap) Len() int

Len returns the length of the map

func (*AddressAccountMap) MarshalJSON

func (sm *AddressAccountMap) MarshalJSON() ([]byte, error)

MarshalJSON is a marshaler function

func (*AddressAccountMap) Put

func (sm *AddressAccountMap) Put(addr common.Address, acc Account)

Put adds data of the key

type AddressAddressAmountMap

type AddressAddressAmountMap struct {
	// contains filtered or unexported fields
}

AddressAddressAmountMap address and AddressAmountMap map

func NewAddressAddressAmountMap

func NewAddressAddressAmountMap() *AddressAddressAmountMap

NewAddressAddressAmountMap returns a AddressAddressAmountMap

func (*AddressAddressAmountMap) Delete

func (sm *AddressAddressAmountMap) Delete(addr common.Address)

Delete removes data of the key

func (*AddressAddressAmountMap) EachAll

EachAll iterates all elements

func (*AddressAddressAmountMap) Get

Get returns data of the key

func (*AddressAddressAmountMap) Has

Has returns data of the key is exist or not

func (*AddressAddressAmountMap) Len

func (sm *AddressAddressAmountMap) Len() int

Len returns the length of the map

func (*AddressAddressAmountMap) MarshalJSON

func (sm *AddressAddressAmountMap) MarshalJSON() ([]byte, error)

MarshalJSON is a marshaler function

func (*AddressAddressAmountMap) Put

Put adds data of the key

type AddressAddressMap

type AddressAddressMap struct {
	// contains filtered or unexported fields
}

AddressAddressMap address and Amount map

func NewAddressAddressMap

func NewAddressAddressMap() *AddressAddressMap

NewAddressAddressMap returns a AddressAddressMap

func (*AddressAddressMap) Delete

func (sm *AddressAddressMap) Delete(addr common.Address)

Delete removes data of the key

func (*AddressAddressMap) EachAll

func (sm *AddressAddressMap) EachAll(fn func(common.Address, common.Address) bool)

EachAll iterates all elements

func (*AddressAddressMap) Get

Get returns data of the key

func (*AddressAddressMap) Has

func (sm *AddressAddressMap) Has(addr common.Address) bool

Has returns data of the key is exist or not

func (*AddressAddressMap) Len

func (sm *AddressAddressMap) Len() int

Len returns the length of the map

func (*AddressAddressMap) MarshalJSON

func (sm *AddressAddressMap) MarshalJSON() ([]byte, error)

MarshalJSON is a marshaler function

func (*AddressAddressMap) Put

func (sm *AddressAddressMap) Put(addr common.Address, am common.Address)

Put adds data of the key

type AddressAmountMap

type AddressAmountMap struct {
	// contains filtered or unexported fields
}

AddressAmountMap address and Amount map

func NewAddressAmountMap

func NewAddressAmountMap() *AddressAmountMap

NewAddressAmountMap returns a AddressAmountMap

func (*AddressAmountMap) Delete

func (sm *AddressAmountMap) Delete(addr common.Address)

Delete removes data of the key

func (*AddressAmountMap) EachAll

func (sm *AddressAmountMap) EachAll(fn func(common.Address, *amount.Amount) bool)

EachAll iterates all elements

func (*AddressAmountMap) Get

func (sm *AddressAmountMap) Get(addr common.Address) (*amount.Amount, bool)

Get returns data of the key

func (*AddressAmountMap) Has

func (sm *AddressAmountMap) Has(addr common.Address) bool

Has returns data of the key is exist or not

func (*AddressAmountMap) Len

func (sm *AddressAmountMap) Len() int

Len returns the length of the map

func (*AddressAmountMap) MarshalJSON

func (sm *AddressAmountMap) MarshalJSON() ([]byte, error)

MarshalJSON is a marshaler function

func (*AddressAmountMap) Put

func (sm *AddressAmountMap) Put(addr common.Address, am *amount.Amount)

Put adds data of the key

type AddressBoolMap

type AddressBoolMap struct {
	// contains filtered or unexported fields
}

AddressBoolMap address and bool map

func NewAddressBoolMap

func NewAddressBoolMap() *AddressBoolMap

NewAddressBoolMap returns a AddressBoolMap

func (*AddressBoolMap) Delete

func (sm *AddressBoolMap) Delete(addr common.Address)

Delete removes data of the key

func (*AddressBoolMap) EachAll

func (sm *AddressBoolMap) EachAll(fn func(common.Address, bool) bool)

EachAll iterates all elements

func (*AddressBoolMap) Get

func (sm *AddressBoolMap) Get(addr common.Address) (bool, bool)

Get returns data of the key

func (*AddressBoolMap) Has

func (sm *AddressBoolMap) Has(addr common.Address) bool

Has returns data of the key is exist or not

func (*AddressBoolMap) Len

func (sm *AddressBoolMap) Len() int

Len returns the length of the map

func (*AddressBoolMap) MarshalJSON

func (sm *AddressBoolMap) MarshalJSON() ([]byte, error)

MarshalJSON is a marshaler function

func (*AddressBoolMap) Put

func (sm *AddressBoolMap) Put(addr common.Address, value bool)

Put adds data of the key

type AddressUint32Map

type AddressUint32Map struct {
	// contains filtered or unexported fields
}

AddressUint32Map address and uint32 map

func NewAddressUint32Map

func NewAddressUint32Map() *AddressUint32Map

NewAddressUint32Map returns a AddressUint32Map

func (*AddressUint32Map) Delete

func (sm *AddressUint32Map) Delete(addr common.Address)

Delete removes data of the key

func (*AddressUint32Map) EachAll

func (sm *AddressUint32Map) EachAll(fn func(common.Address, uint32) bool)

EachAll iterates all elements

func (*AddressUint32Map) Get

func (sm *AddressUint32Map) Get(addr common.Address) (uint32, bool)

Get returns data of the key

func (*AddressUint32Map) Has

func (sm *AddressUint32Map) Has(addr common.Address) bool

Has returns data of the key is exist or not

func (*AddressUint32Map) Len

func (sm *AddressUint32Map) Len() int

Len returns the length of the map

func (*AddressUint32Map) MarshalJSON

func (sm *AddressUint32Map) MarshalJSON() ([]byte, error)

MarshalJSON is a marshaler function

func (*AddressUint32Map) Put

func (sm *AddressUint32Map) Put(addr common.Address, value uint32)

Put adds data of the key

type AddressUint64Map

type AddressUint64Map struct {
	// contains filtered or unexported fields
}

AddressUint64Map address and uint64 map

func NewAddressUint64Map

func NewAddressUint64Map() *AddressUint64Map

NewAddressUint64Map returns a AddressUint64Map

func (*AddressUint64Map) Delete

func (sm *AddressUint64Map) Delete(addr common.Address)

Delete removes data of the key

func (*AddressUint64Map) EachAll

func (sm *AddressUint64Map) EachAll(fn func(common.Address, uint64) bool)

EachAll iterates all elements

func (*AddressUint64Map) Get

func (sm *AddressUint64Map) Get(addr common.Address) (uint64, bool)

Get returns data of the key

func (*AddressUint64Map) Has

func (sm *AddressUint64Map) Has(addr common.Address) bool

Has returns data of the key is exist or not

func (*AddressUint64Map) Len

func (sm *AddressUint64Map) Len() int

Len returns the length of the map

func (*AddressUint64Map) MarshalJSON

func (sm *AddressUint64Map) MarshalJSON() ([]byte, error)

MarshalJSON is a marshaler function

func (*AddressUint64Map) Put

func (sm *AddressUint64Map) Put(addr common.Address, value uint64)

Put adds data of the key

type Application

type Application interface {
	Process
	InitGenesis(ctw *ContextWrapper) error
}

Application defines chain application functions

type ApplicationBase

type ApplicationBase struct{}

ApplicationBase is a base handler of the chain process

func (*ApplicationBase) AfterExecuteTransactions

func (app *ApplicationBase) AfterExecuteTransactions(b *Block, ctw *ContextWrapper) error

AfterExecuteTransactions called after processes transactions of the block

func (*ApplicationBase) BeforeExecuteTransactions

func (app *ApplicationBase) BeforeExecuteTransactions(ctw *ContextWrapper) error

BeforeExecuteTransactions called before processes transactions of the block

func (*ApplicationBase) ID

func (app *ApplicationBase) ID() uint8

ID must returns 255

func (*ApplicationBase) InitGenesis

func (app *ApplicationBase) InitGenesis(ctw *ContextWrapper) error

InitGenesis initializes genesis data

func (*ApplicationBase) OnLoadChain

func (app *ApplicationBase) OnLoadChain(loader LoaderWrapper) error

OnLoadChain called when the chain loaded

func (*ApplicationBase) OnSaveData

func (app *ApplicationBase) OnSaveData(b *Block, ctw *ContextWrapper) error

OnSaveData called when the context of the block saved

type Block

type Block struct {
	Header                Header
	TransactionTypes      []uint16             //MAXLEN : 65535
	Transactions          []Transaction        //MAXLEN : 65535
	TransactionSignatures [][]common.Signature //MAXLEN : 65535
	Signatures            []common.Signature   //MAXLEN : 255
}

Block includes a block header and a block body

type BlockSign

type BlockSign struct {
	HeaderHash         hash.Hash256
	GeneratorSignature common.Signature
}

BlockSign is the generator signature of the block

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 internalLoader) *Context

NewContext returns a Context

func NewEmptyContext

func NewEmptyContext() *Context

NewEmptyContext returns a EmptyContext

func (*Context) Account

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

Account returns the account instance of the address

func (*Context) AccountData

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

AccountData returns the account data from the top snapshot

func (*Context) AddressByName

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

AddressByName returns the account address of the name

func (*Context) ChainID

func (ctx *Context) ChainID() uint8

ChainID returns the id of the 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) error

CreateAccount inserts the account to the top snapshot

func (*Context) CreateAccountIgnoreDelete

func (ctx *Context) CreateAccountIgnoreDelete(acc Account) error

CreateAccountIgnoreDelete inserts the account even account has deleted name

func (*Context) CreateUTXO

func (ctx *Context) CreateUTXO(id uint64, vout *TxOut) error

CreateUTXO inserts the UTXO to the top snapshot

func (*Context) DeleteAccount

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

DeleteAccount deletes the account from the top snapshot

func (*Context) DeleteUTXO

func (ctx *Context) DeleteUTXO(utxo *UTXO) 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) error

EmitEvent creates the event to the top snapshot

func (*Context) HasAccount

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

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

func (*Context) HasAccountName

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

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

func (*Context) HasTimeSlot

func (ctx *Context) HasTimeSlot(slot uint32, key string) bool

HasTimeSlot returns timeslot is exist or not

func (*Context) HasUTXO

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

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

func (*Context) Hash

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

Hash returns the hash value of it

func (*Context) LastHash

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

LastHash returns the recorded prev hash when context generation

func (*Context) LastStatus

func (ctx *Context) LastStatus() (uint32, hash.Hash256)

LastStatus returns the recored target height, prev hash and timestamp

func (*Context) LastTimestamp

func (ctx *Context) LastTimestamp() uint64

LastTimestamp returns the last timestamp of the chain

func (*Context) Name

func (ctx *Context) Name() string

Name returns the name of the chain

func (*Context) NextContext

func (ctx *Context) NextContext(NextHash hash.Hash256, Timestamp uint64) *Context

NextContext returns the next Context of the Context

func (*Context) ProcessData

func (ctx *Context) ProcessData(pid uint8, name []byte) []byte

ProcessData returns the process data from the top snapshot

func (*Context) Revert

func (ctx *Context) Revert(sn int)

Revert removes snapshots after the snapshot number

func (*Context) SetAccountData

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

SetAccountData inserts the account data to the top snapshot

func (*Context) SetProcessData

func (ctx *Context) SetProcessData(pid uint8, name []byte, value []byte)

SetProcessData inserts the process 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) UTXO

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

UTXO returns the UTXO from the top snapshot

func (*Context) UseTimeSlot

func (ctx *Context) UseTimeSlot(slot uint32, key string) error

UseTimeSlot consumes timeslot

func (*Context) Version

func (ctx *Context) Version() uint16

Version returns the version of the chain

type ContextData

type ContextData struct {
	Parent                *ContextData
	AccountMap            *AddressAccountMap
	DeletedAccountMap     *AddressAccountMap
	AccountNameMap        *StringAddressMap
	AccountDataMap        *StringBytesMap
	DeletedAccountDataMap *StringBoolMap
	ProcessDataMap        *StringBytesMap
	DeletedProcessDataMap *StringBoolMap
	UTXOMap               *Uint64UTXOMap
	CreatedUTXOMap        *Uint64TxOutMap
	DeletedUTXOMap        *Uint64UTXOMap
	Events                []Event
	EventN                uint16
	TimeSlotMap           *Uint32StringBoolMap
	// contains filtered or unexported fields
}

ContextData is a state data of the context

func NewContextData

func NewContextData(loader internalLoader, Parent *ContextData) *ContextData

NewContextData returns a ContextData

func (*ContextData) Account

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

Account returns the account instance of the address

func (*ContextData) AccountData

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

AccountData returns the account data

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

CreateAccount inserts the account

func (*ContextData) CreateAccountIgnoreDelete

func (ctd *ContextData) CreateAccountIgnoreDelete(acc Account) error

CreateAccountIgnoreDelete inserts the account even account has deleted name

func (*ContextData) CreateUTXO

func (ctd *ContextData) CreateUTXO(id uint64, vout *TxOut) error

CreateUTXO inserts the UTXO

func (*ContextData) DeleteAccount

func (ctd *ContextData) DeleteAccount(acc Account) error

DeleteAccount deletes the account

func (*ContextData) DeleteUTXO

func (ctd *ContextData) DeleteUTXO(utxo *UTXO) 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) error

EmitEvent creates the event to the top snapshot

func (*ContextData) HasAccount

func (ctd *ContextData) HasAccount(addr common.Address) (bool, error)

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

func (*ContextData) HasAccountName

func (ctd *ContextData) HasAccountName(Name string) (bool, error)

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

func (*ContextData) HasTimeSlot

func (ctd *ContextData) HasTimeSlot(slot uint32, key string) bool

HasTimeSlot returns timeslot is exist or not

func (*ContextData) HasUTXO

func (ctd *ContextData) HasUTXO(id uint64) (bool, error)

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

func (*ContextData) Hash

func (ctd *ContextData) Hash() hash.Hash256

Hash returns the hash value of it

func (*ContextData) ProcessData

func (ctd *ContextData) ProcessData(pid uint8, name []byte) []byte

ProcessData returns the process data

func (*ContextData) SetAccountData

func (ctd *ContextData) SetAccountData(addr common.Address, pid uint8, name []byte, value []byte)

SetAccountData inserts the account data

func (*ContextData) SetProcessData

func (ctd *ContextData) SetProcessData(pid uint8, name []byte, value []byte)

SetProcessData inserts the process data

func (*ContextData) UTXO

func (ctd *ContextData) UTXO(id uint64) (*UTXO, error)

UTXO returns the UTXO

func (*ContextData) UseTimeSlot

func (ctd *ContextData) UseTimeSlot(slot uint32, key string) error

UseTimeSlot consumes timeslot

type ContextWrapper

type ContextWrapper struct {
	// contains filtered or unexported fields
}

ContextWrapper is an context for the process

func NewContextWrapper

func NewContextWrapper(pid uint8, ctx *Context) *ContextWrapper

NewContextWrapper returns a ContextWrapper

func SwitchContextWrapper

func SwitchContextWrapper(pid uint8, ctw *ContextWrapper) *ContextWrapper

SwitchContextWrapper returns a SwitchContextWrapper of the pid

func (*ContextWrapper) Account

func (ctw *ContextWrapper) Account(addr common.Address) (Account, error)

Account returns the account instance of the address

func (*ContextWrapper) AccountData

func (ctw *ContextWrapper) AccountData(addr common.Address, name []byte) []byte

AccountData returns the account data from the top snapshot

func (*ContextWrapper) AddressByName

func (ctw *ContextWrapper) AddressByName(Name string) (common.Address, error)

AddressByName returns the account address of the name

func (*ContextWrapper) ChainID

func (ctw *ContextWrapper) ChainID() uint8

ChainID returns the id of the chain

func (*ContextWrapper) Commit

func (ctw *ContextWrapper) Commit(sn int)

Commit apply snapshots to the top after the snapshot number

func (*ContextWrapper) CreateAccount

func (ctw *ContextWrapper) CreateAccount(acc Account) error

CreateAccount inserts the account to the top snapshot

func (*ContextWrapper) CreateAccountIgnoreDelete

func (ctw *ContextWrapper) CreateAccountIgnoreDelete(acc Account) error

CreateAccountIgnoreDelete inserts the account even account has deleted name

func (*ContextWrapper) CreateUTXO

func (ctw *ContextWrapper) CreateUTXO(id uint64, vout *TxOut) error

CreateUTXO inserts the UTXO to the top snapshot

func (*ContextWrapper) DeleteAccount

func (ctw *ContextWrapper) DeleteAccount(acc Account) error

DeleteAccount deletes the account from the top snapshot

func (*ContextWrapper) DeleteUTXO

func (ctw *ContextWrapper) DeleteUTXO(utxo *UTXO) error

DeleteUTXO deletes the UTXO from the top snapshot

func (*ContextWrapper) Dump

func (ctw *ContextWrapper) Dump() string

Dump prints the top ContextWrapper data of the context

func (*ContextWrapper) EmitEvent

func (ctw *ContextWrapper) EmitEvent(e Event) error

EmitEvent creates the event to the top snapshot

func (*ContextWrapper) HasAccount

func (ctw *ContextWrapper) HasAccount(addr common.Address) (bool, error)

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

func (*ContextWrapper) HasAccountName

func (ctw *ContextWrapper) HasAccountName(Name string) (bool, error)

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

func (*ContextWrapper) HasTimeSlot

func (ctw *ContextWrapper) HasTimeSlot(slot uint32, key string) bool

HasTimeSlot returns timeslot is exist or not

func (*ContextWrapper) HasUTXO

func (ctw *ContextWrapper) HasUTXO(id uint64) (bool, error)

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

func (*ContextWrapper) Hash

func (ctw *ContextWrapper) Hash() hash.Hash256

Hash returns the hash value of it

func (*ContextWrapper) LastHash

func (ctw *ContextWrapper) LastHash() hash.Hash256

LastHash returns the recorded prev hash when ContextWrapper generation

func (*ContextWrapper) LastStatus

func (ctw *ContextWrapper) LastStatus() (uint32, hash.Hash256)

LastStatus returns the recored target height, prev hash

func (*ContextWrapper) LastTimestamp

func (ctw *ContextWrapper) LastTimestamp() uint64

LastTimestamp returns the last timestamp of the chain

func (*ContextWrapper) Name

func (ctw *ContextWrapper) Name() string

Name returns the name of the chain

func (*ContextWrapper) ProcessData

func (ctw *ContextWrapper) ProcessData(name []byte) []byte

ProcessData returns the process data from the top snapshot

func (*ContextWrapper) Revert

func (ctw *ContextWrapper) Revert(sn int)

Revert removes snapshots after the snapshot number

func (*ContextWrapper) SetAccountData

func (ctw *ContextWrapper) SetAccountData(addr common.Address, name []byte, value []byte)

SetAccountData inserts the account data to the top snapshot

func (*ContextWrapper) SetProcessData

func (ctw *ContextWrapper) SetProcessData(name []byte, value []byte)

SetProcessData inserts the process data to the top snapshot

func (*ContextWrapper) Snapshot

func (ctw *ContextWrapper) Snapshot() int

Snapshot push a snapshot and returns the snapshot number of it

func (*ContextWrapper) StackSize

func (ctw *ContextWrapper) StackSize() int

StackSize returns the size of the context data stack

func (*ContextWrapper) Switch

func (ctw *ContextWrapper) Switch(pid uint8) *ContextWrapper

Switch returns a SwitchContextWrapper of the pid

func (*ContextWrapper) TargetHeight

func (ctw *ContextWrapper) TargetHeight() uint32

TargetHeight returns the recorded target height when ContextWrapper generation

func (*ContextWrapper) Top

func (ctw *ContextWrapper) Top() *ContextData

Top returns the top snapshot

func (*ContextWrapper) UTXO

func (ctw *ContextWrapper) UTXO(id uint64) (*UTXO, error)

UTXO returns the UTXO from the top snapshot

func (*ContextWrapper) Version

func (ctw *ContextWrapper) Version() uint16

Version returns the version of the chain

type Event

type Event interface {
	json.Marshaler
	Height() uint32
	Index() uint16
	N() uint16
	SetN(n uint16)
}

Event defines common event functions

type Header struct {
	ChainID       uint8
	Version       uint16
	Height        uint32
	PrevHash      hash.Hash256
	LevelRootHash hash.Hash256
	ContextHash   hash.Hash256
	Timestamp     uint64
	Generator     common.Address
	ConsensusData []byte
}

Header is validation informations

type Loader

type Loader interface {
	ChainID() uint8
	Name() string
	Version() uint16
	TargetHeight() uint32
	Account(addr common.Address) (Account, error)
	AddressByName(Name string) (common.Address, error)
	HasAccount(addr common.Address) (bool, error)
	HasAccountName(Name string) (bool, error)
	HasUTXO(id uint64) (bool, error)
	UTXO(id uint64) (*UTXO, error)
	HasTimeSlot(slot uint32, key string) bool
}

Loader defines functions that loads state data from the target chain

type LoaderWrapper

type LoaderWrapper interface {
	Loader
	AccountData(addr common.Address, name []byte) []byte
	ProcessData(name []byte) []byte
}

LoaderWrapper is an interface to load state data from the target chain

func NewLoaderWrapper

func NewLoaderWrapper(pid uint8, loader Loader) LoaderWrapper

NewLoaderWrapper returns a LoaderWrapper

type Process

type Process interface {
	ID() uint8
	Version() string
	Name() string
	Init(reg *Register, pm ProcessManager, cn Provider) error
	OnLoadChain(loader LoaderWrapper) error
	BeforeExecuteTransactions(ctw *ContextWrapper) error
	AfterExecuteTransactions(b *Block, ctw *ContextWrapper) error
	OnSaveData(b *Block, ctw *ContextWrapper) error
}

Process defines process functions

type ProcessBase

type ProcessBase struct{}

ProcessBase is a base handler of the chain process

func (*ProcessBase) AfterExecuteTransactions

func (p *ProcessBase) AfterExecuteTransactions(b *Block, ctw *ContextWrapper) error

AfterExecuteTransactions called after processes transactions of the block

func (*ProcessBase) BeforeExecuteTransactions

func (p *ProcessBase) BeforeExecuteTransactions(ctw *ContextWrapper) error

BeforeExecuteTransactions called before processes transactions of the block

func (*ProcessBase) InitGenesis

func (p *ProcessBase) InitGenesis(ctw *ContextWrapper) error

InitGenesis initializes genesis data

func (*ProcessBase) OnLoadChain

func (p *ProcessBase) OnLoadChain(loader LoaderWrapper) error

OnLoadChain called when the chain loaded

func (*ProcessBase) OnSaveData

func (p *ProcessBase) OnSaveData(b *Block, ctw *ContextWrapper) error

OnSaveData called when the context of the block saved

type ProcessManager

type ProcessManager interface {
	Processes() []Process
	Process(id uint8) (Process, error)
	ProcessByName(name string) (Process, error)
	Services() []Service
	ServiceByName(name string) (Service, error)
}

ProcessManager managers processes in the chain

type Provider

type Provider interface {
	ChainID() uint8
	Symbol() string
	Usage() string
	Version() uint16
	Height() uint32
	LastStatus() (uint32, hash.Hash256)
	LastHash() hash.Hash256
	LastTimestamp() uint64
	Hash(height uint32) (hash.Hash256, error)
	Header(height uint32) (*Header, error)
	Block(height uint32) (*Block, error)
	Events(From uint32, To uint32) ([]Event, error)
	NewLoaderWrapper(pid uint8) LoaderWrapper
	NewAddress(height uint32, index uint16) common.Address
}

Provider defines functions that loads chain data from the chain

type PublicHashBoolMap

type PublicHashBoolMap struct {
	// contains filtered or unexported fields
}

PublicHashBoolMap PublicHash and bool map

func NewPublicHashBoolMap

func NewPublicHashBoolMap() *PublicHashBoolMap

NewPublicHashBoolMap returns a PublicHashBoolMap

func (*PublicHashBoolMap) Delete

func (sm *PublicHashBoolMap) Delete(pubhash common.PublicHash)

Delete removes data of the key

func (*PublicHashBoolMap) EachAll

func (sm *PublicHashBoolMap) EachAll(fn func(common.PublicHash, bool) bool)

EachAll iterates all elements

func (*PublicHashBoolMap) Get

func (sm *PublicHashBoolMap) Get(pubhash common.PublicHash) (bool, bool)

Get returns data of the key

func (*PublicHashBoolMap) Has

func (sm *PublicHashBoolMap) Has(pubhash common.PublicHash) bool

Has returns data of the key is exist or not

func (*PublicHashBoolMap) Len

func (sm *PublicHashBoolMap) Len() int

Len returns the length of the map

func (*PublicHashBoolMap) MarshalJSON

func (sm *PublicHashBoolMap) MarshalJSON() ([]byte, error)

MarshalJSON is a marshaler function

func (*PublicHashBoolMap) Put

func (sm *PublicHashBoolMap) Put(pubhash common.PublicHash, value bool)

Put adds data of the key

type Register

type Register struct {
	// contains filtered or unexported fields
}

Register adds types of the process to the encoding factory

func NewRegister

func NewRegister(pid uint8) *Register

NewRegister returns a Register

func (*Register) RegisterAccount

func (reg *Register) RegisterAccount(t uint8, acc Account) uint16

RegisterAccount adds the type of the account of the process to the encoding factory

func (*Register) RegisterEvent

func (reg *Register) RegisterEvent(t uint8, acc Event) uint16

RegisterEvent adds the type of the event of the process to the encoding factory

func (*Register) RegisterTransaction

func (reg *Register) RegisterTransaction(t uint8, tx Transaction) uint16

RegisterTransaction adds the type of the transaction of the process to the encoding factory

type Service

type Service interface {
	Name() string
	Init(pm ProcessManager, cn Provider) error
	OnLoadChain(loader Loader) error
	OnBlockConnected(b *Block, events []Event, loader Loader)
	OnTransactionInPoolExpired(txs []Transaction)
}

Service defines service functions

type ServiceBase

type ServiceBase struct{}

ServiceBase is a base handler of the chain service

func (*ServiceBase) OnBlockConnected

func (s *ServiceBase) OnBlockConnected(b *Block, events []Event, loader Loader)

OnBlockConnected called when a block is connected to the chain

func (*ServiceBase) OnLoadChain

func (s *ServiceBase) OnLoadChain(loader Loader) error

OnLoadChain called when the chain loaded

func (*ServiceBase) OnTransactionInPoolExpired

func (s *ServiceBase) OnTransactionInPoolExpired(txs []Transaction)

OnTransactionInPoolExpired called when a transaction in pool is expired

type StringAddressMap

type StringAddressMap struct {
	// contains filtered or unexported fields
}

StringAddressMap address and common.Address map

func NewStringAddressMap

func NewStringAddressMap() *StringAddressMap

NewStringAddressMap returns a StringAddressMap

func (*StringAddressMap) Delete

func (sm *StringAddressMap) Delete(key string)

Delete removes data of the key

func (*StringAddressMap) EachAll

func (sm *StringAddressMap) EachAll(fn func(string, common.Address) bool)

EachAll iterates all elements

func (*StringAddressMap) EachPrefix

func (sm *StringAddressMap) EachPrefix(prefix string, fn func(string, common.Address) bool)

EachPrefix iterates elements that has the given prefix

func (*StringAddressMap) Get

func (sm *StringAddressMap) Get(key string) (common.Address, bool)

Get returns data of the key

func (*StringAddressMap) Has

func (sm *StringAddressMap) Has(key string) bool

Has returns data of the key is exist or not

func (*StringAddressMap) Len

func (sm *StringAddressMap) Len() int

Len returns the length of the map

func (*StringAddressMap) MarshalJSON

func (sm *StringAddressMap) MarshalJSON() ([]byte, error)

MarshalJSON is a marshaler function

func (*StringAddressMap) Put

func (sm *StringAddressMap) Put(key string, addr common.Address)

Put adds data of the key

type StringBoolMap

type StringBoolMap struct {
	// contains filtered or unexported fields
}

StringBoolMap string and bool map

func NewStringBoolMap

func NewStringBoolMap() *StringBoolMap

NewStringBoolMap returns a StringBoolMap

func (*StringBoolMap) Delete

func (sm *StringBoolMap) Delete(key string)

Delete removes data of the key

func (*StringBoolMap) EachAll

func (sm *StringBoolMap) EachAll(fn func(string, bool) bool)

EachAll iterates all elements

func (*StringBoolMap) EachPrefix

func (sm *StringBoolMap) EachPrefix(prefix string, fn func(string, bool) bool)

EachPrefix iterates elements that has the given prefix

func (*StringBoolMap) Get

func (sm *StringBoolMap) Get(key string) (bool, bool)

Get returns data of the key

func (*StringBoolMap) Has

func (sm *StringBoolMap) Has(key string) bool

Has returns data of the key is exist or not

func (*StringBoolMap) Len

func (sm *StringBoolMap) Len() int

Len returns the length of the map

func (*StringBoolMap) MarshalJSON

func (sm *StringBoolMap) MarshalJSON() ([]byte, error)

MarshalJSON is a marshaler function

func (*StringBoolMap) Put

func (sm *StringBoolMap) Put(key string, value bool)

Put adds data of the key

type StringBytesMap

type StringBytesMap struct {
	// contains filtered or unexported fields
}

StringBytesMap string and []byte map

func NewStringBytesMap

func NewStringBytesMap() *StringBytesMap

NewStringBytesMap returns a StringBytesMap

func (*StringBytesMap) Delete

func (sm *StringBytesMap) Delete(key string)

Delete removes data of the key

func (*StringBytesMap) EachAll

func (sm *StringBytesMap) EachAll(fn func(string, []byte) bool)

EachAll iterates all elements

func (*StringBytesMap) EachPrefix

func (sm *StringBytesMap) EachPrefix(prefix string, fn func(string, []byte) bool)

EachPrefix iterates elements that has the given prefix

func (*StringBytesMap) Get

func (sm *StringBytesMap) Get(key string) ([]byte, bool)

Get returns data of the key

func (*StringBytesMap) Has

func (sm *StringBytesMap) Has(key string) bool

Has returns data of the key is exist or not

func (*StringBytesMap) Len

func (sm *StringBytesMap) Len() int

Len returns the length of the map

func (*StringBytesMap) Put

func (sm *StringBytesMap) Put(key string, value []byte)

Put adds data of the key

type StringStringMap

type StringStringMap struct {
	// contains filtered or unexported fields
}

StringStringMap string and string map

func NewStringStringMap

func NewStringStringMap() *StringStringMap

NewStringStringMap returns a StringStringMap

func (*StringStringMap) Delete

func (sm *StringStringMap) Delete(key string)

Delete removes data of the key

func (*StringStringMap) EachAll

func (sm *StringStringMap) EachAll(fn func(string, string) bool)

EachAll iterates all elements

func (*StringStringMap) EachPrefix

func (sm *StringStringMap) EachPrefix(prefix string, fn func(string, string) bool)

EachPrefix iterates elements that has the given prefix

func (*StringStringMap) Get

func (sm *StringStringMap) Get(key string) (string, bool)

Get returns data of the key

func (*StringStringMap) Has

func (sm *StringStringMap) Has(key string) bool

Has returns data of the key is exist or not

func (*StringStringMap) Len

func (sm *StringStringMap) Len() int

Len returns the length of the map

func (*StringStringMap) MarshalJSON

func (sm *StringStringMap) MarshalJSON() ([]byte, error)

MarshalJSON is a marshaler function

func (*StringStringMap) Put

func (sm *StringStringMap) Put(key string, value string)

Put adds data of the key

type Transaction

type Transaction interface {
	json.Marshaler
	Timestamp() uint64
	Validate(p Process, loader LoaderWrapper, signers []common.PublicHash) error
	Execute(p Process, ctx *ContextWrapper, index uint16) error
}

Transaction defines common transaction functions

func DecodeTransaction

func DecodeTransaction(fc *factory.Factory, bs []byte) (uint8, Transaction, uint16, error)

DecodeTransaction returns the encoded transaction

type TransactionSign

type TransactionSign struct {
	TransactionHash hash.Hash256
	Signatures      []common.Signature
}

TransactionSign is the signature of the transaction creator

type TxIn

type TxIn struct {
	Height uint32
	Index  uint16
	N      uint16
}

TxIn represents the position of the UTXO

func NewTxIn

func NewTxIn(id uint64) *TxIn

NewTxIn returns a TxIn

func (*TxIn) Clone

func (in *TxIn) Clone() *TxIn

Clone returns the clonend value of it

func (*TxIn) ID

func (in *TxIn) ID() uint64

ID returns the packed id of the txin

type TxOut

type TxOut struct {
	Amount     *amount.Amount
	PublicHash common.PublicHash
}

TxOut represents recipient of the UTXO

func NewTxOut

func NewTxOut() *TxOut

NewTxOut returns a TxOut

func (*TxOut) Clone

func (out *TxOut) Clone() *TxOut

Clone returns the clonend value of it

func (*TxOut) MarshalJSON

func (out *TxOut) MarshalJSON() ([]byte, error)

MarshalJSON is a marshaler function

type UTXO

type UTXO struct {
	*TxIn
	*TxOut
}

UTXO represents usable coins in the UTXO model

func (*UTXO) Clone

func (utxo *UTXO) Clone() *UTXO

Clone returns the clonend value of it

type Uint32StringBoolMap

type Uint32StringBoolMap struct {
	// contains filtered or unexported fields
}

Uint32StringBoolMap StringBoolMapess and *StringBoolMap map

func NewUint32StringBoolMap

func NewUint32StringBoolMap() *Uint32StringBoolMap

NewUint32StringBoolMap returns a Uint32StringBoolMap

func (*Uint32StringBoolMap) Delete

func (sm *Uint32StringBoolMap) Delete(key uint32)

Delete removes data of the key

func (*Uint32StringBoolMap) EachAll

func (sm *Uint32StringBoolMap) EachAll(fn func(uint32, *StringBoolMap) bool)

EachAll iterates all elements

func (*Uint32StringBoolMap) Get

func (sm *Uint32StringBoolMap) Get(key uint32) (*StringBoolMap, bool)

Get returns data of the key

func (*Uint32StringBoolMap) Has

func (sm *Uint32StringBoolMap) Has(key uint32) bool

Has returns data of the key is exist or not

func (*Uint32StringBoolMap) Len

func (sm *Uint32StringBoolMap) Len() int

Len returns the length of the map

func (*Uint32StringBoolMap) Put

func (sm *Uint32StringBoolMap) Put(key uint32, StringBoolMap *StringBoolMap)

Put adds data of the key

type Uint64BoolMap

type Uint64BoolMap struct {
	// contains filtered or unexported fields
}

Uint64BoolMap uint64 and bool map

func NewUint64BoolMap

func NewUint64BoolMap() *Uint64BoolMap

NewUint64BoolMap returns a Uint64BoolMap

func (*Uint64BoolMap) Delete

func (sm *Uint64BoolMap) Delete(key uint64)

Delete removes data of the key

func (*Uint64BoolMap) EachAll

func (sm *Uint64BoolMap) EachAll(fn func(uint64, bool) bool)

EachAll iterates all elements

func (*Uint64BoolMap) Get

func (sm *Uint64BoolMap) Get(key uint64) (bool, bool)

Get returns data of the key

func (*Uint64BoolMap) Has

func (sm *Uint64BoolMap) Has(key uint64) bool

Has returns data of the key is exist or not

func (*Uint64BoolMap) Len

func (sm *Uint64BoolMap) Len() int

Len returns the length of the map

func (*Uint64BoolMap) MarshalJSON

func (sm *Uint64BoolMap) MarshalJSON() ([]byte, error)

MarshalJSON is a marshaler function

func (*Uint64BoolMap) Put

func (sm *Uint64BoolMap) Put(key uint64, value bool)

Put adds data of the key

type Uint64TxOutMap

type Uint64TxOutMap struct {
	// contains filtered or unexported fields
}

Uint64TxOutMap voutess and *TxOut map

func NewUint64TxOutMap

func NewUint64TxOutMap() *Uint64TxOutMap

NewUint64TxOutMap returns a Uint64TxOutMap

func (*Uint64TxOutMap) Delete

func (sm *Uint64TxOutMap) Delete(key uint64)

Delete removes data of the key

func (*Uint64TxOutMap) EachAll

func (sm *Uint64TxOutMap) EachAll(fn func(uint64, *TxOut) bool)

EachAll iterates all elements

func (*Uint64TxOutMap) Get

func (sm *Uint64TxOutMap) Get(key uint64) (*TxOut, bool)

Get returns data of the key

func (*Uint64TxOutMap) Has

func (sm *Uint64TxOutMap) Has(key uint64) bool

Has returns data of the key is exist or not

func (*Uint64TxOutMap) Len

func (sm *Uint64TxOutMap) Len() int

Len returns the length of the map

func (*Uint64TxOutMap) MarshalJSON

func (sm *Uint64TxOutMap) MarshalJSON() ([]byte, error)

MarshalJSON is a marshaler function

func (*Uint64TxOutMap) Put

func (sm *Uint64TxOutMap) Put(key uint64, vout *TxOut)

Put adds data of the key

type Uint64UTXOMap

type Uint64UTXOMap struct {
	// contains filtered or unexported fields
}

Uint64UTXOMap utxoess and *UTXO map

func NewUint64UTXOMap

func NewUint64UTXOMap() *Uint64UTXOMap

NewUint64UTXOMap returns a Uint64UTXOMap

func (*Uint64UTXOMap) Delete

func (sm *Uint64UTXOMap) Delete(key uint64)

Delete removes data of the key

func (*Uint64UTXOMap) EachAll

func (sm *Uint64UTXOMap) EachAll(fn func(uint64, *UTXO) bool)

EachAll iterates all elements

func (*Uint64UTXOMap) Get

func (sm *Uint64UTXOMap) Get(key uint64) (*UTXO, bool)

Get returns data of the key

func (*Uint64UTXOMap) Has

func (sm *Uint64UTXOMap) Has(key uint64) bool

Has returns data of the key is exist or not

func (*Uint64UTXOMap) Len

func (sm *Uint64UTXOMap) Len() int

Len returns the length of the map

func (*Uint64UTXOMap) MarshalJSON

func (sm *Uint64UTXOMap) MarshalJSON() ([]byte, error)

MarshalJSON is a marshaler function

func (*Uint64UTXOMap) Put

func (sm *Uint64UTXOMap) Put(key uint64, utxo *UTXO)

Put adds data of the key

type Uint8StringBytesMap

type Uint8StringBytesMap struct {
	// contains filtered or unexported fields
}

Uint8StringBytesMap StringBytesMapess and *StringBytesMap map

func NewUint8StringBytesMap

func NewUint8StringBytesMap() *Uint8StringBytesMap

NewUint8StringBytesMap returns a Uint8StringBytesMap

func (*Uint8StringBytesMap) Delete

func (sm *Uint8StringBytesMap) Delete(key uint8)

Delete removes data of the key

func (*Uint8StringBytesMap) EachAll

func (sm *Uint8StringBytesMap) EachAll(fn func(uint8, *StringBytesMap) bool)

EachAll iterates all elements

func (*Uint8StringBytesMap) Get

func (sm *Uint8StringBytesMap) Get(key uint8) (*StringBytesMap, bool)

Get returns data of the key

func (*Uint8StringBytesMap) Has

func (sm *Uint8StringBytesMap) Has(key uint8) bool

Has returns data of the key is exist or not

func (*Uint8StringBytesMap) Len

func (sm *Uint8StringBytesMap) Len() int

Len returns the length of the map

func (*Uint8StringBytesMap) Put

func (sm *Uint8StringBytesMap) Put(key uint8, StringBytesMap *StringBytesMap)

Put adds data of the key

Jump to

Keyboard shortcuts

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