Skip to content

Commit e1173ea

Browse files
Add Offer wrapper for FFI bindings
Implement Offer struct in ffi/types.rs 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.
1 parent 17e4ed5 commit e1173ea

5 files changed

Lines changed: 348 additions & 25 deletions

File tree

bindings/ldk_node.udl

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,29 @@ interface Bolt11Invoice {
736736
PublicKey recover_payee_pub_key();
737737
};
738738

739+
[Enum]
740+
interface OfferAmount {
741+
Bitcoin(u64 amount_msats);
742+
Currency(string iso4217_code, u64 amount);
743+
};
744+
745+
interface Offer {
746+
[Throws=NodeError, Name=from_str]
747+
constructor([ByRef] string offer_str);
748+
OfferId id();
749+
boolean is_expired();
750+
string? description();
751+
string? issuer();
752+
OfferAmount? amount();
753+
boolean is_valid_quantity(u64 quantity);
754+
boolean expects_quantity();
755+
boolean supports_chain(Network chain);
756+
sequence<Network> chains();
757+
sequence<u8>? metadata();
758+
u64? absolute_expiry_seconds();
759+
PublicKey? issuer_signing_pubkey();
760+
};
761+
739762
[Custom]
740763
typedef string Txid;
741764

@@ -754,9 +777,6 @@ typedef string NodeId;
754777
[Custom]
755778
typedef string Address;
756779

757-
[Custom]
758-
typedef string Offer;
759-
760780
[Custom]
761781
typedef string Refund;
762782

src/ffi/conversions.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
mod uniffi_impl {
22
use std::sync::Arc;
33

4+
use lightning::offers::offer::Offer as LdkOffer;
45
use lightning_invoice::{
56
Bolt11Invoice as LdkBolt11Invoice, Bolt11InvoiceDescription as LdkBolt11InvoiceDescription,
67
};
78

89
use crate::error::Error;
9-
use crate::ffi::{Bolt11Invoice, Bolt11InvoiceDescription};
10+
use crate::ffi::{Bolt11Invoice, Bolt11InvoiceDescription, Offer};
1011

1112
pub trait UniffiType {
1213
type LdkType;
@@ -50,6 +51,20 @@ mod uniffi_impl {
5051
}
5152
}
5253

54+
impl UniffiType for Arc<Offer> {
55+
type LdkType = LdkOffer;
56+
57+
fn from_ldk(ldk_value: Self::LdkType) -> Self {
58+
Arc::new(Offer { inner: ldk_value })
59+
}
60+
}
61+
62+
impl UniffiConversionType for Arc<Offer> {
63+
fn as_ldk(&self) -> Self::LdkType {
64+
self.inner.clone()
65+
}
66+
}
67+
5368
pub fn maybe_convert<T: UniffiConversionType>(value: &T) -> T::LdkType {
5469
value.as_ldk()
5570
}

0 commit comments

Comments
 (0)