Update btcOperator.js

This commit is contained in:
sairajzero 2022-11-18 17:51:14 +05:30
parent 64527259d9
commit 02bb160b5f

View File

@ -1,4 +1,4 @@
(function (EXPORTS) { //btcOperator v1.0.13a (function (EXPORTS) { //btcOperator v1.0.13c
/* BTC Crypto and API Operator */ /* BTC Crypto and API Operator */
const btcOperator = EXPORTS; const btcOperator = EXPORTS;
@ -328,7 +328,7 @@
let total_amount = parseFloat(amounts.reduce((t, a) => t + a, 0).toFixed(8)); let total_amount = parseFloat(amounts.reduce((t, a) => t + a, 0).toFixed(8));
const tx = coinjs.transaction(); const tx = coinjs.transaction();
let output_size = addOutputs(tx, receivers, amounts, change_address); let output_size = addOutputs(tx, receivers, amounts, change_address);
addInputs(tx, senders, redeemScripts, total_amount, fee, output_size).then(result => { addInputs(tx, senders, redeemScripts, total_amount, fee, output_size, fee_from_receiver).then(result => {
if (result.change_amount > 0) //add change amount if any if (result.change_amount > 0) //add change amount if any
tx.outs[tx.outs.length - 1].value = parseInt(result.change_amount * SATOSHI_IN_BTC); //values are in satoshi tx.outs[tx.outs.length - 1].value = parseInt(result.change_amount * SATOSHI_IN_BTC); //values are in satoshi
if (fee_from_receiver) { //deduce fee from receivers if fee_from_receiver if (fee_from_receiver) { //deduce fee from receivers if fee_from_receiver
@ -344,10 +344,11 @@
} }
if (fee_remaining > 0) if (fee_remaining > 0)
return reject("Send amount is less than fee"); return reject("Send amount is less than fee");
} }
tx.outs = tx.outs.filter(o => o.value !== 0); //remove all output with value 0 tx.outs = tx.outs.filter(o => o.value != 0); //remove all output with value 0
result.output_size = output_size; result.output_size = output_size;
result.output_amount = total_amount; result.output_amount = total_amount - (fee_from_receiver ? result.fee : 0);
result.total_size = BASE_TX_SIZE + output_size + result.input_size; result.total_size = BASE_TX_SIZE + output_size + result.input_size;
result.transaction = tx; result.transaction = tx;
resolve(result); resolve(result);