aboutsummaryrefslogtreecommitdiffstats
path: root/routes/lightning
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-09-20 22:48:01 -0700
committerAdam Soltys <[email protected]>2022-09-20 22:48:01 -0700
commitb53875cf6bdf47c359139aa846c6597fa3627c87 (patch)
treed4e7c71c5be97903a43e0e25f816b2a4b9fde0a5 /routes/lightning
parent2b552fdd6eca883ee24d2772e1de24f4bab70202 (diff)
downloadcoinos-server-b53875cf6bdf47c359139aa846c6597fa3627c87.tar.gz
coinos-server-b53875cf6bdf47c359139aa846c6597fa3627c87.zip
clightning support
Diffstat (limited to 'routes/lightning')
-rw-r--r--routes/lightning/channel.js7
-rw-r--r--routes/lightning/channelRequest.js3
-rw-r--r--routes/lightning/invoice.js3
-rw-r--r--routes/lightning/receive.js46
4 files changed, 35 insertions, 24 deletions
diff --git a/routes/lightning/channel.js b/routes/lightning/channel.js
index 1c7bab10..107896f4 100644
--- a/routes/lightning/channel.js
+++ b/routes/lightning/channel.js
@@ -1,6 +1,7 @@
import axios from "axios";
import { addPeer, getIdentity } from "lightning";
import lnd from "$lib/lnd";
+import ln from "$lib/ln";
export default async (req, res) => {
const { params } = req.body;
@@ -24,7 +25,11 @@ export default async (req, res) => {
const { callback, k1 } = params;
let remoteid;
try {
- remoteid = (await getIdentity({ lnd })).public_key;
+ if (config.lna.clightning) {
+ remoteid = (await ln.getinfo()).id;
+ } else {
+ remoteid = (await getIdentity({ lnd })).public_key;
+ }
} catch (e) {
err("problem getting lightning node info", e.message);
return res.code(500).send(e.message);
diff --git a/routes/lightning/channelRequest.js b/routes/lightning/channelRequest.js
index 530fad48..74e4cbba 100644
--- a/routes/lightning/channelRequest.js
+++ b/routes/lightning/channelRequest.js
@@ -1,6 +1,7 @@
import { lnurlServer } from "$routes/lnurl";
+import { err } from "$lib/logging";
-export default async (req, res) => {
+export const channelRequest = async (req, res) => {
let { localAmt, pushAmt } = req.body;
pushAmt = 0;
diff --git a/routes/lightning/invoice.js b/routes/lightning/invoice.js
index 94aac768..94961b35 100644
--- a/routes/lightning/invoice.js
+++ b/routes/lightning/invoice.js
@@ -2,6 +2,7 @@ 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;
@@ -11,7 +12,7 @@ export default async (req, res) => {
try {
if (config.lna.clightning) {
if (!memo) memo = "coinos";
- const invoice = await lna.invoice(
+ const invoice = await ln.invoice(
value ? `${value}sat` : "any",
new Date(),
memo,
diff --git a/routes/lightning/receive.js b/routes/lightning/receive.js
index 56714da7..084161b5 100644
--- a/routes/lightning/receive.js
+++ b/routes/lightning/receive.js
@@ -8,11 +8,11 @@ import { computeConversionFee } from "./conversionFee";
import { sendLiquid } from "$routes/liquid/send";
import { subscribeToInvoices } from "lightning";
import lnd from "$lib/lnd";
+import ln from "$lib/ln";
import { l, err, warn } from "$lib/logging";
const handlePayment = async msg => {
try {
- console.log(msg)
l("incoming lightning payment", msg.received);
if (!msg.secret) return;
@@ -134,29 +134,33 @@ const handlePayment = async msg => {
if (config.lna.clightning) {
const poll = async ln => {
- const wait = async i => {
- const {
- bolt11: payment_request,
- pay_index,
- status,
- msatoshi_received,
- payment_preimage: r_preimage
- } = await ln.waitanyinvoice(i);
+ try {
+ const wait = async i => {
+ const {
+ bolt11: request,
+ pay_index,
+ status,
+ msatoshi_received,
+ payment_preimage: secret
+ } = await ln.waitanyinvoice(i);
+ console.log("um");
- let settled = status === "paid";
- let amt_paid_sat = parseInt(msatoshi_received / 1000);
+ let settled = status === "paid";
+ let received = parseInt(msatoshi_received / 1000);
- await handlePayment({
- payment_request,
- settled,
- amt_paid_sat,
- r_preimage
- });
- wait(pay_index);
- };
+ await handlePayment({
+ request,
+ received,
+ secret
+ });
+ await wait(pay_index);
+ };
- const { invoices } = await ln.listinvoices();
- wait(Math.max(...invoices.map(i => i.pay_index).filter(n => n)));
+ const { invoices } = await ln.listinvoices();
+ await wait(Math.max(...invoices.map(i => i.pay_index).filter(n => n)));
+ } catch (e) {
+ err("problem waiting for c-lightning invoice", e.message);
+ }
};
poll(ln);