headerfs

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2019 License: ISC, MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrHeightNotFound is returned when a specified height isn't found in
	// a target index.
	ErrHeightNotFound = fmt.Errorf("target height not found in index")

	// ErrHashNotFound is returned when a specified block hash isn't found
	// in a target index.
	ErrHashNotFound = fmt.Errorf("target hash not found in index")
)

Functions

This section is empty.

Types

type BlockHeader

type BlockHeader struct {
	*wire.BlockHeader

	// Height is the height of this block header within the current main
	// chain.
	Height uint32
}

type BlockHeaderStore

type BlockHeaderStore interface {

	// ChainTip returns the best known block header and height for the
	// BlockHeaderStore.
	ChainTip() (*wire.BlockHeader, uint32, error)

	// LatestBlockLocator returns the latest block locator object based on
	// the tip of the current main chain from the PoV of the
	// BlockHeaderStore.
	LatestBlockLocator() (blockchain.BlockLocator, error)

	// FetchHeaderByHeight attempts to retrieve a target block header based
	// on a block height.
	FetchHeaderByHeight(height uint32) (*wire.BlockHeader, error)

	// FetchHeaderAncestors fetches the numHeaders block headers that are
	// the ancestors of the target stop hash. A total of numHeaders+1
	// headers will be returned, as we'll walk back numHeaders distance to
	// collect each header, then return the final header specified by the
	// stop hash. We'll also return the starting height of the header range
	// as well so callers can compute the height of each header without
	// knowing the height of the stop hash.
	FetchHeaderAncestors(uint32, *chainhash.Hash) ([]wire.BlockHeader,
		uint32, error)

	// HeightFromHash returns the height of a particular block header given
	// its hash.
	HeightFromHash(*chainhash.Hash) (uint32, error)

	// FetchHeader attempts to retrieve a block header determined by the
	// passed block height.
	FetchHeader(*chainhash.Hash) (*wire.BlockHeader, uint32, error)

	// WriteHeaders adds a set of headers to the BlockHeaderStore in a
	// single atomic transaction.
	WriteHeaders(...BlockHeader) error

	// RollbackLastBlock rolls back the BlockHeaderStore by a _single_
	// header. This method is meant to be used in the case of re-org which
	// disconnects the latest block header from the end of the main chain.
	// The information about the new header tip after truncation is
	// returned.
	RollbackLastBlock() (*waddrmgr.BlockStamp, error)
}

func NewBlockHeaderStore

func NewBlockHeaderStore(
	filePath string, db walletdb.DB,
	netParams *chaincfg.Params) (BlockHeaderStore, error)

NewBlockHeaderStore creates a new instance of the blockHeaderStore based on a target file path, an open database instance, and finally a set of parameters for the target chain. These parameters are required as if this is the initial start up of the blockHeaderStore, then the initial genesis header will need to be inserted.

type FilterHeader

type FilterHeader struct {

	// HeaderHash is the hash of the block header that this filter header
	// corresponds to.
	HeaderHash chainhash.Hash

	// FilterHash is the filter header itself.
	FilterHash chainhash.Hash

	// Height is the block height of the filter header in the main chain.
	Height uint32
}

type FilterHeaderStore

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

func NewFilterHeaderStore

func NewFilterHeaderStore(
	filePath string, db walletdb.DB,
	filterType HeaderType, netParams *chaincfg.Params) (*FilterHeaderStore, error)

NewFilterHeaderStore returns a new instance of the FilterHeaderStore based on a target file path, filter type, and target net parameters. These parameters are required as if this is the initial start up of the FilterHeaderStore, then the initial genesis filter header will need to be inserted.

func (*FilterHeaderStore) ChainTip

func (f *FilterHeaderStore) ChainTip() (*chainhash.Hash, uint32, error)

ChainTip returns the latest filter header and height known to the FilterHeaderStore.

func (*FilterHeaderStore) FetchHeader

func (f *FilterHeaderStore) FetchHeader(hash *chainhash.Hash) (*chainhash.Hash, error)

FetchHeader returns the filter header that corresponds to the passed block height.

func (*FilterHeaderStore) FetchHeaderByHeight

func (f *FilterHeaderStore) FetchHeaderByHeight(height uint32) (*chainhash.Hash, error)

FetchHeaderByHeight returns the filter header for a particular block height.

func (*FilterHeaderStore) RollbackLastBlock

func (f *FilterHeaderStore) RollbackLastBlock(newTip *chainhash.Hash) (*waddrmgr.BlockStamp, error)

RollbackLastBlock rollsback both the index, and on-disk header file by a _single_ filter header. This method is meant to be used in the case of re-org which disconnects the latest filter header from the end of the main chain. The information about the latest header tip after truncation is returned.

func (*FilterHeaderStore) WriteHeaders

func (f *FilterHeaderStore) WriteHeaders(hdrs ...FilterHeader) error

WriteHeaders writes a batch of filter headers to persistent storage. The headers themselves are appended to the flat file, and then the index updated to reflect the new entires.

type HeaderType

type HeaderType uint8
const (
	// Block is the header type that represents regular Bitcoin block
	// headers.
	Block HeaderType = iota

	// RegularFilter is a header type that represents the basic filter
	// header type for the filter header chain.
	RegularFilter
)

Jump to

Keyboard shortcuts

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