mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 09:53:54 +01:00
5fce91caf9
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.
53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
package chainntnfs
|
|
|
|
import (
|
|
"github.com/btcsuite/btcd/wire"
|
|
"github.com/lightningnetwork/lnd/fn"
|
|
"github.com/stretchr/testify/mock"
|
|
)
|
|
|
|
// MockMempoolWatcher is a mock implementation of the MempoolWatcher interface.
|
|
// This is used by other subsystems to mock the behavior of the mempool
|
|
// watcher.
|
|
type MockMempoolWatcher struct {
|
|
mock.Mock
|
|
}
|
|
|
|
// NewMockMempoolWatcher returns a new instance of a mock mempool watcher.
|
|
func NewMockMempoolWatcher() *MockMempoolWatcher {
|
|
return &MockMempoolWatcher{}
|
|
}
|
|
|
|
// Compile-time check to ensure MockMempoolWatcher implements MempoolWatcher.
|
|
var _ MempoolWatcher = (*MockMempoolWatcher)(nil)
|
|
|
|
// SubscribeMempoolSpent implements the MempoolWatcher interface.
|
|
func (m *MockMempoolWatcher) SubscribeMempoolSpent(
|
|
op wire.OutPoint) (*MempoolSpendEvent, error) {
|
|
|
|
args := m.Called(op)
|
|
|
|
if args.Get(0) == nil {
|
|
return nil, args.Error(1)
|
|
}
|
|
|
|
return args.Get(0).(*MempoolSpendEvent), args.Error(1)
|
|
}
|
|
|
|
// CancelMempoolSpendEvent implements the MempoolWatcher interface.
|
|
func (m *MockMempoolWatcher) CancelMempoolSpendEvent(
|
|
sub *MempoolSpendEvent) {
|
|
|
|
m.Called(sub)
|
|
}
|
|
|
|
// LookupInputMempoolSpend looks up the mempool to find a spending tx which
|
|
// spends the given outpoint.
|
|
func (m *MockMempoolWatcher) LookupInputMempoolSpend(
|
|
op wire.OutPoint) fn.Option[wire.MsgTx] {
|
|
|
|
args := m.Called(op)
|
|
|
|
return args.Get(0).(fn.Option[wire.MsgTx])
|
|
}
|