bip152/merkleblock: use Map objects.
This commit is contained in:
parent
a071a58380
commit
15d0b88308
@ -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
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user