Skip to content

Commit 703e38b

Browse files
authored
Merge pull request #6 from synonymdev/feat/bolt11-msat
feat: support msat amounts in bolt11 generate endpoint
2 parents 115bd7b + d13e82f commit 703e38b

4 files changed

Lines changed: 28 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
- Preserve LNURL-pay invoice millisatoshi precision by creating invoices with LND `value_msat` instead of truncating callback amounts to sats
1717

1818
### Added
19+
- Support `amount_msat` query param in `/generate/bolt11` endpoint for sub-sat precision invoices
1920
- `bolt11` command in `bitcoin-cli` for creating regular Lightning invoices (supports `--msat` and `-m` memo)
2021
- LND hold invoice commands in `bitcoin-cli`: `holdinvoice`, `settleinvoice`, `cancelinvoice`
2122
- LND `getinfo` command in `bitcoin-cli` for connectivity debugging

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ A complete Docker-based development environment for Bitcoin and Lightning Networ
6363
- `/generate/pay` - Generate LNURL-pay
6464
- `/generate/channel` - Generate LNURL-channel
6565
- `/generate/auth` - Generate LNURL-auth
66+
- `/generate/bolt11` - Generate Bolt11 invoice (`?amount=` sats, `?amount_msat=` msats)
6667
- `/.well-known/lnurlp/:username` - Lightning Address
6768

6869
### VSS Server

lnurl-server/routes/generate.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,27 @@ const generateLnurlAuth = async (query) => {
185185
};
186186

187187
const generateBolt11 = async (query) => {
188-
const { amount } = query;
188+
const { amount, amount_msat } = query;
189189

190-
// Default to 0 (zero-amount invoice) if not specified
191-
const amountSats = amount ? parseInt(amount) : 0;
190+
let invoice;
191+
let amountDisplay;
192192

193-
if (isNaN(amountSats) || amountSats < 0) {
194-
throw new ValidationError('Invalid amount. Must be zero or a positive integer.');
193+
if (amount_msat) {
194+
const msat = parseInt(amount_msat);
195+
if (isNaN(msat) || msat < 0) {
196+
throw new ValidationError('Invalid amount_msat. Must be zero or a positive integer.');
197+
}
198+
invoice = await lndService.createInvoiceMsat(msat, '', 3600);
199+
amountDisplay = { msat };
200+
} else {
201+
const amountSats = amount ? parseInt(amount) : 0;
202+
if (isNaN(amountSats) || amountSats < 0) {
203+
throw new ValidationError('Invalid amount. Must be zero or a positive integer.');
204+
}
205+
invoice = await lndService.createInvoice(amountSats, '', 3600);
206+
amountDisplay = { sats: amountSats };
195207
}
196208

197-
// Create invoice with LND
198-
const invoice = await lndService.createInvoice(amountSats, '', 3600);
199209
const paymentRequest = invoice.payment_request;
200210

201211
const qrCode = await QRCode.toDataURL(paymentRequest, {
@@ -207,13 +217,13 @@ const generateBolt11 = async (query) => {
207217
}
208218
});
209219

210-
Logger.info('Bolt11 invoice generated', { amount: amountSats, paymentHash: invoice.r_hash });
220+
Logger.info('Bolt11 invoice generated', { amount: amountDisplay, paymentHash: invoice.r_hash });
211221

212222
return {
213223
bolt11: paymentRequest,
214224
qrCode,
215225
type: 'bolt11',
216-
amount: amountSats,
226+
amount: amountDisplay,
217227
paymentHash: invoice.r_hash
218228
};
219229
};

lnurl-server/templates.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,13 @@ const renderGeneratorPage = ({}) => {
681681
{
682682
method: 'GET',
683683
path: '/generate/bolt11?amount=2000',
684-
description: 'Generate Bolt11 with custom amount',
684+
description: 'Generate Bolt11 with amount in sats',
685+
clickable: true
686+
},
687+
{
688+
method: 'GET',
689+
path: '/generate/bolt11?amount_msat=222222',
690+
description: 'Generate Bolt11 with amount in msats',
685691
clickable: true
686692
}
687693
]

0 commit comments

Comments
 (0)