blockchain

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2021 License: Apache-2.0 Imports: 21 Imported by: 30

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrInvalidTipHeight is the error returned when the block height is not valid
	ErrInvalidTipHeight = errors.New("invalid tip height")
	// ErrInvalidBlock is the error returned when the block is not valid
	ErrInvalidBlock = errors.New("failed to validate the block")
	// ErrActionNonce is the error when the nonce of the action is wrong
	ErrActionNonce = errors.New("invalid action nonce")
	// ErrInsufficientGas indicates the error of insufficient gas value for data storage
	ErrInsufficientGas = errors.New("insufficient intrinsic gas value")
	// ErrBalance indicates the error of balance
	ErrBalance = errors.New("invalid balance")
)

Functions

func Productivity added in v1.0.0

func Productivity(bc Blockchain, startHeight uint64, endHeight uint64) (map[string]uint64, error)

Productivity returns the map of the number of blocks produced per delegate in given epoch

Types

type BlockBuilderFactory added in v0.11.0

type BlockBuilderFactory interface {
	// NewBlockBuilder creates block builder
	NewBlockBuilder(context.Context, func(action.Envelope) (action.SealedEnvelope, error)) (*block.Builder, error)
}

BlockBuilderFactory is the factory interface of block builder

type BlockCreationSubscriber added in v0.4.4

type BlockCreationSubscriber interface {
	ReceiveBlock(*block.Block) error
}

BlockCreationSubscriber is an interface which will get notified when a block is created

type Blockchain

type Blockchain interface {
	lifecycle.StartStopper

	// For exposing blockchain states
	// BlockHeaderByHeight return block header by height
	BlockHeaderByHeight(height uint64) (*block.Header, error)
	// BlockFooterByHeight return block footer by height
	BlockFooterByHeight(height uint64) (*block.Footer, error)
	// ChainID returns the chain ID
	ChainID() uint32
	// ChainAddress returns chain address on parent chain, the root chain return empty.
	ChainAddress() string
	// TipHash returns tip block's hash
	TipHash() hash.Hash256
	// TipHeight returns tip block's height
	TipHeight() uint64
	// Genesis returns the genesis
	Genesis() genesis.Genesis
	// Context returns current context
	Context(context.Context) (context.Context, error)

	// For block operations
	// MintNewBlock creates a new block with given actions
	// Note: the coinbase transfer will be added to the given transfers when minting a new block
	MintNewBlock(timestamp time.Time) (*block.Block, error)
	// CommitBlock validates and appends a block to the chain
	CommitBlock(blk *block.Block) error
	// ValidateBlock validates a new block before adding it to the blockchain
	ValidateBlock(blk *block.Block) error

	// AddSubscriber make you listen to every single produced block
	AddSubscriber(BlockCreationSubscriber) error

	// RemoveSubscriber make you listen to every single produced block
	RemoveSubscriber(BlockCreationSubscriber) error
}

Blockchain represents the blockchain data structure and hosts the APIs to access it

func NewBlockchain

func NewBlockchain(cfg config.Config, dao blockdao.BlockDAO, bbf BlockBuilderFactory, opts ...Option) Blockchain

NewBlockchain creates a new blockchain and DB instance TODO: replace sf with blockbuilderfactory

type Option added in v0.3.0

type Option func(*blockchain, config.Config) error

Option sets blockchain construction parameter

func BlockValidatorOption added in v0.11.0

func BlockValidatorOption(blockValidator block.Validator) Option

BlockValidatorOption sets block validator

func BoltDBDaoOption added in v0.3.0

func BoltDBDaoOption(indexers ...blockdao.BlockIndexer) Option

BoltDBDaoOption sets blockchain's dao with BoltDB from config.Chain.ChainDBPath

func ClockOption added in v0.3.0

func ClockOption(clk clock.Clock) Option

ClockOption overrides the default clock

func InMemDaoOption added in v0.3.0

func InMemDaoOption(indexers ...blockdao.BlockIndexer) Option

InMemDaoOption sets blockchain's dao with MemKVStore

type PubSubManager added in v0.11.0

type PubSubManager interface {
	AddBlockListener(BlockCreationSubscriber) error
	RemoveBlockListener(BlockCreationSubscriber) error
	SendBlockToSubscribers(*block.Block)
}

PubSubManager is an interface which handles multi-thread publisher and subscribers

func NewPubSub added in v0.11.0

func NewPubSub(bufferSize uint64) PubSubManager

NewPubSub creates new pubSub struct with buffersize for pendingBlock buffer channel

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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