chain

package
v0.0.0-...-77b6ffe Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBlock

func GetBlock(hash common.Hash, height uint64) *types.Block

func GetBlockByHash

func GetBlockByHash(hash common.Hash) *types.Block

func GetBlockByHeight

func GetBlockByHeight(height uint64) *types.Block

func GetHeightOfChain

func GetHeightOfChain() uint64

Types

type Blockchain

type Blockchain interface {
	Genesis() *types.Block
	LastBlock() *types.Block      // Last block in memory
	LastFinalBlock() *types.Block // Last irreversible block
	GetBlockByHeight(height uint64) *types.Block
	GetBlockByHash(hash common.Hash) *types.Block
	GetHeader(hash common.Hash, height uint64) *types.Header
	GetHeaderByHash(hash common.Hash) *types.Header
	AddBlock(block *types.Block) error
}

type Ledger

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

Ledger is the canonical blockchain given a database with a genesis block

func NewBlockchain

func NewBlockchain(db tdb.Database) (*Ledger, error)

func (*Ledger) AddBlock

func (bc *Ledger) AddBlock(block *types.Block) error

AddBlock appends block into chain. The blocks passed have been validated by block_pool.

func (*Ledger) AddBlocks

func (bc *Ledger) AddBlocks(blocks types.Blocks) error

AddBlocks insert blocks in batch when importing outer blockchain

func (*Ledger) CommitBlock

func (bc *Ledger) CommitBlock(batch tdb.Batch, block *types.Block) error

commit persist the block to db.

func (*Ledger) Genesis

func (bc *Ledger) Genesis() *types.Block

func (*Ledger) GetBlock

func (bc *Ledger) GetBlock(hash common.Hash, height uint64) *types.Block

func (*Ledger) GetBlockByHash

func (bc *Ledger) GetBlockByHash(hash common.Hash) *types.Block

func (*Ledger) GetBlockByHeight

func (bc *Ledger) GetBlockByHeight(height uint64) *types.Block

func (*Ledger) GetHash

func (bc *Ledger) GetHash(height uint64) common.Hash

func (*Ledger) GetHeader

func (bc *Ledger) GetHeader(hash common.Hash, height uint64) *types.Header

func (*Ledger) GetHeaderByHash

func (bc *Ledger) GetHeaderByHash(hash common.Hash) *types.Header

func (*Ledger) LastBlock

func (bc *Ledger) LastBlock() *types.Block

LastBlock returns the last block of latest blockchain in memory

func (*Ledger) LastFinalBlock

func (bc *Ledger) LastFinalBlock() *types.Block

LastFinalBlock returns the last commited block in db

func (*Ledger) LastHeight

func (bc *Ledger) LastHeight() uint64

func (*Ledger) Purge

func (bc *Ledger) Purge()

Purge drop the blocks in memory and revert the blockchain to the height of `lastFinalBlock`

func (*Ledger) Reset

func (bc *Ledger) Reset() error

Reset init Ledger with genesis block

func (*Ledger) ResetWithGenesis

func (bc *Ledger) ResetWithGenesis(genesis *types.Block) error

func (*Ledger) SetGenesis

func (bc *Ledger) SetGenesis(genesis *types.Block) error

Jump to

Keyboard shortcuts

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