aboutsummaryrefslogtreecommitdiffstats
path: root/routes/lightning/channel.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-06-17 11:04:18 -0700
committerAdam Soltys <[email protected]>2020-06-17 11:04:18 -0700
commit139000e710e7cd5f76bc272fb8940305dc6475f1 (patch)
treeb5dd5964eb5d5e4fc02d122da8d995d2ae9947e3 /routes/lightning/channel.js
parented0da89c7d98195294ced6d71812183a04e24c76 (diff)
downloadcoinos-server-139000e710e7cd5f76bc272fb8940305dc6475f1.tar.gz
coinos-server-139000e710e7cd5f76bc272fb8940305dc6475f1.zip
lnurl channel flow
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 });
+ }
+};