Skip to content

Commit 55d5fd5

Browse files
committed
tracker: read all channels simultaneously
1 parent 78bfe73 commit 55d5fd5

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

tracker/tracker.go

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -500,23 +500,28 @@ func (t *Tracker) fastScanTransactions(blockhash string, blockHeight int64, tran
500500
var spentTxids []string
501501
var spentVouts []int
502502

503-
log.Info().
504-
Msg("Receiving losses")
505-
for loss := range lossCh {
506-
losses = append(losses, loss)
507-
}
508-
509-
log.Info().
510-
Msg("Receiving transactions")
511-
for tx := range txCh {
512-
txs = append(txs, tx)
513-
}
514-
515-
log.Info().
516-
Msg("Receiving spent txids")
517-
for spent := range spentTxidVoutCh {
518-
spentTxids = append(spentTxids, spent[0].(string))
519-
spentVouts = append(spentVouts, spent[1].(int))
503+
for lossCh != nil || txCh != nil || spentTxidVoutCh != nil {
504+
select {
505+
case loss, ok := <-lossCh:
506+
if !ok {
507+
lossCh = nil
508+
continue
509+
}
510+
losses = append(losses, loss)
511+
case tx, ok := <-txCh:
512+
if !ok {
513+
txCh = nil
514+
continue
515+
}
516+
txs = append(txs, tx)
517+
case spent, ok := <-spentTxidVoutCh:
518+
if !ok {
519+
spentTxidVoutCh = nil
520+
continue
521+
}
522+
spentTxids = append(spentTxids, spent[0].(string))
523+
spentVouts = append(spentVouts, spent[1].(int))
524+
}
520525
}
521526

522527
return losses, txs, spentTxids, spentVouts

0 commit comments

Comments
 (0)