diff options
Diffstat (limited to 'routes/bitcoin')
| -rw-r--r-- | routes/bitcoin/broadcast.js | 3 | ||||
| -rw-r--r-- | routes/bitcoin/receive.js | 22 |
2 files changed, 21 insertions, 4 deletions
diff --git a/routes/bitcoin/broadcast.js b/routes/bitcoin/broadcast.js index c7b134ac..4324e0d9 100644 --- a/routes/bitcoin/broadcast.js +++ b/routes/bitcoin/broadcast.js @@ -19,12 +19,13 @@ module.exports = ah(async (req, res) => { network: "BTC", }); - account.balance -= payment.amount + payment.fee; + account.balance += payment.amount - payment.fee; await account.save(); payment = payment.get({ plain: true }); payment.account = account.get({ plain: true }); emit(user.username, "payment", payment); + emit(user.username, "account", payment.account); res.send(payment); } else { res.send(result); diff --git a/routes/bitcoin/receive.js b/routes/bitcoin/receive.js index ec120605..987f5079 100644 --- a/routes/bitcoin/receive.js +++ b/routes/bitcoin/receive.js @@ -1,6 +1,7 @@ const reverse = require("buffer-reverse"); const zmq = require("zeromq"); const { Op } = require("sequelize"); +const { fromBase58 } = require("bip32"); const bitcoin = require("bitcoinjs-lib"); @@ -35,7 +36,10 @@ zmqRawTx.on("message", async (topic, message, sequence) => { return; } - if (Object.keys(addresses).includes(address) && !change.includes(address)) { + if ( + Object.keys(addresses).includes(address) && + !change.includes(address) + ) { payments.push(hash); let user = await db.User.findOne({ @@ -55,7 +59,7 @@ zmqRawTx.on("message", async (topic, message, sequence) => { const currency = invoice ? invoice.currency : user.currency; const rate = invoice ? invoice.rate : app.get("rates")[user.currency]; const tip = invoice ? invoice.tip : 0; - const memo = invoice ? invoice.memo : ''; + const memo = invoice ? invoice.memo : ""; let confirmed = false; @@ -66,7 +70,19 @@ zmqRawTx.on("message", async (topic, message, sequence) => { }, }); - let account = accounts.find(a => a.address === address); + let account = accounts.find(({ index, pubkey }) => { + const { payments } = bitcoin; + index && + pubkey && + address === + payments.p2wpkh({ + pubkey: fromBase58(pubkey, network).derivePath( + `${index}` + ).publicKey, + network, + }).address; + }); + if (!account) account = accounts[0]; account.pending += value; |
