Skip to content

Feature: Add Bolt12 Uniffi Type Wrappers #542

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 4 commits into
base: main
Choose a base branch
from

Conversation

alexanderwiederin
Copy link
Contributor

@alexanderwiederin alexanderwiederin commented May 19, 2025

Second PR for #504.

This PR adds full Offer-, Refund- and Bolt12Invoice- types for the FFI bindings.

Changes:

  • Type definitions in ldk_node.udl and uniffi_types.rs
  • Implementation of UniffiType trait to standardize conversions between LDK types and their FFI-compatible wrappers in uniffi_conversions.rs
  • Integration of wrapper types in payment handling methods in bolt12.rs and unified_qr.rs

Benefits:

  • Direct access to Offer, Refund and Bolt12Invoice properties from FFI languages
  • Consistent API across languages

Note:

Appreciate that this PR is big. Happy to break down into smaller parts if preferred.

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented May 19, 2025

I've assigned @valentinewallace 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.

match LdkBolt11InvoiceDescription::try_from(self) {
Ok(ldk_description) => ldk_description,
Err(e) => {
panic!("Failed to convert Bolt11InvoiceDescription to LDK type: {:?}", e)
Copy link
Contributor Author

@alexanderwiederin alexanderwiederin May 19, 2025

Choose a reason for hiding this comment

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

Not a fan of this myself. We could refactor the Bolt11InvoiceDescription to be a struct that holds the LdkType in an inner field (similar to what we did to other types) to make this conversion safer. Looking for advice on whether it's worth introducing a breaking change for this!

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

Modified payment handling in bolt12.rs to:
- Support both native and FFI-compatible types via type aliasing
- Implement conditional compilation for transparent FFI support
- Update payment functions to handle wrapped types

Added testing to verify that properties are preserved when wrapping/unwrapping between native and FFI types.
Implement Refund struct in uniffi_types to provide a wrapper around LDK's Refund for cross-language bindings.

Modified payment handling in bolt12.rs to:
- Support both native and FFI-compatible types via type aliasing
- Implement conditional compilation for transparent FFI support
- Update payment functions to handle wrapped types

Added testing to verify that properties are preserved when wrapping/unwrapping between native and FFI types.
Implement Bolt12Invoice struct in uniffi_types to provide a wrapper around LDK's Bolt12Invoice for cross-language bindings.

Modified payment handling in bolt12.rs to:
- Support both native and FFI-compatible types via type aliasing
- Implement conditional compilation for transparent FFI support
- Update payment functions to handle wrapped types

Added testing to verify that properties are preserved when wrapping/unwrapping between native and FFI types.
Implement UniffiType trait to standardize conversion between native LDK types and their FFI-compatible wrappers.

Enhanced uniffi_conversions module to:
- Add a generic trait-based approach to type conversions
- Support all wrapped Lightning types (Offer, Refund, Bolt11Invoice, Bolt12Invoice, Bolt11InvoiceDescription)
- Provide consistent maybe_convert and maybe_wrap utilities for conditional compilation
- Ensure correct type handling with compile-time feature flags

Designed for maintainability and consistency when adding new FFI type wrappers in the future.
@alexanderwiederin alexanderwiederin marked this pull request as ready for review May 20, 2025 21:21
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.

2 participants