Skip to content

Commit 51128fe

Browse files
committed
Migrate FFI-only types and remaining types to UniFFI proc-macro export
Migrate `Bolt11InvoiceDescription`, `OfferAmount`, `UnifiedPaymentResult`, `RouteHintHop`, `LogRecord`, `LSPS1PaymentInfo`, `LSPS1Bolt11PaymentInfo`, `LSPS1OnchainPaymentInfo`, `ChannelInfo`, `ChannelUpdateInfo`, `NodeInfo`, `NodeAnnouncementInfo`, and `VssHeaderProviderError` from UDL definitions to proc-macro derives. Co-Authored-By: HAL 9000
1 parent 17aa045 commit 51128fe

5 files changed

Lines changed: 27 additions & 97 deletions

File tree

bindings/ldk_node.udl

Lines changed: 13 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,7 @@ enum LogLevel {
4040
"Error",
4141
};
4242

43-
dictionary LogRecord {
44-
LogLevel level;
45-
string args;
46-
string module_path;
47-
u32 line;
48-
PublicKey? peer_id;
49-
ChannelId? channel_id;
50-
PaymentHash? payment_hash;
51-
};
43+
typedef dictionary LogRecord;
5244

5345
[Trait, WithForeign]
5446
interface LogWriter {
@@ -151,11 +143,7 @@ interface Node {
151143
bytes export_pathfinding_scores();
152144
};
153145

154-
[Enum]
155-
interface Bolt11InvoiceDescription {
156-
Hash(string hash);
157-
Direct(string description);
158-
};
146+
typedef enum Bolt11InvoiceDescription;
159147

160148
interface Bolt11Payment {
161149
[Throws=NodeError]
@@ -335,13 +323,7 @@ interface VssHeaderProvider {
335323
record<string, string> get_headers(sequence<u8> request);
336324
};
337325

338-
[Error]
339-
interface VssHeaderProviderError {
340-
InvalidData(string error);
341-
RequestError(string error);
342-
AuthorizationError(string error);
343-
InternalError(string error);
344-
};
326+
typedef enum VssHeaderProviderError;
345327

346328
[Remote]
347329
enum PaymentFailureReason {
@@ -359,12 +341,7 @@ enum PaymentFailureReason {
359341

360342
typedef enum PaymentKind;
361343

362-
[Enum]
363-
interface UnifiedPaymentResult {
364-
Onchain(Txid txid);
365-
Bolt11(PaymentId payment_id);
366-
Bolt12(PaymentId payment_id);
367-
};
344+
typedef enum UnifiedPaymentResult;
368345

369346
typedef enum PaymentDirection;
370347

@@ -405,29 +382,11 @@ dictionary LSPS1OrderParams {
405382
boolean announce_channel;
406383
};
407384

408-
dictionary LSPS1PaymentInfo {
409-
LSPS1Bolt11PaymentInfo? bolt11;
410-
LSPS1OnchainPaymentInfo? onchain;
411-
};
385+
typedef dictionary LSPS1PaymentInfo;
412386

413-
dictionary LSPS1Bolt11PaymentInfo {
414-
LSPS1PaymentState state;
415-
LSPSDateTime expires_at;
416-
u64 fee_total_sat;
417-
u64 order_total_sat;
418-
Bolt11Invoice invoice;
419-
};
387+
typedef dictionary LSPS1Bolt11PaymentInfo;
420388

421-
dictionary LSPS1OnchainPaymentInfo {
422-
LSPS1PaymentState state;
423-
LSPSDateTime expires_at;
424-
u64 fee_total_sat;
425-
u64 order_total_sat;
426-
Address address;
427-
u16? min_onchain_payment_confirmations;
428-
FeeRate min_fee_for_0conf;
429-
Address? refund_onchain_address;
430-
};
389+
typedef dictionary LSPS1OnchainPaymentInfo;
431390

432391
[Remote]
433392
dictionary LSPS1ChannelInfo {
@@ -486,39 +445,19 @@ interface NetworkGraph {
486445
NodeInfo? node([ByRef]NodeId node_id);
487446
};
488447

489-
dictionary ChannelInfo {
490-
NodeId node_one;
491-
ChannelUpdateInfo? one_to_two;
492-
NodeId node_two;
493-
ChannelUpdateInfo? two_to_one;
494-
u64? capacity_sats;
495-
};
448+
typedef dictionary ChannelInfo;
496449

497-
dictionary ChannelUpdateInfo {
498-
u32 last_update;
499-
boolean enabled;
500-
u16 cltv_expiry_delta;
501-
u64 htlc_minimum_msat;
502-
u64 htlc_maximum_msat;
503-
RoutingFees fees;
504-
};
450+
typedef dictionary ChannelUpdateInfo;
505451

506452
[Remote]
507453
dictionary RoutingFees {
508454
u32 base_msat;
509455
u32 proportional_millionths;
510456
};
511457

512-
dictionary NodeInfo {
513-
sequence<u64> channels;
514-
NodeAnnouncementInfo? announcement_info;
515-
};
458+
typedef dictionary NodeInfo;
516459

517-
dictionary NodeAnnouncementInfo {
518-
u32 last_update;
519-
string alias;
520-
sequence<SocketAddress> addresses;
521-
};
460+
typedef dictionary NodeAnnouncementInfo;
522461

523462
[Remote]
524463
enum Currency {
@@ -531,14 +470,7 @@ enum Currency {
531470

532471
typedef enum AsyncPaymentsRole;
533472

534-
dictionary RouteHintHop {
535-
PublicKey src_node_id;
536-
u64 short_channel_id;
537-
u16 cltv_expiry_delta;
538-
u64? htlc_minimum_msat;
539-
u64? htlc_maximum_msat;
540-
RoutingFees fees;
541-
};
473+
typedef dictionary RouteHintHop;
542474

543475
[Traits=(Debug, Display, Eq)]
544476
interface Bolt11Invoice {
@@ -562,11 +494,7 @@ interface Bolt11Invoice {
562494
PublicKey recover_payee_pub_key();
563495
};
564496

565-
[Enum]
566-
interface OfferAmount {
567-
Bitcoin(u64 amount_msats);
568-
Currency(string iso4217_code, u64 amount);
569-
};
497+
typedef enum OfferAmount;
570498

571499
[Traits=(Debug, Display, Eq)]
572500
interface Offer {

src/ffi/types.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use vss_client::headers::VssHeaderProvider as VssClientHeaderProvider;
4747
use vss_client::headers::VssHeaderProviderError as VssClientHeaderProviderError;
4848

4949
/// Errors around providing headers for each VSS request.
50-
#[derive(Debug)]
50+
#[derive(Debug, uniffi::Error)]
5151
pub enum VssHeaderProviderError {
5252
/// Invalid data was encountered.
5353
InvalidData {
@@ -141,7 +141,7 @@ use crate::builder::sanitize_alias;
141141
pub use crate::config::{default_config, ElectrumSyncConfig, EsploraSyncConfig};
142142
pub use crate::entropy::{generate_entropy_mnemonic, EntropyError, NodeEntropy, WordCount};
143143
use crate::error::Error;
144-
pub use crate::graph::{ChannelInfo, ChannelUpdateInfo, NodeAnnouncementInfo, NodeInfo};
144+
pub use crate::graph::{ChannelInfo, NodeInfo};
145145
pub use crate::liquidity::LSPS1OrderStatus;
146146
pub use crate::logger::{LogLevel, LogRecord, LogWriter};
147147
pub use crate::payment::UnifiedPaymentResult;
@@ -203,7 +203,7 @@ uniffi::custom_type!(ScriptBuf, String, {
203203
},
204204
});
205205

206-
#[derive(Debug, Clone, PartialEq, Eq)]
206+
#[derive(Debug, Clone, PartialEq, Eq, uniffi::Enum)]
207207
pub enum OfferAmount {
208208
Bitcoin { amount_msats: u64 },
209209
Currency { iso4217_code: String, amount: u64 },
@@ -933,7 +933,7 @@ uniffi::custom_type!(NodeAlias, String, {
933933

934934
/// Represents the description of an invoice which has to be either a directly included string or
935935
/// a hash of a description provided out of band.
936-
#[derive(Debug, Clone, PartialEq, Eq)]
936+
#[derive(Debug, Clone, PartialEq, Eq, uniffi::Enum)]
937937
pub enum Bolt11InvoiceDescription {
938938
/// Contains a full description.
939939
Direct {
@@ -1026,7 +1026,7 @@ impl From<lightning_invoice::Currency> for Currency {
10261026
///
10271027
/// While this generally comes from BOLT 11's `r` field, this struct includes more fields than are
10281028
/// available in BOLT 11.
1029-
#[derive(Debug, Clone, PartialEq, Eq)]
1029+
#[derive(Debug, Clone, PartialEq, Eq, uniffi::Record)]
10301030
pub struct RouteHintHop {
10311031
/// The node_id of the non-target end of the route
10321032
pub src_node_id: PublicKey,
@@ -1198,7 +1198,7 @@ impl std::fmt::Display for Bolt11Invoice {
11981198
}
11991199
}
12001200

1201-
#[derive(Clone, Debug, PartialEq, Eq)]
1201+
#[derive(Clone, Debug, PartialEq, Eq, uniffi::Record)]
12021202
pub struct LSPS1PaymentInfo {
12031203
/// A Lightning payment using BOLT 11.
12041204
pub bolt11: Option<crate::ffi::LSPS1Bolt11PaymentInfo>,
@@ -1218,7 +1218,7 @@ impl From<lightning_liquidity::lsps1::msgs::LSPS1PaymentInfo> for LSPS1PaymentIn
12181218

12191219
/// An onchain payment.
12201220
#[cfg(feature = "uniffi")]
1221-
#[derive(Clone, Debug, PartialEq, Eq)]
1221+
#[derive(Clone, Debug, PartialEq, Eq, uniffi::Record)]
12221222
pub struct LSPS1OnchainPaymentInfo {
12231223
/// Indicates the current state of the payment.
12241224
pub state: lightning_liquidity::lsps1::msgs::LSPS1PaymentState,
@@ -1257,7 +1257,7 @@ impl From<lightning_liquidity::lsps1::msgs::LSPS1OnchainPaymentInfo> for LSPS1On
12571257
}
12581258
}
12591259
/// A Lightning payment using BOLT 11.
1260-
#[derive(Clone, Debug, PartialEq, Eq)]
1260+
#[derive(Clone, Debug, PartialEq, Eq, uniffi::Record)]
12611261
pub struct LSPS1Bolt11PaymentInfo {
12621262
/// Indicates the current state of the payment.
12631263
pub state: LSPS1PaymentState,

src/graph.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl NetworkGraph {
5656
///
5757
/// This is a simplified version of LDK's `ChannelInfo` for bindings.
5858
#[cfg(feature = "uniffi")]
59-
#[derive(Clone, Debug, PartialEq, Eq)]
59+
#[derive(Clone, Debug, PartialEq, Eq, uniffi::Record)]
6060
pub struct ChannelInfo {
6161
/// Source node of the first direction of a channel
6262
pub node_one: NodeId,
@@ -87,7 +87,7 @@ impl From<lightning::routing::gossip::ChannelInfo> for ChannelInfo {
8787
///
8888
/// This is a simplified version of LDK's `ChannelUpdateInfo` for bindings.
8989
#[cfg(feature = "uniffi")]
90-
#[derive(Clone, Debug, PartialEq, Eq)]
90+
#[derive(Clone, Debug, PartialEq, Eq, uniffi::Record)]
9191
pub struct ChannelUpdateInfo {
9292
/// When the last update to the channel direction was issued.
9393
/// Value is opaque, as set in the announcement.
@@ -122,7 +122,7 @@ impl From<lightning::routing::gossip::ChannelUpdateInfo> for ChannelUpdateInfo {
122122
///
123123
/// This is a simplified version of LDK's `NodeInfo` for bindings.
124124
#[cfg(feature = "uniffi")]
125-
#[derive(Clone, Debug, PartialEq, Eq)]
125+
#[derive(Clone, Debug, PartialEq, Eq, uniffi::Record)]
126126
pub struct NodeInfo {
127127
/// All valid channels a node has announced
128128
pub channels: Vec<u64>,
@@ -146,7 +146,7 @@ impl From<lightning::routing::gossip::NodeInfo> for NodeInfo {
146146
///
147147
/// This is a simplified version of LDK's `NodeAnnouncementInfo` for bindings.
148148
#[cfg(feature = "uniffi")]
149-
#[derive(Clone, Debug, PartialEq, Eq)]
149+
#[derive(Clone, Debug, PartialEq, Eq, uniffi::Record)]
150150
pub struct NodeAnnouncementInfo {
151151
/// When the last known update to the node state was issued.
152152
/// Value is opaque, as set in the announcement.

src/logger.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ impl fmt::Display for LogContext<'_> {
101101
/// It is similar to the non-`uniffi` version, but it omits the lifetime parameter
102102
/// for the `LogRecord`, as the Uniffi-exposed interface cannot handle lifetimes.
103103
#[cfg(feature = "uniffi")]
104+
#[derive(uniffi::Record)]
104105
pub struct LogRecord {
105106
/// The verbosity level of the message.
106107
pub level: LogLevel,

src/payment/unified.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ impl UnifiedPayment {
296296
/// [`PaymentId`]: lightning::ln::channelmanager::PaymentId
297297
/// [`Txid`]: bitcoin::hash_types::Txid
298298
#[derive(Debug)]
299+
#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
299300
pub enum UnifiedPaymentResult {
300301
/// An on-chain payment.
301302
Onchain {

0 commit comments

Comments
 (0)