aboutsummaryrefslogtreecommitdiffstats
path: root/routes/liquid/broadcast.js
diff options
context:
space:
mode:
Diffstat (limited to 'routes/liquid/broadcast.js')
-rw-r--r--routes/liquid/broadcast.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/routes/liquid/broadcast.js b/routes/liquid/broadcast.js
new file mode 100644
index 00000000..e3709597
--- /dev/null
+++ b/routes/liquid/broadcast.js
@@ -0,0 +1,36 @@
+module.exports = ah(async (req, res) => {
+ try {
+ const { user } = req;
+ let hash = await lq.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: "LBTC",
+ });
+
+ 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);
+ }
+ } catch (e) {
+ res.status(500).send(e.message);
+ }
+});