mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-01 10:11:11 +02:00
chainntnfs: refactor common registration code within RegisterConfirmationsNtfn
This commit is contained in:
@@ -50,7 +50,6 @@ type txUpdate struct {
|
||||
// notifications. Multiple concurrent clients are supported. All notifications
|
||||
// are achieved via non-blocking sends on client channels.
|
||||
type BtcdNotifier struct {
|
||||
confClientCounter uint64 // To be used aotmically.
|
||||
spendClientCounter uint64 // To be used atomically.
|
||||
epochClientCounter uint64 // To be used atomically.
|
||||
|
||||
@@ -851,41 +850,23 @@ func (b *BtcdNotifier) RegisterConfirmationsNtfn(txid *chainhash.Hash,
|
||||
pkScript []byte,
|
||||
numConfs, heightHint uint32) (*chainntnfs.ConfirmationEvent, error) {
|
||||
|
||||
// Construct a notification request for the transaction and send it to
|
||||
// the main event loop.
|
||||
confID := atomic.AddUint64(&b.confClientCounter, 1)
|
||||
confRequest, err := chainntnfs.NewConfRequest(txid, pkScript)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ntfn := &chainntnfs.ConfNtfn{
|
||||
ConfID: confID,
|
||||
ConfRequest: confRequest,
|
||||
NumConfirmations: numConfs,
|
||||
Event: chainntnfs.NewConfirmationEvent(numConfs, func() {
|
||||
b.txNotifier.CancelConf(confRequest, confID)
|
||||
}),
|
||||
HeightHint: heightHint,
|
||||
}
|
||||
|
||||
chainntnfs.Log.Infof("New confirmation subscription: %v, num_confs=%v ",
|
||||
confRequest, numConfs)
|
||||
|
||||
// Register the conf notification with the TxNotifier. A non-nil value
|
||||
// for `dispatch` will be returned if we are required to perform a
|
||||
// manual scan for the confirmation. Otherwise the notifier will begin
|
||||
// watching at tip for the transaction to confirm.
|
||||
dispatch, _, err := b.txNotifier.RegisterConf(ntfn)
|
||||
ntfn, err := b.txNotifier.RegisterConf(
|
||||
txid, pkScript, numConfs, heightHint,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if dispatch == nil {
|
||||
if ntfn.HistoricalDispatch == nil {
|
||||
return ntfn.Event, nil
|
||||
}
|
||||
|
||||
select {
|
||||
case b.notificationRegistry <- dispatch:
|
||||
case b.notificationRegistry <- ntfn.HistoricalDispatch:
|
||||
return ntfn.Event, nil
|
||||
case <-b.quit:
|
||||
return nil, chainntnfs.ErrChainNotifierShuttingDown
|
||||
|
Reference in New Issue
Block a user