aboutsummaryrefslogtreecommitdiffstats
path: root/routes/bitcoin/receive.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-04-30 00:05:37 -0400
committerAdam Soltys <[email protected]>2020-04-30 00:05:37 -0400
commitc5545d98aed3eaac4f88cdc3a9f3d7d9e7204134 (patch)
treea14213bcad22d9a0f331b6073e15308fe015177c /routes/bitcoin/receive.js
parent53b76aa961bdd4b8daa6cb8a8f002373546cd7f7 (diff)
parentfa84d5a65844602c7e97e9bf0e5a51befdebaf53 (diff)
downloadcoinos-server-c5545d98aed3eaac4f88cdc3a9f3d7d9e7204134.tar.gz
coinos-server-c5545d98aed3eaac4f88cdc3a9f3d7d9e7204134.zip
Merge branch 'master' of https://github.com/asoltys/coinos-server
Diffstat (limited to 'routes/bitcoin/receive.js')
-rw-r--r--routes/bitcoin/receive.js12
1 files changed, 12 insertions, 0 deletions
diff --git a/routes/bitcoin/receive.js b/routes/bitcoin/receive.js
index deded625..1aae1467 100644
--- a/routes/bitcoin/receive.js
+++ b/routes/bitcoin/receive.js
@@ -73,10 +73,22 @@ zmqRawTx.on("message", async (topic, message, sequence) => {
addresses[user.address] = user.username;
+ let totalOutputs = tx.outs.reduce((a, b) => a + b.value, 0);
+ let totalInputs = 0;
+ for (let i = 0; i < tx.ins.length; i++) {
+ let { hash, index } = tx.ins[i];
+ hash = reverse(hash).toString("hex");
+ let hex = await bc.getRawTransaction(hash.toString('hex'));
+ let inputTx = bitcoin.Transaction.fromHex(hex);
+ totalInputs += inputTx.outs[index].value;
+ }
+ let fee = totalInputs - totalOutputs;
+
let payment = await db.Payment.create({
account_id: account.id,
user_id: user.id,
hash,
+ fee,
amount: value - tip,
currency,
rate,