aboutsummaryrefslogtreecommitdiffstats
path: root/routes/lightning/channel.js
diff options
context:
space:
mode:
Diffstat (limited to 'routes/lightning/channel.js')
-rw-r--r--routes/lightning/channel.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/routes/lightning/channel.js b/routes/lightning/channel.js
new file mode 100644
index 00000000..c5ab6a02
--- /dev/null
+++ b/routes/lightning/channel.js
@@ -0,0 +1,39 @@
+const axios = require("axios");
+
+module.exports = async (req, res) => {
+ const { params } = req.body;
+ const [pubkey, host] = params.uri.split("@");
+
+ l.info("connecting to peer", req.user.username, pubkey, host);
+ let result;
+ try {
+ result = await lna.connectPeer({
+ addr: { pubkey, host },
+ perm: true
+ });
+ } catch (e) {
+ if (!e.message.includes('already connected')) {
+ l.error("problem connecting to peer", e.message);
+ return res.status(500).send(e.message);
+ }
+ }
+
+ const { callback, k1 } = params;
+ let remoteid;
+ try {
+ remoteid = (await lna.getInfo({})).identity_pubkey;
+ } catch(e) {
+ l.error("problem getting lightning node info", e.message);
+ return res.status(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) {
+ l.error("problem sending channel request", e.message);
+ return res.status(500).send({ status: "ERROR", reason: e.message });
+ }
+};