mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-06-06 18:31:00 +00:00
fix responses according to lud21
This commit is contained in:
parent
9588161abc
commit
e81aeb4ead
@ -17,13 +17,13 @@ export default async function handler(req, res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!foundAddress) {
|
if (!foundAddress) {
|
||||||
res.status(404).json({ error: 'Lightning address not found' });
|
res.status(200).json({
|
||||||
|
status: "ERROR",
|
||||||
|
reason: "Lightning address not found"
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("FOUND ADDRESS", foundAddress);
|
|
||||||
console.log("SLUG", slug);
|
|
||||||
|
|
||||||
// Call LND to check payment status
|
// Call LND to check payment status
|
||||||
const response = await axios.get(
|
const response = await axios.get(
|
||||||
`https://${foundAddress.lndHost}:${foundAddress.lndPort}/v1/invoice/${slug}`,
|
`https://${foundAddress.lndHost}:${foundAddress.lndPort}/v1/invoice/${slug}`,
|
||||||
@ -34,14 +34,23 @@ export default async function handler(req, res) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// According to LNURL-pay spec, we should return { status: "OK" } if paid
|
// According to LUD-21 spec, we should return:
|
||||||
// or { status: "ERROR", reason: "error message" } if not paid or error
|
// - { status: "OK", settled: true, preimage: "123456...", pr: "lnbc10..." }
|
||||||
if (response.data.state === 'SETTLED') {
|
// - { status: "OK", settled: false, preimage: null, pr: "lnbc10..." }
|
||||||
res.status(200).json({ status: "OK" });
|
// - { status: "ERROR", reason: "error message" }
|
||||||
|
if (response.data) {
|
||||||
|
res.status(200).json({
|
||||||
|
status: "OK",
|
||||||
|
settled: response.data.state === "SETTLED",
|
||||||
|
preimage: response.data.r_preimage ?
|
||||||
|
Buffer.from(response.data.r_preimage, 'base64').toString('hex') :
|
||||||
|
null,
|
||||||
|
pr: response.data.payment_request
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
status: "ERROR",
|
status: "ERROR",
|
||||||
reason: "Invoice not paid"
|
reason: "Invoice not found"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user