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) SubscribeEvent ¶
SubscribeEvent subscribes to header events. The provided callback will be notified of events. The returned function unsubscribes. FIXME: not thread-safe
Click to show internal directories.
Click to hide internal directories.