Documentation ¶
Index ¶
- Variables
- func BuildLevelRoot(hashes []hash.Hash256) (hash.Hash256, error)
- func HashTransaction(ChainID uint8, tx types.Transaction) hash.Hash256
- func HashTransactionByType(ChainID uint8, t uint16, tx types.Transaction) hash.Hash256
- type AccountTransaction
- type BlockCreator
- func (bc *BlockCreator) AddTx(Generator common.Address, tx types.Transaction, sigs []common.Signature) error
- func (bc *BlockCreator) Finalize(Timestamp uint64) (*types.Block, error)
- func (bc *BlockCreator) Init() error
- func (bc *BlockCreator) UnsafeAddTx(Generator common.Address, t uint16, TxHash hash.Hash256, tx types.Transaction, ...) error
- type Chain
- func (cn *Chain) Close()
- func (cn *Chain) ConnectBlock(b *types.Block, SigMap map[hash.Hash256][]common.PublicHash) error
- func (cn *Chain) Init() error
- func (cn *Chain) MustAddProcess(p types.Process)
- func (cn *Chain) MustAddService(s types.Service)
- func (cn *Chain) NewContext() *types.Context
- func (cn *Chain) Process(id uint8) (types.Process, error)
- func (cn *Chain) ProcessByName(name string) (types.Process, error)
- func (cn *Chain) Processes() []types.Process
- func (cn *Chain) Provider() types.Provider
- func (cn *Chain) ServiceByName(name string) (types.Service, error)
- func (cn *Chain) Services() []types.Service
- type Committer
- type Consensus
- type ConsensusBase
- func (cs *ConsensusBase) InitGenesis(ctw *types.ContextWrapper) error
- func (cs *ConsensusBase) OnLoadChain(loader types.LoaderWrapper) error
- func (cs *ConsensusBase) OnSaveData(b *types.Block, ctw *types.ContextWrapper) error
- func (cs *ConsensusBase) ValidateSignature(bh *types.Header, sigs []common.Signature) error
- type Store
- func (st *Store) Account(addr common.Address) (types.Account, error)
- func (st *Store) AccountData(addr common.Address, pid uint8, name []byte) []byte
- func (st *Store) Accounts() ([]types.Account, error)
- func (st *Store) AddressByName(Name string) (common.Address, error)
- func (st *Store) Block(height uint32) (*types.Block, error)
- func (st *Store) ChainID() uint8
- func (st *Store) Close()
- func (st *Store) Events(From uint32, To uint32) ([]types.Event, error)
- func (st *Store) HasAccount(addr common.Address) (bool, error)
- func (st *Store) HasAccountName(Name string) (bool, error)
- func (st *Store) HasUTXO(id uint64) (bool, error)
- func (st *Store) Hash(height uint32) (hash.Hash256, error)
- func (st *Store) Header(height uint32) (*types.Header, error)
- func (st *Store) Height() uint32
- func (st *Store) IterBlockAfterContext(fn func(b *types.Block) error) error
- func (st *Store) LastHash() hash.Hash256
- func (st *Store) LastStatus() (uint32, hash.Hash256)
- func (st *Store) LastTimestamp() uint64
- func (st *Store) Name() string
- func (st *Store) NewAddress(height uint32, index uint16) common.Address
- func (st *Store) NewLoaderWrapper(pid uint8) types.LoaderWrapper
- func (st *Store) ProcessData(pid uint8, name []byte) []byte
- func (st *Store) Seq(addr common.Address) uint64
- func (st *Store) StoreBlock(b *types.Block, ctd *types.ContextData) error
- func (st *Store) StoreGenesis(genHash hash.Hash256, ctd *types.ContextData) error
- func (st *Store) Symbol() string
- func (st *Store) TargetHeight() uint32
- func (st *Store) UTXO(id uint64) (*types.UTXO, error)
- func (st *Store) UTXOs() ([]*types.UTXO, error)
- func (st *Store) Usage() string
- func (st *Store) Version() uint16
Constants ¶
This section is empty.
Variables ¶
var ( ErrExistServiceName = errors.New("exist service name") ErrExistServiceID = errors.New("exist service id") ErrNotExistService = errors.New("not exist service") ErrInvalidChainID = errors.New("invalid chain id") ErrInvalidVersion = errors.New("invalid version") ErrInvalidHeight = errors.New("invalid height") ErrInvalidPrevHash = errors.New("invalid prev hash") ErrInvalidContextHash = errors.New("invalid context hash") ErrInvalidLevelRootHash = errors.New("invalid level root hash") ErrInvalidTimestamp = errors.New("invalid timestamp") ErrInvalidGenerator = errors.New("invalid generator") ErrExceedHashCount = errors.New("exceed hash count") ErrInvalidHashCount = errors.New("invalid hash count") ErrInvalidGenesisHash = errors.New("invalid genesis hash") ErrInvalidTxInKey = errors.New("invalid txin key") ErrInvalidResult = errors.New("invalid result") ErrChainClosed = errors.New("chain closed") ErrStoreClosed = errors.New("store closed") ErrAlreadyGenesised = errors.New("already genesised") ErrDirtyContext = errors.New("dirty context") ErrReservedID = errors.New("reserved id") ErrAddBeforeChainInit = errors.New("add before chain init") ErrApplicationIDMustBe255 = errors.New("application id must be 255") ErrFoundForkedBlock = errors.New("found forked block") ErrCannotDeleteGeneratorAccount = errors.New("cannot delete generator account") ErrInvalidAccountName = errors.New("invalid account name") )
errors
Functions ¶
func BuildLevelRoot ¶
BuildLevelRoot returns the level root hash
func HashTransaction ¶
func HashTransaction(ChainID uint8, tx types.Transaction) hash.Hash256
HashTransaction returns the hash of the transaction
func HashTransactionByType ¶
HashTransactionByType returns the hash of the transaction using the type
Types ¶
type AccountTransaction ¶
AccountTransaction defines common functions of account model based transactions
type BlockCreator ¶
type BlockCreator struct {
// contains filtered or unexported fields
}
BlockCreator helps to create block
func NewBlockCreator ¶
func NewBlockCreator(cn *Chain, ctx *types.Context, Generator common.Address, ConsensusData []byte) *BlockCreator
NewBlockCreator returns a BlockCreator
func (*BlockCreator) AddTx ¶
func (bc *BlockCreator) AddTx(Generator common.Address, tx types.Transaction, sigs []common.Signature) error
AddTx validates, executes and adds transactions
func (*BlockCreator) Finalize ¶
func (bc *BlockCreator) Finalize(Timestamp uint64) (*types.Block, error)
Finalize generates block that has transactions adds by AddTx
func (*BlockCreator) UnsafeAddTx ¶
func (bc *BlockCreator) UnsafeAddTx(Generator common.Address, t uint16, TxHash hash.Hash256, tx types.Transaction, sigs []common.Signature, signers []common.PublicHash) error
UnsafeAddTx adds transactions without signer validation if signers is not empty
type Chain ¶
Chain manages the chain data using processes
func NewChain ¶
func NewChain(consensus Consensus, app types.Application, store *Store) *Chain
NewChain returns a Chain
func (*Chain) ConnectBlock ¶
ConnectBlock try to connect block to the chain
func (*Chain) MustAddProcess ¶
MustAddProcess adds Process but panic when has the same name process
func (*Chain) MustAddService ¶
MustAddService adds Service but panic when has the same name service
func (*Chain) NewContext ¶
NewContext returns the context of the chain
func (*Chain) ProcessByName ¶
ProcessByName returns the process by the name
func (*Chain) ServiceByName ¶
ServiceByName returns the service by the name
type Committer ¶
type Committer interface { ValidateHeader(bh *types.Header) error ExecuteBlockOnContext(b *types.Block, ctx *types.Context, SigMap map[hash.Hash256][]common.PublicHash) error ConnectBlockWithContext(b *types.Block, ctx *types.Context) error NewContext() *types.Context }
Committer enables to commit block with pre-executed context
type Consensus ¶
type Consensus interface { Init(cn *Chain, ct Committer) error InitGenesis(ctw *types.ContextWrapper) error OnLoadChain(loader types.LoaderWrapper) error ValidateSignature(bh *types.Header, sigs []common.Signature) error OnSaveData(b *types.Block, ctw *types.ContextWrapper) error }
Consensus defines chain consensus functions
type ConsensusBase ¶
type ConsensusBase struct{}
ConsensusBase is a base handler of the chain consensus
func (*ConsensusBase) InitGenesis ¶
func (cs *ConsensusBase) InitGenesis(ctw *types.ContextWrapper) error
InitGenesis initializes genesis data
func (*ConsensusBase) OnLoadChain ¶
func (cs *ConsensusBase) OnLoadChain(loader types.LoaderWrapper) error
OnLoadChain called when the chain loaded
func (*ConsensusBase) OnSaveData ¶
func (cs *ConsensusBase) OnSaveData(b *types.Block, ctw *types.ContextWrapper) error
OnSaveData called when the context of the block saved
func (*ConsensusBase) ValidateSignature ¶
ValidateSignature called when required to validate signatures
type Store ¶
type Store struct { sync.Mutex SeqMapLock sync.Mutex SeqMap map[common.Address]uint64 // contains filtered or unexported fields }
Store saves the target chain state All updates are executed in one transaction with FileSync option
func NewStore ¶
func NewStore(db backend.StoreBackend, cdb *pile.DB, ChainID uint8, symbol string, usage string, version uint16) (*Store, error)
NewStore returns a Store
func (*Store) AccountData ¶
AccountData returns the account data from the store
func (*Store) AddressByName ¶
AddressByName returns the account instance of the name from the store
func (*Store) HasAccount ¶
HasAccount bhecks that the account of the address is exist or not
func (*Store) HasAccountName ¶
HasAccountName bhecks that the account of the name is exist or not
func (*Store) IterBlockAfterContext ¶
func (*Store) LastStatus ¶
LastStatus returns the recored target height, prev hash and timestamp
func (*Store) LastTimestamp ¶
LastTimestamp returns the last timestamp of the chain
func (*Store) NewAddress ¶
NewAddress returns the new address with the magic number of the chain
func (*Store) NewLoaderWrapper ¶
func (st *Store) NewLoaderWrapper(pid uint8) types.LoaderWrapper
NewLoaderWrapper returns the loader wrapper of the chain
func (*Store) ProcessData ¶
ProcessData returns the process data from the store
func (*Store) StoreBlock ¶
StoreBlock stores the block
func (*Store) StoreGenesis ¶
StoreGenesis stores the genesis data
func (*Store) TargetHeight ¶
TargetHeight returns the target height of the target chain