Skip to content

Conversation

@martinsaposnic
Copy link
Contributor

@martinsaposnic martinsaposnic commented Jan 27, 2026

Summary

  • Replaces payLnurl(), payBolt11(), and payBolt12Offer() with a single pay() method
  • Auto-detects destination type using bitcoin_payment_instructions crate
  • Reduces ~450 lines of duplicated payment logic

Supported destinations

  • BOLT12 offers (lno...)
  • LNURL (lnurl...)
  • Lightning addresses (user@domain)
  • Variable-amount BOLT11 invoices

Breaking change

BOLT11 invoices with pre-set amounts are no longer supported directly. The amount_msat parameter is always required. This enforces consistent amount handling across all payment types.

For BOLT11 invoices returned from LNURL/lightning address resolution, the code validates that any embedded amount matches the requested amount (protection against malicious services).

Test plan

  • Test payment to BOLT12 offer
  • Test payment to LNURL
  • Test payment to lightning address
  • Test payment to variable-amount BOLT11
  • Verify rejection of fixed-amount destinations

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9948d6762d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@martinsaposnic
Copy link
Contributor Author

@codex review

Replace payLnurl(), payBolt11(), and payBolt12Offer() with a single pay()
method that auto-detects the destination type using bitcoin_payment_instructions.

Supported destinations:
- BOLT12 offers (lno...)
- LNURL (lnurl...)
- Lightning addresses (user@domain)
- Zero-amount BOLT11 invoices

This is a breaking change: BOLT11 invoices with pre-set amounts are no longer
supported through this API. The design enforces that the caller always
specifies the amount, which:
- Simplifies the API surface (one method instead of three)
- Ensures consistent amount handling across all payment types
- Protects against malicious LNURL services returning wrong amounts

The amount_msat parameter is now always required.
@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Can't wait for the next one!

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".


// Validate BOLT11 invoice amount matches requested (protects against malicious LNURL services)
if let PaymentTarget::Bolt11(ref invoice, _) = payment_target {
if let Some(invoice_amount) = invoice.amount_milli_satoshis() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the LNURL returns no amount?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it returns no amount, we will skip validation and proceed with the requested amount. we always use send_using_amount with the requested amount so I think this is safe


/// Internal enum representing a resolved payment target with amount
enum PaymentTarget {
Bolt11(Bolt11Invoice, u64), // invoice + amount_msat
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Worth boxing the Bolt11Invoice too? Think it's also large enough to warrant it but not certain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants