Decode BOLT12 invoices in the DecodeInvoice API#215
Open
vincenzopalazzo wants to merge 2 commits into
Open
Conversation
|
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 |
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.
For a decoded BOLT12 invoice the fields that map onto
`DecodeInvoiceResponse` are populated: `destination` (signing pubkey),
`payment_hash`, `amount_msat`, `timestamp` (`created_at`), `expiry`
(`relative_expiry`), `description`, `fallback_address`, `features`, and
`is_expired`. BOLT11-only fields (`payment_secret`, `route_hints`,
`currency`, ...) are left empty.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
86d444d to
bcdb005
Compare
`DecodeInvoiceResponse` previously dropped the blinded payment paths of a decoded BOLT12 invoice. It now carries them in a new `paths` field, mirroring the `paths` already exposed for decoded BOLT12 offers. BOLT11 invoices leave the field empty, as they carry route hints instead. The blinded-path-to-proto conversion is extracted from `decode_offer` into a shared `blinded_path_to_proto` helper, so offer decoding (blinded message paths) and invoice decoding (blinded payment paths) build the same `BlindedPath` representation. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
benthecarman
requested changes
May 21, 2026
| pub is_expired: bool, | ||
| /// The kind of decoded invoice: "bolt11" or "bolt12". | ||
| #[prost(string, tag = "16")] | ||
| pub kind: ::prost::alloc::string::String, |
Collaborator
There was a problem hiding this comment.
Can we make this a proper enum
Collaborator
There was a problem hiding this comment.
can you add a e2e test
Collaborator
There was a problem hiding this comment.
can you add a mcp test
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).