diff --git a/lib/net/bip152.js b/lib/net/bip152.js index 0de0d78a..17825183 100644 --- a/lib/net/bip152.js +++ b/lib/net/bip152.js @@ -50,7 +50,7 @@ function CompactBlock(options) { this.ptx = []; this.available = []; - this.idMap = {}; + this.idMap = new Map(); this.count = 0; this.sipKey = null; this.totalTX = 0; @@ -322,7 +322,7 @@ CompactBlock.prototype.fillMempool = function fillMempool(witness, mempool) { hash = tx.witnessHash(); id = this.sid(hash); - index = this.idMap[id]; + index = this.idMap.get(id); if (index == null) continue; @@ -445,10 +445,10 @@ CompactBlock.prototype.init = function init() { id = this.ids[i]; // Fails on siphash collision - if (this.idMap[id]) + if (this.idMap.has(id)) return false; - this.idMap[id] = i + offset; + this.idMap.set(id, i + offset); // We're supposed to fail here if there's // more than 12 hash collisions, but we diff --git a/lib/primitives/merkleblock.js b/lib/primitives/merkleblock.js index 77ec81f2..8bf09227 100644 --- a/lib/primitives/merkleblock.js +++ b/lib/primitives/merkleblock.js @@ -106,7 +106,7 @@ MerkleBlock.prototype.refresh = function refresh(all) { MerkleBlock.prototype.addTX = function addTX(tx) { let tree = this.getTree(); let hash = tx.hash('hex'); - let index = tree.map[hash]; + let index = tree.map.get(hash); this.txs.push(tx); @@ -131,7 +131,7 @@ MerkleBlock.prototype.hasTX = function hasTX(hash) { MerkleBlock.prototype.indexOf = function indexOf(hash) { let tree = this.getTree(); - let index = tree.map[hash]; + let index = tree.map.get(hash); if (index == null) return -1; @@ -140,8 +140,7 @@ MerkleBlock.prototype.indexOf = function indexOf(hash) { }; /** - * Verify the partial merkletree. Push leaves onto - * {@link MerkleBlock#tx} and into {@link MerkleBlock#map}. + * Verify the partial merkletree. * @private * @returns {Boolean} */ @@ -152,8 +151,7 @@ MerkleBlock.prototype.verifyBody = function verifyBody() { }; /** - * Verify the partial merkletree. Push leaves onto - * {@link MerkleBlock#tx} and into {@link MerkleBlock#map}. + * Verify the partial merkletree. * @private * @returns {Array} [valid, reason, score] */ @@ -196,7 +194,7 @@ MerkleBlock.prototype.extractTree = function extractTree() { let hashUsed = 0; let matches = []; let indexes = []; - let map = {}; + let map = new Map(); let failed = false; let hashes = this.hashes; let flags = this.flags; @@ -232,7 +230,7 @@ MerkleBlock.prototype.extractTree = function extractTree() { let txid = hash.toString('hex'); matches.push(hash); indexes.push(pos); - map[txid] = pos; + map.set(txid, pos); } return hash; @@ -679,7 +677,7 @@ function PartialTree(root, matches, indexes, map) { this.root = root ? root.toString('hex') : encoding.NULL_HASH; this.matches = matches || []; this.indexes = indexes || []; - this.map = map || {}; + this.map = map || new Map(); } /*