Skip to content

Commit 2894d87

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 c245cf6 commit 2894d87

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
@@ -1,13 +1,16 @@
11
mod uniffi_impl {
22
use std::sync::Arc;
33

4-
use lightning::offers::{offer::Offer as LdkOffer, refund::Refund as LdkRefund};
4+
use lightning::offers::{
5+
invoice::Bolt12Invoice as LdkBolt12Invoice, offer::Offer as LdkOffer,
6+
refund::Refund as LdkRefund,
7+
};
58
use lightning_invoice::{
69
Bolt11Invoice as LdkBolt11Invoice, Bolt11InvoiceDescription as LdkBolt11InvoiceDescription,
710
};
811

912
use crate::error::Error;
10-
use crate::ffi::{Bolt11Invoice, Bolt11InvoiceDescription, Offer, Refund};
13+
use crate::ffi::{Bolt11Invoice, Bolt11InvoiceDescription, Bolt12Invoice, Offer, Refund};
1114

1215
pub trait UniffiType {
1316
type LdkType;
@@ -79,6 +82,20 @@ mod uniffi_impl {
7982
}
8083
}
8184

85+
impl UniffiType for Arc<Bolt12Invoice> {
86+
type LdkType = LdkBolt12Invoice;
87+
88+
fn from_ldk(ldk_value: Self::LdkType) -> Self {
89+
Arc::new(Bolt12Invoice { inner: ldk_value })
90+
}
91+
}
92+
93+
impl UniffiConversionType for Arc<Bolt12Invoice> {
94+
fn as_ldk(&self) -> Self::LdkType {
95+
self.inner.clone()
96+
}
97+
}
98+
8299
pub fn maybe_convert<T: UniffiConversionType>(value: &T) -> T::LdkType {
83100
value.as_ldk()
84101
}

0 commit comments

Comments
 (0)