diff options
| author | Zoltan <[email protected]> | 2021-09-22 18:59:06 +0300 |
|---|---|---|
| committer | Zoltan <[email protected]> | 2021-09-22 18:59:06 +0300 |
| commit | ed3482fc15d3d8f8e8b3bceff7d473fd29601280 (patch) | |
| tree | 0fc50475d353ddeddbb2ddbfe780abb4091c9b84 /lib | |
| parent | 3e61c801fc3ca9644304c88f86adf5aa297aeef4 (diff) | |
| download | coinos-server-ed3482fc15d3d8f8e8b3bceff7d473fd29601280.tar.gz coinos-server-ed3482fc15d3d8f8e8b3bceff7d473fd29601280.zip | |
feat: added withdraw endpoint for bitcoin
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/feetx.js | 19 |
1 files changed, 19 insertions, 0 deletions
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); +} |
