headers

package
v4.7.0+incompatible Latest Latest
Warning

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

Go to latest
Published: May 10, 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 {
	// Begin starts a DB transaction. Apply `defer tx.Rollback()` in any case after. Use
	// `tx.Commit()` to commit the write operations.
	Begin() (DBTxInterface, error)
}

DBInterface can be implemented by database backends to open database transactions.

type DBTxInterface

type DBTxInterface interface {
	// Commit closes the transaction, writing the changes.
	Commit() error
	// Rollback closes the transaction without writing anything and be called safely after Commit().
	Rollback()
	// PutHeader stores a header at a new tip.
	PutHeader(tip int, header *wire.BlockHeader) error
	HeaderByHeight(height int) (*wire.BlockHeader, error)
	PutTip(tip int) error
	Tip() (int, error)
}

DBTxInterface needs to be implemented to persist all headers related data.

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