Skip to content

Commit 3990ea0

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 abd4bb4 commit 3990ea0

File tree

5 files changed

+353
-25
lines changed

5 files changed

+353
-25
lines changed

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
@@ -8,12 +8,13 @@
88
mod uniffi_impl {
99
use std::sync::Arc;
1010

11+
use lightning::offers::offer::Offer as LdkOffer;
1112
use lightning_invoice::{
1213
Bolt11Invoice as LdkBolt11Invoice, Bolt11InvoiceDescription as LdkBolt11InvoiceDescription,
1314
};
1415

1516
use crate::error::Error;
16-
use crate::ffi::{Bolt11Invoice, Bolt11InvoiceDescription};
17+
use crate::ffi::{Bolt11Invoice, Bolt11InvoiceDescription, Offer};
1718

1819
pub trait UniffiType {
1920
type LdkType;
@@ -57,6 +58,20 @@ mod uniffi_impl {
5758
}
5859
}
5960

61+
impl UniffiType for Arc<Offer> {
62+
type LdkType = LdkOffer;
63+
64+
fn from_ldk(ldk_value: Self::LdkType) -> Self {
65+
Arc::new(Offer { inner: ldk_value })
66+
}
67+
}
68+
69+
impl UniffiConversionType for Arc<Offer> {
70+
fn as_ldk(&self) -> Self::LdkType {
71+
self.inner.clone()
72+
}
73+
}
74+
6075
pub fn maybe_convert<T: UniffiConversionType>(value: &T) -> T::LdkType {
6176
value.as_ldk()
6277
}

0 commit comments

Comments
 (0)