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