diff --git a/chainntnfs/bitcoindnotify/bitcoind.go b/chainntnfs/bitcoindnotify/bitcoind.go index 78a9aba57..e9393ff6d 100644 --- a/chainntnfs/bitcoindnotify/bitcoind.go +++ b/chainntnfs/bitcoindnotify/bitcoind.go @@ -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. diff --git a/chainntnfs/btcdnotify/btcd.go b/chainntnfs/btcdnotify/btcd.go index ca4b89823..32f776fe8 100644 --- a/chainntnfs/btcdnotify/btcd.go +++ b/chainntnfs/btcdnotify/btcd.go @@ -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. diff --git a/chainntnfs/interface.go b/chainntnfs/interface.go index 7d160de13..3362a9d2d 100644 --- a/chainntnfs/interface.go +++ b/chainntnfs/interface.go @@ -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) +} diff --git a/chainreg/chainregistry.go b/chainreg/chainregistry.go index 667c20d38..c4a5caecd 100644 --- a/chainreg/chainregistry.go +++ b/chainreg/chainregistry.go @@ -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(