chain

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: 15 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

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

func BuildLevelRoot(hashes []hash.Hash256) (hash.Hash256, error)

BuildLevelRoot returns the level root hash

Types

type AccountTransaction

type AccountTransaction interface {
	Seq() uint64
	From() common.Address
}

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, Timestamp uint64) *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() (*types.Block, error)

Finalize generates block that has transactions adds by AddTx

func (*BlockCreator) Init

func (bc *BlockCreator) Init() error

Init initializes the block creator

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

type Chain struct {
	sync.Mutex
	// contains filtered or unexported fields
}

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

func (cn *Chain) Close()

Close terminates and cleans the chain

func (*Chain) ConnectBlock

func (cn *Chain) ConnectBlock(b *types.Block, sp SignerProvider) error

ConnectBlock try to connect block to the chain

func (*Chain) Init

func (cn *Chain) Init() error

Init initializes the chain

func (*Chain) MustAddProcess

func (cn *Chain) MustAddProcess(p types.Process)

MustAddProcess adds Process but panic when has the same name process

func (*Chain) MustAddService

func (cn *Chain) MustAddService(s types.Service)

MustAddService adds Service but panic when has the same name service

func (*Chain) NewContext

func (cn *Chain) NewContext() *types.Context

NewContext returns the context of the chain

func (*Chain) Process

func (cn *Chain) Process(id uint8) (types.Process, error)

Process returns the process by the id

func (*Chain) ProcessByName

func (cn *Chain) ProcessByName(name string) (types.Process, error)

ProcessByName returns the process by the name

func (*Chain) Processes

func (cn *Chain) Processes() []types.Process

Processes returns processes

func (*Chain) Provider

func (cn *Chain) Provider() types.Provider

Provider returns a chain provider

func (*Chain) ServiceByName

func (cn *Chain) ServiceByName(name string) (types.Service, error)

ServiceByName returns the service by the name

func (*Chain) Services

func (cn *Chain) Services() []types.Service

Services returns services

type Committer

type Committer interface {
	ValidateHeader(bh *types.Header) error
	ExecuteBlockOnContext(b *types.Block, ctx *types.Context, sp SignerProvider) 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

func (cs *ConsensusBase) ValidateSignature(bh *types.Header, sigs []common.Signature) error

ValidateSignature called when required to validate signatures

type SignerProvider

type SignerProvider interface {
	GetSigners(TxHash hash.Hash256) ([]common.Signature, []common.PublicHash)
	UnsafeGetSigners(TxHash hash.Hash256) ([]common.Signature, []common.PublicHash)
	Lock()
	Unlock()
}

SignerProvider provides signers of the hash

type Store

type Store struct {
	sync.Mutex
	// 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) Account

func (st *Store) Account(addr common.Address) (types.Account, error)

Account returns the account instance of the address from the store

func (*Store) AccountData

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

AccountData returns the account data from the store

func (*Store) Accounts

func (st *Store) Accounts() ([]types.Account, error)

Accounts returns all accounts in the store

func (*Store) AddressByName

func (st *Store) AddressByName(Name string) (common.Address, error)

AddressByName returns the account instance of the name from the store

func (*Store) Block

func (st *Store) Block(height uint32) (*types.Block, error)

Block returns the block by height

func (*Store) ChainID

func (st *Store) ChainID() uint8

ChainID returns the chain id of the target chain

func (*Store) Close

func (st *Store) Close()

Close terminate and clean store

func (*Store) Events

func (st *Store) Events(From uint32, To uint32) ([]types.Event, error)

Events returns all events by conditions

func (*Store) HasAccount

func (st *Store) HasAccount(addr common.Address) (bool, error)

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

func (*Store) HasAccountName

func (st *Store) HasAccountName(Name string) (bool, error)

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

func (*Store) HasTimeSlot

func (st *Store) HasTimeSlot(slot uint32, key string) bool

HasTimeSlot returns timeslot is exist or not

func (*Store) HasUTXO

func (st *Store) HasUTXO(id uint64) (bool, error)

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

func (*Store) Hash

func (st *Store) Hash(height uint32) (hash.Hash256, error)

Hash returns the hash of the data by height

func (*Store) Header

func (st *Store) Header(height uint32) (*types.Header, error)

Header returns the header of the data by height

func (*Store) Height

func (st *Store) Height() uint32

Height returns the current height of the target chain

func (*Store) IterBlockAfterContext

func (st *Store) IterBlockAfterContext(fn func(b *types.Block) error) error

func (*Store) LastHash

func (st *Store) LastHash() hash.Hash256

LastHash returns the last hash of the chain

func (*Store) LastStatus

func (st *Store) LastStatus() (uint32, hash.Hash256)

LastStatus returns the recored target height, prev hash and timestamp

func (*Store) LastTimestamp

func (st *Store) LastTimestamp() uint64

LastTimestamp returns the last timestamp of the chain

func (*Store) Name

func (st *Store) Name() string

Name returns the name of the target chain

func (*Store) NewAddress

func (st *Store) NewAddress(height uint32, index uint16) common.Address

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

func (st *Store) ProcessData(pid uint8, name []byte) []byte

ProcessData returns the process data from the store

func (*Store) StoreBlock

func (st *Store) StoreBlock(b *types.Block, ctd *types.ContextData) error

StoreBlock stores the block

func (*Store) StoreGenesis

func (st *Store) StoreGenesis(genHash hash.Hash256, ctd *types.ContextData) error

StoreGenesis stores the genesis data

func (*Store) Symbol

func (st *Store) Symbol() string

Symbol returns the symbol of the target chain

func (*Store) TargetHeight

func (st *Store) TargetHeight() uint32

TargetHeight returns the target height of the target chain

func (*Store) UTXO

func (st *Store) UTXO(id uint64) (*types.UTXO, error)

UTXO returns the UTXO from the top store

func (*Store) UTXOs

func (st *Store) UTXOs() ([]*types.UTXO, error)

UTXOs returns all UTXOs in the store

func (*Store) Usage

func (st *Store) Usage() string

Usage returns the usage of the target chain

func (*Store) Version

func (st *Store) Version() uint16

Version returns the version of the target chain

Jump to

Keyboard shortcuts

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