chainntnfs: add new method notifyNumConfsLeft

So it's easier to handle the following commit where we start skipping
duplicate notifications.
This commit is contained in:
yyforyongyu
2024-11-19 16:02:19 +08:00
parent 0c3b2b5e06
commit 7695880c13

View File

@@ -942,10 +942,9 @@ func (n *TxNotifier) dispatchConfDetails(
// We'll send a 0 value to the Updates channel, // We'll send a 0 value to the Updates channel,
// indicating that the transaction/output script has already // indicating that the transaction/output script has already
// been confirmed. // been confirmed.
select { err := n.notifyNumConfsLeft(ntfn, 0)
case ntfn.Event.Updates <- 0: if err != nil {
case <-n.quit: return err
return ErrTxNotifierExiting
} }
select { select {
@@ -972,10 +971,9 @@ func (n *TxNotifier) dispatchConfDetails(
// confirmations are left for the transaction/output script to // confirmations are left for the transaction/output script to
// be confirmed. // be confirmed.
numConfsLeft := confHeight - n.currentHeight numConfsLeft := confHeight - n.currentHeight
select { err := n.notifyNumConfsLeft(ntfn, numConfsLeft)
case ntfn.Event.Updates <- numConfsLeft: if err != nil {
case <-n.quit: return err
return ErrTxNotifierExiting
} }
} }
@@ -1740,10 +1738,9 @@ func (n *TxNotifier) NotifyHeight(height uint32) error {
continue continue
} }
select { err := n.notifyNumConfsLeft(ntfn, numConfsLeft)
case ntfn.Event.Updates <- numConfsLeft: if err != nil {
case <-n.quit: return err
return ErrTxNotifierExiting
} }
} }
} }
@@ -2081,3 +2078,15 @@ func (n *TxNotifier) TearDown() {
} }
} }
} }
// notifyNumConfsLeft sends the number of confirmations left to the
// notification subscriber through the Event.Updates channel.
func (n *TxNotifier) notifyNumConfsLeft(ntfn *ConfNtfn, num uint32) error {
select {
case ntfn.Event.Updates <- num:
case <-n.quit:
return ErrTxNotifierExiting
}
return nil
}