aboutsummaryrefslogtreecommitdiffstats
path: root/routes/lightning/invoice.js
blob: 94961b35ecaa08886f9ac119b347fb53c9241c2e (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
import config from "$config";
import { createInvoice } from "lightning";
import { err } from "$lib/logging";
import lnd from "$lib/lnd";
import ln from "$lib/ln";

export default async (req, res) => {
  let { amount, memo, tip } = req.body;
  if (!tip) tip = 0;
  let value = amount + tip;

  try {
    if (config.lna.clightning) {
      if (!memo) memo = "coinos";
      const invoice = await ln.invoice(
        value ? `${value}sat` : "any",
        new Date(),
        memo,
        360
      );
      res.send({ text: invoice.bolt11 });
    } else {
      const invoice = await createInvoice({
        lnd,
        tokens: value,
        description: memo
      });
      res.send({ text: invoice.request });
    }
  } catch (e) {
    console.log(e)
    err("problem creating invoice", e.message);
    res.code(500).send(e.message);
  }
};