Skip to content

Expose Bolt11Invoice type in bindings #522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alexanderwiederin
Copy link
Contributor

@alexanderwiederin alexanderwiederin commented Apr 14, 2025

First PR for #504.

This PR converts Bolt11Invoice from a string typedef to a full interface in the UDL, providing direct access to invoice properties across language bindings.

The scope has been limited to primitive properties for simplicity, with plans to extend the interface in future PRs.

Changes

  • Added Bolt11Invoice interface to UDL with core methods
  • Created wrapper struct in uniffi_types.rs with proper implementations
  • Updated payment code to work with the new wrapper type
  • Disabled doctests when uniffi feature is enabled to avoid conflicts with different Bolt11Invoice type representation
  • Added tests verifying property preservation during conversion

Benefits

  • Direct access to invoice properties from FFI languages
  • Consistent API across languages

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Apr 14, 2025

👋 Thanks for assigning @tnull as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@alexanderwiederin alexanderwiederin marked this pull request as ready for review April 14, 2025 09:27
@ldk-reviews-bot
Copy link

🔔 1st Reminder

Hey @valentinewallace! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@tnull tnull requested review from tnull and removed request for valentinewallace April 16, 2025 10:11
Copy link
Collaborator

@tnull tnull left a comment

Choose a reason for hiding this comment

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

Thanks for looking into this!

Approach looks already pretty good, some comments

@alexanderwiederin alexanderwiederin force-pushed the bolt11-invoice-uniffi branch 10 times, most recently from 6352b5d to 15153ef Compare April 22, 2025 17:01
@tnull
Copy link
Collaborator

tnull commented Apr 22, 2025

Please let me know when this is ready for another round of review!

@alexanderwiederin alexanderwiederin force-pushed the bolt11-invoice-uniffi branch 9 times, most recently from f2552f4 to e2f37df Compare April 24, 2025 21:27
@alexanderwiederin
Copy link
Contributor Author

@tnull, when you have time, could you take another look? I believe the check failures are not related.

@alexanderwiederin
Copy link
Contributor Author

alexanderwiederin commented Apr 25, 2025

The first commit won't build on its own because of the function signatures in the bindings. Should I squash to one single commit?

@alexanderwiederin alexanderwiederin requested a review from tnull April 28, 2025 13:30
Copy link
Collaborator

@tnull tnull left a comment

Choose a reason for hiding this comment

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

Excuse the delay here! Generally looks good, just two minor comments.

The first commit won't build on its own because of the function signatures in the bindings. Should I squash to one single commit?

Yes, if the commits don't build by themselves, it's preferable to squash, thank you!

type Bolt11Invoice = Arc<crate::uniffi_types::Bolt11Invoice>;

#[cfg(not(feature = "uniffi"))]
pub fn maybe_wrap_invoice(invoice: LdkBolt11Invoice) -> Bolt11Invoice {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think these helper methods should be pub?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Changed to pub(crate) because it's needed in unified_qr.rs.

Implement Bolt11Invoice struct in uniffi_types to provide a wrapper
around LDK's Bolt11Invoice for cross-language bindings.

Modified payment handling in bolt11.rs to:
- Support both native and FFI-compatible invoice types via type aliasing
- Add maybe_wrap_invoice and maybe_convert_invoice helper functions
- Implement conditional compilation for transparent FFI support
- Update all payment functions to handle wrapped invoice types

Integrated with unified_qr.rs to ensure consistent invoice handling
across the QR code generation and payment workflows.

Functionality tested with test coverage to ensure that data does not
change when wrapping/unwrapping.
@alexanderwiederin alexanderwiederin force-pushed the bolt11-invoice-uniffi branch from 422a81b to 0efa3f9 Compare May 1, 2025 14:55
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.

3 participants