aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-06-14 12:38:29 -0700
committerAdam Soltys <[email protected]>2026-06-17 07:47:49 -0700
commit0987582546363935c5a388a9accb9b245c11a7c7 (patch)
tree8cfa81107fab77a01bb7d4cabcc6d6865f1166bb /lib
parentaf8e395dd9ed010fce0e3b92593d5ea6d39dc65a (diff)
downloadcoinos-server-0987582546363935c5a388a9accb9b245c11a7c7.tar.gz
coinos-server-0987582546363935c5a388a9accb9b245c11a7c7.zip
nwc: pay_invoice honors request amount for amountless bolt11
Port of master ce9616f6. pay_invoice derived the amount solely from the decoded invoice, so an amountless bolt11 yielded amount = round(undefined/ 1000) = NaN and sendLightning rejected it with "Invalid amount". NIP-47 lets the client specify the amount (msat) in the request; fall back to it when the invoice carries none, with a clear error if still missing. Fixes #83. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Diffstat (limited to 'lib')
-rw-r--r--lib/nwc.ts16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/nwc.ts b/lib/nwc.ts
index 662d2fa8..49e2cfc2 100644
--- a/lib/nwc.ts
+++ b/lib/nwc.ts
@@ -161,10 +161,22 @@ export default () => {
const handle = (method, params, ev, app, user) =>
({
async pay_invoice() {
- const { invoice: pr, metadata } = params;
+ const { invoice: pr, metadata, amount: reqAmountMsat } = params;
const { amount_msat, payee } = await ln.decode(pr);
const { id } = await ln.getinfo();
- const amount = Math.round(amount_msat / 1000);
+ // For an amountless bolt11, the invoice carries no amount — NIP-47 lets the
+ // client specify it in the request's `amount` field (msat). Fall back to
+ // that so amountless invoices aren't rejected with "Invalid amount"
+ // (issue #83). Invoice amount takes precedence when present.
+ const amountMsat = amount_msat || reqAmountMsat;
+ if (!amountMsat) {
+ return error({
+ code: "OTHER",
+ message:
+ "Amountless invoice requires an amount; specify amount (msat) in the request",
+ });
+ }
+ const amount = Math.round(amountMsat / 1000);
const { max_amount, max_fee, budget_renewal, pubkey, created } = app;
const periods = {