Skip to content

Commit 40a3aeb

Browse files
authored
Merge pull request #542 from alexanderwiederin/uniffi-bolt12-clean
Feature: Add Bolt12 Uniffi Type Wrappers
2 parents f95c879 + f01d021 commit 40a3aeb

File tree

9 files changed

+1816
-868
lines changed

9 files changed

+1816
-868
lines changed

bindings/ldk_node.udl

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,71 @@ 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+
[Traits=(Debug, Display, Eq)]
746+
interface Offer {
747+
[Throws=NodeError, Name=from_str]
748+
constructor([ByRef] string offer_str);
749+
OfferId id();
750+
boolean is_expired();
751+
string? description();
752+
string? issuer();
753+
OfferAmount? amount();
754+
boolean is_valid_quantity(u64 quantity);
755+
boolean expects_quantity();
756+
boolean supports_chain(Network chain);
757+
sequence<Network> chains();
758+
sequence<u8>? metadata();
759+
u64? absolute_expiry_seconds();
760+
PublicKey? issuer_signing_pubkey();
761+
};
762+
763+
[Traits=(Debug, Display, Eq)]
764+
interface Refund {
765+
[Throws=NodeError, Name=from_str]
766+
constructor([ByRef] string refund_str);
767+
string description();
768+
u64? absolute_expiry_seconds();
769+
boolean is_expired();
770+
string? issuer();
771+
sequence<u8> payer_metadata();
772+
Network? chain();
773+
u64 amount_msats();
774+
u64? quantity();
775+
PublicKey payer_signing_pubkey();
776+
string? payer_note();
777+
};
778+
779+
interface Bolt12Invoice {
780+
[Throws=NodeError, Name=from_str]
781+
constructor([ByRef] string invoice_str);
782+
PaymentHash payment_hash();
783+
u64 amount_msats();
784+
OfferAmount? amount();
785+
PublicKey signing_pubkey();
786+
u64 created_at();
787+
u64? absolute_expiry_seconds();
788+
u64 relative_expiry();
789+
boolean is_expired();
790+
string? description();
791+
string? issuer();
792+
string? payer_note();
793+
sequence<u8>? metadata();
794+
u64? quantity();
795+
sequence<u8> signable_hash();
796+
PublicKey payer_signing_pubkey();
797+
PublicKey? issuer_signing_pubkey();
798+
sequence<u8> chain();
799+
sequence<sequence<u8>>? offer_chains();
800+
sequence<Address> fallback_addresses();
801+
sequence<u8> encode();
802+
};
803+
739804
[Custom]
740805
typedef string Txid;
741806

@@ -754,15 +819,6 @@ typedef string NodeId;
754819
[Custom]
755820
typedef string Address;
756821

757-
[Custom]
758-
typedef string Offer;
759-
760-
[Custom]
761-
typedef string Refund;
762-
763-
[Custom]
764-
typedef string Bolt12Invoice;
765-
766822
[Custom]
767823
typedef string OfferId;
768824

src/ffi/mod.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// This file is Copyright its original authors, visible in version control history.
2+
//
3+
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5+
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
6+
7+
#[cfg(feature = "uniffi")]
8+
mod types;
9+
10+
#[cfg(feature = "uniffi")]
11+
pub use types::*;
12+
13+
#[cfg(feature = "uniffi")]
14+
pub fn maybe_deref<T, R>(wrapped_type: &std::sync::Arc<T>) -> &R
15+
where
16+
T: AsRef<R>,
17+
{
18+
wrapped_type.as_ref().as_ref()
19+
}
20+
21+
#[cfg(feature = "uniffi")]
22+
pub fn maybe_try_convert_enum<T, R>(wrapped_type: &T) -> Result<R, crate::error::Error>
23+
where
24+
for<'a> R: TryFrom<&'a T, Error = crate::error::Error>,
25+
{
26+
R::try_from(wrapped_type)
27+
}
28+
29+
#[cfg(feature = "uniffi")]
30+
pub fn maybe_wrap<T>(ldk_type: impl Into<T>) -> std::sync::Arc<T> {
31+
std::sync::Arc::new(ldk_type.into())
32+
}
33+
34+
#[cfg(not(feature = "uniffi"))]
35+
pub fn maybe_deref<T>(value: &T) -> &T {
36+
value
37+
}
38+
39+
#[cfg(not(feature = "uniffi"))]
40+
pub fn maybe_try_convert_enum<T>(value: &T) -> Result<&T, crate::error::Error> {
41+
Ok(value)
42+
}
43+
44+
#[cfg(not(feature = "uniffi"))]
45+
pub fn maybe_wrap<T>(value: T) -> T {
46+
value
47+
}

0 commit comments

Comments
 (0)