lnd/lntest/mock/chainnotifier.go
Olaoluwa Osuntokun 08f1c2e93a
chainntfns: add new option for conf notifications to send block
In this commit, we add a new option for the existing confirmation
notification system that optionally allows the caller to specify that a
block should be included as well.

The only quirk w/ the implementation here is the neutrino backend:
usually we get filtered blocks, we so need to first fetch the block
again so we can deliver the full block to the notifier. On the notifier
end, it'll only be checking for the transactions we care about, to
sending a full block doesn't affect the correctness.

We also extend the `testBatchConfirmationNotification` test to assert
that a block is only included if the caller specifies it.
2022-08-01 19:59:21 -07:00

64 lines
1.7 KiB
Go

package mock
import (
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/chainntnfs"
)
// ChainNotifier is a mock implementation of the ChainNotifier interface.
type ChainNotifier struct {
SpendChan chan *chainntnfs.SpendDetail
EpochChan chan *chainntnfs.BlockEpoch
ConfChan chan *chainntnfs.TxConfirmation
}
// RegisterConfirmationsNtfn returns a ConfirmationEvent that contains a channel
// that the tx confirmation will go over.
func (c *ChainNotifier) RegisterConfirmationsNtfn(txid *chainhash.Hash,
pkScript []byte, numConfs, heightHint uint32,
opts ...chainntnfs.NotifierOption) (*chainntnfs.ConfirmationEvent, error) {
return &chainntnfs.ConfirmationEvent{
Confirmed: c.ConfChan,
Cancel: func() {},
}, nil
}
// RegisterSpendNtfn returns a SpendEvent that contains a channel that the spend
// details will go over.
func (c *ChainNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint,
pkScript []byte, heightHint uint32) (*chainntnfs.SpendEvent, error) {
return &chainntnfs.SpendEvent{
Spend: c.SpendChan,
Cancel: func() {},
}, nil
}
// RegisterBlockEpochNtfn returns a BlockEpochEvent that contains a channel that
// block epochs will go over.
func (c *ChainNotifier) RegisterBlockEpochNtfn(blockEpoch *chainntnfs.BlockEpoch) (
*chainntnfs.BlockEpochEvent, error) {
return &chainntnfs.BlockEpochEvent{
Epochs: c.EpochChan,
Cancel: func() {},
}, nil
}
// Start currently returns a dummy value.
func (c *ChainNotifier) Start() error {
return nil
}
// Started currently returns a dummy value.
func (c *ChainNotifier) Started() bool {
return true
}
// Stop currently returns a dummy value.
func (c *ChainNotifier) Stop() error {
return nil
}