bitbox-wallet-app: Index | Files | Directories

package headers

import ""


Package Files

db.go headers.go

type DBInterface Uses

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
    // Close closes the database.
    Close() error

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

type Event Uses

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 Uses

type Headers struct {
    // contains filtered or unexported fields

Headers manages syncing blockchain headers.

func NewHeaders Uses

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

NewHeaders creates a new Headers instance.

func (*Headers) Close Uses

func (headers *Headers) Close() error

Close shuts down the downloading goroutine and closes the database.

func (*Headers) HeaderByHeight Uses

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 Uses

func (headers *Headers) Initialize()

Initialize starts the syncing process.

func (*Headers) Status Uses

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

Status returns the current sync status.

func (*Headers) SubscribeEvent Uses

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 Uses

func (headers *Headers) TipHeight() int

TipHeight returns the height of the tip.

type Interface Uses

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

Interface represents the public API of this package. go:generate mockery -name Interface

type Status Uses

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.



Package headers imports 15 packages (graph) and is imported by 3 packages. Updated 2019-11-23. Refresh now. Tools for package owners.