aboutsummaryrefslogtreecommitdiffstats
path: root/routes/liquid/broadcast.js
blob: e3709597b2f824719b9fa0c82d4cb52e8b9a86ed (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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);
  }
});