Skip to content

Commit 3126d86

Browse files
Add Bolt12Invoice wrapper for FFI bindings
Implement Bolt12Invoice struct in ffi/types.rs 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.
1 parent bf89d9f commit 3126d86

File tree

4 files changed

+391
-23
lines changed

4 files changed

+391
-23
lines changed

bindings/ldk_node.udl

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,31 @@ interface Refund {
774774
string? payer_note();
775775
};
776776

777+
interface Bolt12Invoice {
778+
[Throws=NodeError, Name=from_str]
779+
constructor([ByRef] string invoice_str);
780+
PaymentHash payment_hash();
781+
u64 amount_msats();
782+
OfferAmount? amount();
783+
PublicKey signing_pubkey();
784+
u64 created_at();
785+
u64? absolute_expiry_seconds();
786+
u64 relative_expiry();
787+
boolean is_expired();
788+
string? description();
789+
string? issuer();
790+
string? payer_note();
791+
sequence<u8>? metadata();
792+
u64? quantity();
793+
sequence<u8> signable_hash();
794+
PublicKey payer_signing_pubkey();
795+
PublicKey? issuer_signing_pubkey();
796+
sequence<u8> chain();
797+
sequence<sequence<u8>>? offer_chains();
798+
sequence<Address> fallback_addresses();
799+
sequence<u8> encode();
800+
};
801+
777802
[Custom]
778803
typedef string Txid;
779804

@@ -792,9 +817,6 @@ typedef string NodeId;
792817
[Custom]
793818
typedef string Address;
794819

795-
[Custom]
796-
typedef string Bolt12Invoice;
797-
798820
[Custom]
799821
typedef string OfferId;
800822

src/ffi/conversions.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
mod uniffi_impl {
99
use std::sync::Arc;
1010

11-
use lightning::offers::{offer::Offer as LdkOffer, refund::Refund as LdkRefund};
11+
use lightning::offers::{
12+
invoice::Bolt12Invoice as LdkBolt12Invoice, offer::Offer as LdkOffer,
13+
refund::Refund as LdkRefund,
14+
};
1215
use lightning_invoice::{
1316
Bolt11Invoice as LdkBolt11Invoice, Bolt11InvoiceDescription as LdkBolt11InvoiceDescription,
1417
};
1518

1619
use crate::error::Error;
17-
use crate::ffi::{Bolt11Invoice, Bolt11InvoiceDescription, Offer, Refund};
20+
use crate::ffi::{Bolt11Invoice, Bolt11InvoiceDescription, Bolt12Invoice, Offer, Refund};
1821

1922
pub trait UniffiType {
2023
type LdkType;
@@ -86,6 +89,20 @@ mod uniffi_impl {
8689
}
8790
}
8891

92+
impl UniffiType for Arc<Bolt12Invoice> {
93+
type LdkType = LdkBolt12Invoice;
94+
95+
fn from_ldk(ldk_value: Self::LdkType) -> Self {
96+
Arc::new(Bolt12Invoice { inner: ldk_value })
97+
}
98+
}
99+
100+
impl UniffiConversionType for Arc<Bolt12Invoice> {
101+
fn as_ldk(&self) -> Self::LdkType {
102+
self.inner.clone()
103+
}
104+
}
105+
89106
pub fn maybe_convert<T: UniffiConversionType>(value: &T) -> T::LdkType {
90107
value.as_ldk()
91108
}

0 commit comments

Comments
 (0)