chain

package
v0.0.0-...-37869b2 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2019 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MAX_HEADERS = 2000
	CACHE_SIZE  = 100
)

Variables

View Source
var (
	BKTHeaders  = []byte("Headers")
	BKTChainTip = []byte("ChainTip")
	KEYChainTip = []byte("ChainTip")
)
View Source
var OrphanHeaderError = errors.New("header does not extend any known headers")

Functions

This section is empty.

Types

type Blockchain

type Blockchain struct {
	HeaderUpdate chan uint32
	IsOpen       bool
	// contains filtered or unexported fields
}

Wrapper around Headers implementation that handles all blockchain operations

func NewBlockchain

func NewBlockchain(filePath string, params *chaincfg.Params, isOpen bool) (*Blockchain, error)

func (*Blockchain) BestBlock

func (b *Blockchain) BestBlock() (StoredHeader, error)

func (*Blockchain) CheckHeader

func (b *Blockchain) CheckHeader(header wire.BlockHeader, prevHeader StoredHeader) bool

func (*Blockchain) Close

func (b *Blockchain) Close()

func (*Blockchain) CommitHeader

func (b *Blockchain) CommitHeader(header wire.BlockHeader) (bool, *StoredHeader, uint32, error)

func (*Blockchain) GetBlockLocator

func (b *Blockchain) GetBlockLocator() blockchain.BlockLocator

func (*Blockchain) GetCommonAncestor

func (b *Blockchain) GetCommonAncestor(bestHeader, prevBestHeader StoredHeader) (*StoredHeader, error)

GetCommonAncestor returns last header before reorg point

func (*Blockchain) GetEpoch

func (b *Blockchain) GetEpoch() (*wire.BlockHeader, error)

func (*Blockchain) GetHeader

func (b *Blockchain) GetHeader(hash *chainhash.Hash) (StoredHeader, error)

func (*Blockchain) GetHeaderByHeight

func (b *Blockchain) GetHeaderByHeight(height uint32) (sh StoredHeader, err error)

add by zou

func (*Blockchain) GetNPrevBlockHashes

func (b *Blockchain) GetNPrevBlockHashes(n int) []*chainhash.Hash

func (*Blockchain) Rollback

func (b *Blockchain) Rollback(t time.Time) error

Rollback the header database to the last header before time t. We shouldn't go back further than the checkpoint

type Checkpoint

type Checkpoint struct {
	Height uint32
	Header wire.BlockHeader
}

func GetCheckpoint

func GetCheckpoint(walletCreationDate time.Time, params *chaincfg.Params) Checkpoint

type HeaderCache

type HeaderCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*HeaderCache) Get

func (h *HeaderCache) Get(hash chainhash.Hash) (StoredHeader, error)

func (*HeaderCache) GetHashByHeight

func (h *HeaderCache) GetHashByHeight(height uint32) (chainhash.Hash, error)

add by zou

func (*HeaderCache) Set

func (h *HeaderCache) Set(sh StoredHeader)

type HeaderDB

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

HeaderDB implements Headers using bolt DB

func NewHeaderDB

func NewHeaderDB(filePath string) (*HeaderDB, error)

func (*HeaderDB) Close

func (h *HeaderDB) Close()

func (*HeaderDB) DeleteAfter

func (h *HeaderDB) DeleteAfter(height uint32) error

func (*HeaderDB) GetBestHeader

func (h *HeaderDB) GetBestHeader() (sh StoredHeader, err error)

func (*HeaderDB) GetHeader

func (h *HeaderDB) GetHeader(hash chainhash.Hash) (sh StoredHeader, err error)

func (*HeaderDB) GetHeaderByHeight

func (h *HeaderDB) GetHeaderByHeight(height uint32) (sh StoredHeader, err error)

add by zou

func (*HeaderDB) GetPreviousHeader

func (h *HeaderDB) GetPreviousHeader(header wire.BlockHeader) (sh StoredHeader, err error)

func (*HeaderDB) Height

func (h *HeaderDB) Height() (uint32, error)

func (*HeaderDB) Print

func (h *HeaderDB) Print(w io.Writer)

func (*HeaderDB) Prune

func (h *HeaderDB) Prune() error

func (*HeaderDB) Put

func (h *HeaderDB) Put(sh StoredHeader, newBestHeader bool) error

type Headers

type Headers interface {
	// Put a block header to the database
	// Total work and height are required to be calculated prior to insertion
	// If this is the new best header, the chain tip should also be updated
	Put(header StoredHeader, newBestHeader bool) error

	// Delete all headers after the MAX_HEADERS most recent
	Prune() error

	// Delete all headers after the given height
	DeleteAfter(height uint32) error

	// Returns all information about the previous header
	GetPreviousHeader(header wire.BlockHeader) (StoredHeader, error)

	// Grab a header given hash
	GetHeader(hash chainhash.Hash) (StoredHeader, error)

	// add by zou
	GetHeaderByHeight(height uint32) (StoredHeader, error)

	// Retrieve the best header from the database
	GetBestHeader() (StoredHeader, error)

	// Get the height of chain
	Height() (uint32, error)

	// Cleanly close the db
	Close()

	// Print all headers
	Print(io.Writer)
}

Database interface for storing block headers

type StoredHeader

type StoredHeader struct {
	Header wire.BlockHeader
	Height uint32
	// contains filtered or unexported fields
}

func (*StoredHeader) GetTotalWork

func (sh *StoredHeader) GetTotalWork() *big.Int

Jump to

Keyboard shortcuts

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