Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrSubscriptionManagerStopped is an error returned when we attempt to // register a new block subscription but the manager has been stopped. ErrSubscriptionManagerStopped = errors.New("subscription manager was " + "stopped") )
Functions ¶
func DisableLog ¶
func DisableLog()
DisableLog disables all library log output. Logging output is disabled by default until either UseLogger or SetLogWriter are called.
Types ¶
type BlockNtfn ¶
type BlockNtfn interface { // Header returns the header of the block for which this notification is // for. Header() wire.BlockHeader // Height returns the height of the block for which this notification is // for. Height() uint32 // ChainTip returns the header of the new tip of the chain after // processing the block being connected/disconnected. ChainTip() wire.BlockHeader }
BlockNtfn is an interface that coalesces all the different types of block notifications.
type Connected ¶
type Connected struct {
// contains filtered or unexported fields
}
Connected is a block notification that gets dispatched to clients when the filter header of a new block has been found that extends the current chain.
func NewBlockConnected ¶
func NewBlockConnected(header wire.BlockHeader, height uint32) *Connected
NewBlockConnected creates a new Connected notification for the given block.
func (*Connected) ChainTip ¶
func (n *Connected) ChainTip() wire.BlockHeader
ChainTip returns the header of the new tip of the chain after processing the block being connected.
func (*Connected) Header ¶
func (n *Connected) Header() wire.BlockHeader
Header returns the header of the block extending the chain.
type Disconnected ¶
type Disconnected struct {
// contains filtered or unexported fields
}
Disconnected if a notification that gets dispatched to clients when a reorg has been detected at the tip of the chain.
func NewBlockDisconnected ¶
func NewBlockDisconnected(headerDisconnected wire.BlockHeader, heightDisconnected uint32, chainTip wire.BlockHeader) *Disconnected
NewBlockDisconnected creates a Disconnected notification for the given block.
func (*Disconnected) ChainTip ¶
func (n *Disconnected) ChainTip() wire.BlockHeader
ChainTip returns the header of the new tip of the chain after processing the block being disconnected.
func (*Disconnected) Header ¶
func (n *Disconnected) Header() wire.BlockHeader
Header returns the header of the block being disconnected.
func (*Disconnected) Height ¶
func (n *Disconnected) Height() uint32
Height returns the height of the block being disconnected.
func (*Disconnected) String ¶
func (n *Disconnected) String() string
String returns the string representation of a Disconnected notification.
type NotificationSource ¶
type NotificationSource interface { // Notifications returns a channel through which the latest // notifications of the tip of the chain can be retrieved from. Notifications() <-chan BlockNtfn // NotificationsSinceHeight returns a backlog of block notifications // starting from the given height to the tip of the chain. // // TODO(wilmer): extend with best hash to track reorgs. NotificationsSinceHeight(uint32) ([]BlockNtfn, uint32, error) }
NotificationSource is an interface responsible for delivering block notifications of a chain.
type Subscription ¶
type Subscription struct { // Notifications is the channel through which block notifications will // be sent through. // // TODO(wilmer): make read-only chan once we remove // resetBlockReFetchTimer hack from rescan. Notifications chan BlockNtfn // Cancel is closure that can be invoked to cancel the client's desire // to receive notifications. Cancel func() }
Subscription represents an intent to receive notifications about the latest block events in the chain. The notifications will be streamed through the Notifications channel. A Cancel closure is also included to indicate that the client no longer wishes to receive any notifications.
type SubscriptionManager ¶
type SubscriptionManager struct {
// contains filtered or unexported fields
}
SubscriptionManager is a system responsible for managing the delivery of block notifications for a chain at tip to multiple clients in an asynchronous manner.
func NewSubscriptionManager ¶
func NewSubscriptionManager(ntfnSource NotificationSource) *SubscriptionManager
NewSubscriptionManager creates a subscription manager backed by a NotificationSource.
func (*SubscriptionManager) NewSubscription ¶
func (m *SubscriptionManager) NewSubscription(bestHeight uint32) (*Subscription, error)
NewSubscription creates a new block notification subscription for a client. The bestHeight parameter can be used by the client to indicate its best known state. A backlog of notifications from said point until the tip of the chain will be delivered upon the client's successful registration. When providing a bestHeight of 0, no backlog will be delivered.
These notifications, along with the latest notifications of the chain, will be delivered through the Notifications channel within the Subscription returned. A Cancel closure is also provided, in the event that the client wishes to no longer receive any notifications.
func (*SubscriptionManager) Start ¶
func (m *SubscriptionManager) Start()
Start starts all the goroutines required for the SubscriptionManager to carry out its duties.
func (*SubscriptionManager) Stop ¶
func (m *SubscriptionManager) Stop()
Stop stops all active goroutines required for the SubscriptionManager to carry out its duties.