btcOperator v1.1.2a: bug fix

- Fixed: checkIfSameTx loop in comparing outputs using incorrect length
This commit is contained in:
sairajzero 2023-02-23 23:24:55 +05:30
parent 09e306d312
commit daec31c1ac

View File

@ -1,4 +1,4 @@
(function (EXPORTS) { //btcOperator v1.1.2 (function (EXPORTS) { //btcOperator v1.1.2a
/* BTC Crypto and API Operator */ /* BTC Crypto and API Operator */
const btcOperator = EXPORTS; const btcOperator = EXPORTS;
@ -703,12 +703,15 @@
btcOperator.checkIfSameTx = function (tx1, tx2) { btcOperator.checkIfSameTx = function (tx1, tx2) {
tx1 = deserializeTx(tx1); tx1 = deserializeTx(tx1);
tx2 = deserializeTx(tx2); tx2 = deserializeTx(tx2);
//compare input and output length
if (tx1.ins.length !== tx2.ins.length || tx1.outs.length !== tx2.outs.length) if (tx1.ins.length !== tx2.ins.length || tx1.outs.length !== tx2.outs.length)
return false; return false;
//compare inputs
for (let i = 0; i < tx1.ins.length; i++) for (let i = 0; i < tx1.ins.length; i++)
if (tx1.ins[i].outpoint.hash !== tx2.ins[i].outpoint.hash || tx1.ins[i].outpoint.index !== tx2.ins[i].outpoint.index) if (tx1.ins[i].outpoint.hash !== tx2.ins[i].outpoint.hash || tx1.ins[i].outpoint.index !== tx2.ins[i].outpoint.index)
return false; return false;
for (let i = 0; i < tx2.ins.length; i++) //compare outputs
for (let i = 0; i < tx1.outs.length; i++)
if (tx1.outs[i].value !== tx2.outs[i].value || Crypto.util.bytesToHex(tx1.outs[i].script.buffer) !== Crypto.util.bytesToHex(tx2.outs[i].script.buffer)) if (tx1.outs[i].value !== tx2.outs[i].value || Crypto.util.bytesToHex(tx1.outs[i].script.buffer) !== Crypto.util.bytesToHex(tx2.outs[i].script.buffer))
return false; return false;
return true; return true;