headers

package
v4.14.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DBInterface

type DBInterface interface {
	// PutHeader stores a header at the specified height.
	PutHeader(height int, header *wire.BlockHeader) error
	// HeaderByHeight retrieves a header stored at the specified height. If no header was found, nil
	// is returned.
	HeaderByHeight(height int) (*wire.BlockHeader, error)
	// RevertTo deletes all headers after tip.
	RevertTo(tip int) error
	// Tip retrieves the current max. height.
	Tip() (int, error)
	// Flush forces the db changes to the filesystem.
	Flush() error
}

DBInterface can be implemented by database backends to store/retrieve headers.

type Event

type Event string

Event instances are sent to the onEvent callback.

const (
	// EventSyncing is fired when the headers are syncing (a batch was downloaded but more are
	// coming). At the end, EventSynced is fired.
	EventSyncing Event = "syncing"
	// EventSynced is fired when the headers finished syncing.
	EventSynced Event = "synced"
	// EventNewTip is fired when a new tip is known.
	EventNewTip Event = "newTip"
)

type Headers

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

Headers manages syncing blockchain headers.

func NewHeaders

func NewHeaders(
	net *chaincfg.Params,
	db DBInterface,
	blockchain blockchain.Interface,
	log *logrus.Entry) *Headers

NewHeaders creates a new Headers instance.

func (*Headers) HeaderByHeight

func (headers *Headers) HeaderByHeight(height int) (*wire.BlockHeader, error)

HeaderByHeight returns the header at the given height. Returns nil if the headers are not synced up to this height yet.

func (*Headers) Initialize

func (headers *Headers) Initialize()

Initialize starts the syncing process.

func (*Headers) Status

func (headers *Headers) Status() (*Status, error)

Status returns the current sync status.

func (*Headers) SubscribeEvent

func (headers *Headers) SubscribeEvent(f func(event Event)) func()

SubscribeEvent subscribes to header events. The provided callback will be notified of events. The returned function unsubscribes. FIXME: not thread-safe

func (*Headers) TipHeight

func (headers *Headers) TipHeight() int

TipHeight returns the height of the tip.

type Interface

type Interface interface {
	Initialize()
	SubscribeEvent(f func(Event)) func()
	HeaderByHeight(int) (*wire.BlockHeader, error)
	TipHeight() int
	Status() (*Status, error)
}

Interface represents the public API of this package.

type Status

type Status struct {
	TipAtInitTime int `json:"tipAtInitTime"`
	Tip           int `json:"tip"`
	// Only well defined if Tip >= 0
	TipHashHex   blockchain.TXHash `json:"tipHashHex"`
	TargetHeight int               `json:"targetHeight"`
}

Status represents the syncing status.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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