From ed3482fc15d3d8f8e8b3bceff7d473fd29601280 Mon Sep 17 00:00:00 2001 From: Zoltan Date: Wed, 22 Sep 2021 18:59:06 +0300 Subject: feat: added withdraw endpoint for bitcoin --- lib/feetx.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 lib/feetx.js (limited to 'lib') diff --git a/lib/feetx.js b/lib/feetx.js new file mode 100644 index 00000000..26ade9da --- /dev/null +++ b/lib/feetx.js @@ -0,0 +1,19 @@ +module.exports = async (txid) => { + const tx = await bc.getRawTransaction(txid); + const transaction = await bc.decodeRawTransaction(tx); + let valueIn = 0; + let valueOut = 0; + + const txVin = await Promise.all( + transaction.vin.map(async o => + await bc.decodeRawTransaction( + await bc.getRawTransaction(o.txid) + ) + ) + ); + + txVin.forEach(o => o.vout.forEach(o => valueIn += o.value)); + transaction.vout.forEach(o => valueOut += o.value); + + return toSats(valueIn - valueOut); +} -- cgit v1.2.3