Skip to content

Commit 174376e

Browse files
committed
fix(BlockStream): fix getting transactions for Merkle blocks
Would previously always emit empty transaction arrays, even if there should be a matched transaction.
1 parent 02319b7 commit 174376e

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

lib/blockStream.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,19 @@ BlockStream.prototype._getTransactions = function (txids, cb) {
135135
hash: u.toHash(txid)
136136
})
137137
})
138-
var message = this.peers.messages.GetData(inventory)
139-
var transactions = []
138+
var peer = this._getPeer()
139+
var message = peer.messages.GetData(inventory)
140+
var remaining = txids.length
141+
var transactions = new Array(txids.length)
140142
function onTx (res) {
141-
var index = txids.indexOf(res.transaction.id)
142-
if (index === -1) return
143-
txids.splice(index, 1)
144-
if (txids.length === 0) {
143+
var txid = u.toHash(res.transaction.id)
144+
for (var i = 0; i < txids.length; i++) {
145+
if (txids[i].compare(txid) === 0) break
146+
}
147+
if (i === txids.length) return
148+
transactions[i] = res.transaction
149+
remaining--
150+
if (remaining === 0) {
145151
self.removeListener('tx', onTx)
146152
cb(null, transactions)
147153
}

0 commit comments

Comments
 (0)