aboutsummaryrefslogtreecommitdiffstats
path: root/routes/lightning/channel.js
blob: d5d5b7b238bf72f6ab669a32face83ad88a387df (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
import axios from "axios";
import ln from "$lib/ln";

export default async (req, res) => {
  const { params } = req.body;
  const [public_key, socket] = params.uri.split("@");

  l("connecting to peer", req.user.username, public_key, socket);
  let result;

  const { callback, k1 } = params;
  let remoteid;
  try {
      remoteid = (await ln.getinfo()).id;
  } catch (e) {
    err("problem getting lightning node info", e.message);
    return res.code(500).send(e.message);
  }

  let url = `${callback}?k1=${k1}&remoteid=${remoteid}&private=0`;

  try {
    let response = await axios.get(url);
    res.send(response.data);
  } catch (e) {
    err("problem sending channel request", e.message);
    return res.code(500).send({ status: "ERROR", reason: e.message });
  }
};