diff options
| author | Adam Soltys <[email protected]> | 2020-08-11 09:18:26 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2020-08-11 09:18:26 -0700 |
| commit | 3980fec05509a060ac41f98b4dd126a13e4bc9cd (patch) | |
| tree | eacb00d0f3cc42a5216baa654b8e23b96a2e64d3 /routes/bitcoin/broadcast.js | |
| parent | f89b0ffde25292909bd398430e84e6c693084582 (diff) | |
| download | coinos-server-3980fec05509a060ac41f98b4dd126a13e4bc9cd.tar.gz coinos-server-3980fec05509a060ac41f98b4dd126a13e4bc9cd.zip | |
non-custodial sends
Diffstat (limited to 'routes/bitcoin/broadcast.js')
| -rw-r--r-- | routes/bitcoin/broadcast.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/routes/bitcoin/broadcast.js b/routes/bitcoin/broadcast.js new file mode 100644 index 00000000..c7b134ac --- /dev/null +++ b/routes/bitcoin/broadcast.js @@ -0,0 +1,35 @@ +module.exports = ah(async (req, res) => { + try { + const { user } = req; + let hash = await bc.sendRawTransaction(req.body.tx); + + if (user) { + let { account } = user; + let payment = await db.Payment.create({ + ...req.body.payment, + hash, + amount: -req.body.payment.amount, + tip: 0, + account_id: account.id, + user_id: user.id, + rate: app.get("rates")[user.currency], + currency: user.currency, + confirmed: true, + received: false, + network: "BTC", + }); + + 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); + res.send(payment); + } else { + res.send(result); + } + } catch (e) { + res.status(500).send(e.message); + } +}); |
