Decode BOLT12 invoices in the DecodeInvoice API#215
Open
vincenzopalazzo wants to merge 1 commit into
Open
Conversation
The `DecodeInvoice` RPC previously accepted only a BOLT11 invoice
string. It now also accepts a hex-encoded BOLT12 invoice, and the
response carries a new `kind` field ("bolt11" or "bolt12") identifying
which was decoded.
Unlike offers and BOLT11 invoices, a BOLT12 invoice has no
human-readable string encoding -- it is exchanged as raw bytes over
onion messages -- so the input is expected to be hex-encoded, and LDK's
`Bolt12Invoice` is parsed via `TryFrom<Vec<u8>>` accordingly. Per the
minimal scope here, only `kind` is populated for a BOLT12 invoice; the
remaining fields continue to apply to BOLT11 invoices.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
I've assigned @benthecarman as a reviewer! |
Collaborator
|
Do we even have a way to get a bolt 12 invoice? |
Contributor
Author
Ah good point, and yes and no! With the new version of ldk-node we can perform a proof of payment (first version of it) with lightningdevkit/ldk-node#733 but people may want to use ldk to decode an bolt12 invoice that they are getting from somewhere else |
| fn decode_bolt12_invoice(invoice: &str) -> Option<DecodeInvoiceResponse> { | ||
| let bytes = Vec::<u8>::from_hex(invoice).ok()?; | ||
| Bolt12Invoice::try_from(bytes).ok()?; | ||
| Some(DecodeInvoiceResponse { kind: INVOICE_KIND_BOLT12.to_string(), ..Default::default() }) |
Collaborator
There was a problem hiding this comment.
whats the point of decoding the bolt12 invoice if we don't fill in any data? We just validate its a bolt12 invoice and thats it?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DecodeInvoicenow also decodes a hex-encoded BOLT12 invoice, not just a BOLT11 invoice string.DecodeInvoiceResponsegains akindfield ("bolt11"or"bolt12") identifying which invoice type was decoded.Bolt12Invoice::try_from. Per the intentionally minimal scope, onlykindis populated for a BOLT12 invoice; the remaining fields continue to apply to BOLT11 invoices.Test plan
cargo test— new unit tests indecode_invoice.rscover the BOLT12 invoice round-trip and rejection of unparseable / non-invoice inputtest_cli_decode_invoiceandtest_mcp_live_tool_callsassertkind == "bolt11"cargo check --all-features --all-targets,cargo fmt --all, clippy clean for the changed codeRUSTFLAGS="--cfg genproto" cargo build -p ldk-server-grpcAI tools: implemented with Claude Code (Claude Opus 4.7).