mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 01:43:16 +01:00
chainntnfs+chainreg: add interface MempoolWatcher
This commit adds the interface `MempoolWatcher` and uses it in the chain registry.
This commit is contained in:
parent
ad5e798392
commit
e81d62fc70
@ -80,6 +80,10 @@ type BitcoindNotifier struct {
|
||||
// time.
|
||||
var _ chainntnfs.ChainNotifier = (*BitcoindNotifier)(nil)
|
||||
|
||||
// Ensure BitcoindNotifier implements the MempoolWatcher interface at compile
|
||||
// time.
|
||||
var _ chainntnfs.MempoolWatcher = (*BitcoindNotifier)(nil)
|
||||
|
||||
// New returns a new BitcoindNotifier instance. This function assumes the
|
||||
// bitcoind node detailed in the passed configuration is already running, and
|
||||
// willing to accept RPC requests and new zmq clients.
|
||||
|
@ -96,6 +96,9 @@ type BtcdNotifier struct {
|
||||
// Ensure BtcdNotifier implements the ChainNotifier interface at compile time.
|
||||
var _ chainntnfs.ChainNotifier = (*BtcdNotifier)(nil)
|
||||
|
||||
// Ensure BtcdNotifier implements the MempoolWatcher interface at compile time.
|
||||
var _ chainntnfs.MempoolWatcher = (*BtcdNotifier)(nil)
|
||||
|
||||
// New returns a new BtcdNotifier instance. This function assumes the btcd node
|
||||
// detailed in the passed configuration is already running, and willing to
|
||||
// accept new websockets clients.
|
||||
|
@ -808,3 +808,16 @@ type ConfirmHintCache interface {
|
||||
// the cache.
|
||||
PurgeConfirmHint(confRequests ...ConfRequest) error
|
||||
}
|
||||
|
||||
// MempoolWatcher defines an interface that allows the caller to query
|
||||
// information in the mempool.
|
||||
type MempoolWatcher interface {
|
||||
// SubscribeMempoolSpent allows the caller to register a subscription
|
||||
// to watch for a spend of an outpoint in the mempool.The event will be
|
||||
// dispatched once the outpoint is spent in the mempool.
|
||||
SubscribeMempoolSpent(op wire.OutPoint) (*MempoolSpendEvent, error)
|
||||
|
||||
// CancelMempoolSpendEvent allows the caller to cancel a subscription to
|
||||
// watch for a spend of an outpoint in the mempool.
|
||||
CancelMempoolSpendEvent(sub *MempoolSpendEvent)
|
||||
}
|
||||
|
@ -182,6 +182,10 @@ type PartialChainControl struct {
|
||||
// interested in.
|
||||
ChainNotifier chainntnfs.ChainNotifier
|
||||
|
||||
// MempoolNotifier is used to watch for spending events happened in
|
||||
// mempool.
|
||||
MempoolNotifier chainntnfs.MempoolWatcher
|
||||
|
||||
// ChainView is used in the router for maintaining an up-to-date graph.
|
||||
ChainView chainview.FilteredChainView
|
||||
|
||||
@ -433,10 +437,14 @@ func NewPartialChainControl(cfg *Config) (*PartialChainControl, func(), error) {
|
||||
"bitcoind: %v", err)
|
||||
}
|
||||
|
||||
cc.ChainNotifier = bitcoindnotify.New(
|
||||
chainNotifier := bitcoindnotify.New(
|
||||
bitcoindConn, cfg.ActiveNetParams.Params, hintCache,
|
||||
hintCache, cfg.BlockCache,
|
||||
)
|
||||
|
||||
cc.ChainNotifier = chainNotifier
|
||||
cc.MempoolNotifier = chainNotifier
|
||||
|
||||
cc.ChainView = chainview.NewBitcoindFilteredChainView(
|
||||
bitcoindConn, cfg.BlockCache,
|
||||
)
|
||||
@ -655,7 +663,8 @@ func NewPartialChainControl(cfg *Config) (*PartialChainControl, func(), error) {
|
||||
DisableConnectOnNew: true,
|
||||
DisableAutoReconnect: false,
|
||||
}
|
||||
cc.ChainNotifier, err = btcdnotify.New(
|
||||
|
||||
chainNotifier, err := btcdnotify.New(
|
||||
rpcConfig, cfg.ActiveNetParams.Params, hintCache,
|
||||
hintCache, cfg.BlockCache,
|
||||
)
|
||||
@ -663,6 +672,9 @@ func NewPartialChainControl(cfg *Config) (*PartialChainControl, func(), error) {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
cc.ChainNotifier = chainNotifier
|
||||
cc.MempoolNotifier = chainNotifier
|
||||
|
||||
// Finally, we'll create an instance of the default chain view
|
||||
// to be used within the routing layer.
|
||||
cc.ChainView, err = chainview.NewBtcdFilteredChainView(
|
||||
|
Loading…
Reference in New Issue
Block a user