mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-29 07:00:55 +02:00
chainntnfs+sweep: add LookupInputMempoolSpend
and use it in the
sweeper This commit implements a new method, `LookupInputMempoolSpend` to do lookups in the mempool. This method is useful in the case when we only want to know whether an input is already been spent in the mempool by the time we call.
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/btcsuite/btcwallet/chain"
|
||||
"github.com/lightningnetwork/lnd/blockcache"
|
||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||
"github.com/lightningnetwork/lnd/fn"
|
||||
"github.com/lightningnetwork/lnd/queue"
|
||||
)
|
||||
|
||||
@@ -1070,3 +1071,26 @@ func (b *BitcoindNotifier) CancelMempoolSpendEvent(
|
||||
|
||||
b.memNotifier.UnsubscribeEvent(sub)
|
||||
}
|
||||
|
||||
// LookupInputMempoolSpend takes an outpoint and queries the mempool to find
|
||||
// its spending tx. Returns the tx if found, otherwise fn.None.
|
||||
//
|
||||
// NOTE: part of the MempoolWatcher interface.
|
||||
func (b *BitcoindNotifier) LookupInputMempoolSpend(
|
||||
op wire.OutPoint) fn.Option[wire.MsgTx] {
|
||||
|
||||
// Find the spending txid.
|
||||
txid, found := b.chainConn.LookupInputMempoolSpend(op)
|
||||
if !found {
|
||||
return fn.None[wire.MsgTx]()
|
||||
}
|
||||
|
||||
// Query the spending tx using the id.
|
||||
tx, err := b.chainConn.GetRawTransaction(&txid)
|
||||
if err != nil {
|
||||
// TODO(yy): enable logging errors in this package.
|
||||
return fn.None[wire.MsgTx]()
|
||||
}
|
||||
|
||||
return fn.Some(*tx.MsgTx().Copy())
|
||||
}
|
||||
|
Reference in New Issue
Block a user