diff options
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); +} |
