From 67386fd69f45610c1c02912828d24ce9d654282c Mon Sep 17 00:00:00 2001 From: sairajzero Date: Tue, 16 Aug 2022 20:39:49 +0530 Subject: [PATCH] Update btcOperator.js - Added checkIfSameTx(tx1, tx2): checks if the transactions is of the same --- btcOperator.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/btcOperator.js b/btcOperator.js index 591cd0a..aff13ee 100644 --- a/btcOperator.js +++ b/btcOperator.js @@ -1,4 +1,4 @@ -(function(EXPORTS) { //btcOperator v1.0.7c +(function(EXPORTS) { //btcOperator v1.0.8 /* BTC Crypto and API Operator */ const btcOperator = EXPORTS; @@ -519,6 +519,20 @@ return bool ? !(n.filter(x => x !== true).length) : n; } + btcOperator.checkIfSameTx = function(tx1, tx2) { + tx1 = deserializeTx(tx1); + tx2 = deserializeTx(tx2); + if (tx1.ins.length !== tx2.ins.length || tx1.outs.length !== tx2.outs.length) + return false; + 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) + return false; + for (let i = 0; i < tx2.ins.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)) + return false; + return true; + } + btcOperator.getTx = txid => new Promise((resolve, reject) => { fetch_api(`get_tx/BTC/${txid}`) .then(result => resolve(result.data))