mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-13 02:58:33 +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
0e1aaad6d4
commit
b765c44539
4 changed files with 34 additions and 2 deletions
|
@ -80,6 +80,10 @@ type BitcoindNotifier struct {
|
||||||
// time.
|
// time.
|
||||||
var _ chainntnfs.ChainNotifier = (*BitcoindNotifier)(nil)
|
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
|
// New returns a new BitcoindNotifier instance. This function assumes the
|
||||||
// bitcoind node detailed in the passed configuration is already running, and
|
// bitcoind node detailed in the passed configuration is already running, and
|
||||||
// willing to accept RPC requests and new zmq clients.
|
// 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.
|
// Ensure BtcdNotifier implements the ChainNotifier interface at compile time.
|
||||||
var _ chainntnfs.ChainNotifier = (*BtcdNotifier)(nil)
|
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
|
// New returns a new BtcdNotifier instance. This function assumes the btcd node
|
||||||
// detailed in the passed configuration is already running, and willing to
|
// detailed in the passed configuration is already running, and willing to
|
||||||
// accept new websockets clients.
|
// accept new websockets clients.
|
||||||
|
|
|
@ -808,3 +808,16 @@ type ConfirmHintCache interface {
|
||||||
// the cache.
|
// the cache.
|
||||||
PurgeConfirmHint(confRequests ...ConfRequest) error
|
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.
|
// interested in.
|
||||||
ChainNotifier chainntnfs.ChainNotifier
|
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 is used in the router for maintaining an up-to-date graph.
|
||||||
ChainView chainview.FilteredChainView
|
ChainView chainview.FilteredChainView
|
||||||
|
|
||||||
|
@ -433,10 +437,14 @@ func NewPartialChainControl(cfg *Config) (*PartialChainControl, func(), error) {
|
||||||
"bitcoind: %v", err)
|
"bitcoind: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cc.ChainNotifier = bitcoindnotify.New(
|
chainNotifier := bitcoindnotify.New(
|
||||||
bitcoindConn, cfg.ActiveNetParams.Params, hintCache,
|
bitcoindConn, cfg.ActiveNetParams.Params, hintCache,
|
||||||
hintCache, cfg.BlockCache,
|
hintCache, cfg.BlockCache,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
cc.ChainNotifier = chainNotifier
|
||||||
|
cc.MempoolNotifier = chainNotifier
|
||||||
|
|
||||||
cc.ChainView = chainview.NewBitcoindFilteredChainView(
|
cc.ChainView = chainview.NewBitcoindFilteredChainView(
|
||||||
bitcoindConn, cfg.BlockCache,
|
bitcoindConn, cfg.BlockCache,
|
||||||
)
|
)
|
||||||
|
@ -655,7 +663,8 @@ func NewPartialChainControl(cfg *Config) (*PartialChainControl, func(), error) {
|
||||||
DisableConnectOnNew: true,
|
DisableConnectOnNew: true,
|
||||||
DisableAutoReconnect: false,
|
DisableAutoReconnect: false,
|
||||||
}
|
}
|
||||||
cc.ChainNotifier, err = btcdnotify.New(
|
|
||||||
|
chainNotifier, err := btcdnotify.New(
|
||||||
rpcConfig, cfg.ActiveNetParams.Params, hintCache,
|
rpcConfig, cfg.ActiveNetParams.Params, hintCache,
|
||||||
hintCache, cfg.BlockCache,
|
hintCache, cfg.BlockCache,
|
||||||
)
|
)
|
||||||
|
@ -663,6 +672,9 @@ func NewPartialChainControl(cfg *Config) (*PartialChainControl, func(), error) {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cc.ChainNotifier = chainNotifier
|
||||||
|
cc.MempoolNotifier = chainNotifier
|
||||||
|
|
||||||
// Finally, we'll create an instance of the default chain view
|
// Finally, we'll create an instance of the default chain view
|
||||||
// to be used within the routing layer.
|
// to be used within the routing layer.
|
||||||
cc.ChainView, err = chainview.NewBtcdFilteredChainView(
|
cc.ChainView, err = chainview.NewBtcdFilteredChainView(
|
||||||
|
|
Loading…
Add table
Reference in a new issue