aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--index.js1
-rw-r--r--lib/payments.js5
-rw-r--r--routes/lnurl.js19
3 files changed, 20 insertions, 5 deletions
diff --git a/index.js b/index.js
index 9972baf5..c5190c7d 100644
--- a/index.js
+++ b/index.js
@@ -68,6 +68,7 @@ app.post("/replace", auth, payments.replace);
app.get("/encode", lnurl.encode);
app.get("/decode", lnurl.decode);
+app.get("/lnurl/verify/:id", lnurl.verify);
app.get("/lnurlp/:username", lnurl.lnurlp);
app.get("/lnurl/:id", lnurl.lnurl);
diff --git a/lib/payments.js b/lib/payments.js
index 56d048c8..d3250778 100644
--- a/lib/payments.js
+++ b/lib/payments.js
@@ -175,7 +175,10 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => {
};
if ([types.bitcoin, types.liquid].includes(type)) inv.pending += amount;
- else inv.received += amount;
+ else {
+ inv.received += amount;
+ inv.preimage = ref;
+ }
let balanceKey = "balance";
if ([types.bitcoin, types.liquid].includes(type)) {
diff --git a/routes/lnurl.js b/routes/lnurl.js
index c092d6fe..03dcc19a 100644
--- a/routes/lnurl.js
+++ b/routes/lnurl.js
@@ -1,6 +1,6 @@
import migrate from "$lib/migrate";
import { g, s } from "$lib/db";
-import { l, warn } from "$lib/logging";
+import { l, err, warn } from "$lib/logging";
import { bail, getUser, fail } from "$lib/utils";
import { v4 } from "uuid";
import got from "got";
@@ -92,7 +92,7 @@ export default {
let memo = `Paying ${username}@${host}`;
let metadata = JSON.stringify([
["text/plain", memo],
- ["text/identifier", `${username}@${host}`]
+ ["text/identifier", `${username}@${host}`],
]);
if (nostr) {
@@ -106,7 +106,7 @@ export default {
}
}
- let { text: pr } = await generate({
+ let { id: iid, text: pr } = await generate({
invoice: {
amount: Math.round(amount / 1000),
memo: metadata,
@@ -115,9 +115,20 @@ export default {
user,
});
- res.send({ pr, routes: [] });
+ res.send({ pr, routes: [], verify: `${URL}/api/lnurl/verify/${iid}` });
} catch (e) {
bail(res, e.message);
}
},
+
+ async verify({ params: { id } }, res) {
+ let inv = await g(`invoice:${id}`);
+
+ if (!inv) return res.send({ status: "ERROR", reason: "Not found" });
+
+ let { received, amount, preimage } = inv;
+ let settled = received >= amount;
+
+ res.send({ status: "OK", settled, preimage });
+ },
};