You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In getMerkleProof, it builds the merkle tree twice (once inside merkle.createRoot and once inside merkle.createBranch. I think this could be simplified to where this only happens once.
async getMerkleProof(txid, height) {
const block = await super.execute('getblockbyheight', [height]);
let index = -1;
const txs = [];
for (const [i, tx] of Object.entries(block.tx)) {
if (tx === txid) { index = i >>> 0; } // cast to uint from string
txs.push(Buffer.from(tx, 'hex').reverse());
}
assert(index >= 0, 'Transaction not in block.');
const [root] = merkle.createRoot(hash256, txs.slice());
assert.bufferEqual(Buffer.from(block.merkleroot, 'hex').reverse(), root);
const branch = merkle.createBranch(hash256, index, txs.slice());
const proof = [];
for (const hash of branch) { proof.push(hash.toString('hex')); }
return [proof, index];
}
In
getMerkleProof, it builds the merkle tree twice (once insidemerkle.createRootand once insidemerkle.createBranch. I think this could be simplified to where this only happens once.