Skip to content

Commit 7695880

Browse files
committed
chainntnfs: add new method notifyNumConfsLeft
So it's easier to handle the following commit where we start skipping duplicate notifications.
1 parent 0c3b2b5 commit 7695880

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

chainntnfs/txnotifier.go

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -942,10 +942,9 @@ func (n *TxNotifier) dispatchConfDetails(
942942
// We'll send a 0 value to the Updates channel,
943943
// indicating that the transaction/output script has already
944944
// been confirmed.
945-
select {
946-
case ntfn.Event.Updates <- 0:
947-
case <-n.quit:
948-
return ErrTxNotifierExiting
945+
err := n.notifyNumConfsLeft(ntfn, 0)
946+
if err != nil {
947+
return err
949948
}
950949

951950
select {
@@ -972,10 +971,9 @@ func (n *TxNotifier) dispatchConfDetails(
972971
// confirmations are left for the transaction/output script to
973972
// be confirmed.
974973
numConfsLeft := confHeight - n.currentHeight
975-
select {
976-
case ntfn.Event.Updates <- numConfsLeft:
977-
case <-n.quit:
978-
return ErrTxNotifierExiting
974+
err := n.notifyNumConfsLeft(ntfn, numConfsLeft)
975+
if err != nil {
976+
return err
979977
}
980978
}
981979

@@ -1740,10 +1738,9 @@ func (n *TxNotifier) NotifyHeight(height uint32) error {
17401738
continue
17411739
}
17421740

1743-
select {
1744-
case ntfn.Event.Updates <- numConfsLeft:
1745-
case <-n.quit:
1746-
return ErrTxNotifierExiting
1741+
err := n.notifyNumConfsLeft(ntfn, numConfsLeft)
1742+
if err != nil {
1743+
return err
17471744
}
17481745
}
17491746
}
@@ -2081,3 +2078,15 @@ func (n *TxNotifier) TearDown() {
20812078
}
20822079
}
20832080
}
2081+
2082+
// notifyNumConfsLeft sends the number of confirmations left to the
2083+
// notification subscriber through the Event.Updates channel.
2084+
func (n *TxNotifier) notifyNumConfsLeft(ntfn *ConfNtfn, num uint32) error {
2085+
select {
2086+
case ntfn.Event.Updates <- num:
2087+
case <-n.quit:
2088+
return ErrTxNotifierExiting
2089+
}
2090+
2091+
return nil
2092+
}

0 commit comments

Comments
 (0)