Skip to content

Commit

Permalink
fix(BlockStream): fix getting transactions for Merkle blocks
Browse files Browse the repository at this point in the history
Would previously always emit empty transaction arrays, even if there should be a matched transaction.
  • Loading branch information
mappum committed Jan 5, 2016
1 parent 02319b7 commit 174376e
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/blockStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,19 @@ BlockStream.prototype._getTransactions = function (txids, cb) {
hash: u.toHash(txid)
})
})
var message = this.peers.messages.GetData(inventory)
var transactions = []
var peer = this._getPeer()
var message = peer.messages.GetData(inventory)
var remaining = txids.length
var transactions = new Array(txids.length)
function onTx (res) {
var index = txids.indexOf(res.transaction.id)
if (index === -1) return
txids.splice(index, 1)
if (txids.length === 0) {
var txid = u.toHash(res.transaction.id)
for (var i = 0; i < txids.length; i++) {
if (txids[i].compare(txid) === 0) break
}
if (i === txids.length) return
transactions[i] = res.transaction
remaining--
if (remaining === 0) {
self.removeListener('tx', onTx)
cb(null, transactions)
}
Expand Down

0 comments on commit 174376e

Please sign in to comment.