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

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

  try {
    if (!memo) memo = "coinos";
    const invoice = await ln.invoice(
      value ? `${value}sat` : "ancpy",
      v4(),
      memo,
      360
    );
    res.send({ text: invoice.bolt11 });
  } catch (e) {
    console.log(e);
    err("problem creating invoice", e.message);
    res.code(500).send(e.message);
  }
};