Skip to content

Commit 17aa045

Browse files
committed
Migrate records and config types to UniFFI proc-macro export
Migrate `Config`, `AnchorChannelsConfig`, `BackgroundSyncConfig`, `SyncTimeoutsConfig`, `EsploraSyncConfig`, `ElectrumSyncConfig`, `ChannelConfig`, `CustomTlvRecord`, `PeerDetails`, `PaymentDetails`, `BalanceDetails`, `NodeStatus`, `LSPS2ServiceConfig`, and `ChannelDetails` from UDL dictionary definitions to `#[derive(uniffi::Record)]` proc-macro exports. Co-Authored-By: HAL 9000
1 parent 6f1de4f commit 17aa045

8 files changed

Lines changed: 31 additions & 133 deletions

File tree

bindings/ldk_node.udl

Lines changed: 15 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,19 @@ namespace ldk_node {
33
Config default_config();
44
};
55

6-
dictionary Config {
7-
string storage_dir_path;
8-
Network network;
9-
sequence<SocketAddress>? listening_addresses;
10-
sequence<SocketAddress>? announcement_addresses;
11-
NodeAlias? node_alias;
12-
sequence<PublicKey> trusted_peers_0conf;
13-
u64 probing_liquidity_limit_multiplier;
14-
AnchorChannelsConfig? anchor_channels_config;
15-
RouteParametersConfig? route_parameters;
16-
};
6+
typedef dictionary Config;
177

18-
dictionary AnchorChannelsConfig {
19-
sequence<PublicKey> trusted_peers_no_reserve;
20-
u64 per_channel_reserve_sats;
21-
};
8+
typedef dictionary AnchorChannelsConfig;
229

23-
dictionary BackgroundSyncConfig {
24-
u64 onchain_wallet_sync_interval_secs;
25-
u64 lightning_wallet_sync_interval_secs;
26-
u64 fee_rate_cache_update_interval_secs;
27-
};
10+
typedef dictionary BackgroundSyncConfig;
2811

29-
dictionary SyncTimeoutsConfig {
30-
u64 onchain_wallet_sync_timeout_secs;
31-
u64 lightning_wallet_sync_timeout_secs;
32-
u64 fee_rate_cache_update_timeout_secs;
33-
u64 tx_broadcast_timeout_secs;
34-
u8 per_request_timeout_secs;
35-
};
12+
typedef dictionary SyncTimeoutsConfig;
3613

37-
dictionary EsploraSyncConfig {
38-
BackgroundSyncConfig? background_sync_config;
39-
SyncTimeoutsConfig timeouts_config;
40-
};
14+
typedef dictionary EsploraSyncConfig;
4115

42-
dictionary ElectrumSyncConfig {
43-
BackgroundSyncConfig? background_sync_config;
44-
SyncTimeoutsConfig timeouts_config;
45-
};
16+
typedef dictionary ElectrumSyncConfig;
4617

47-
dictionary LSPS2ServiceConfig {
48-
string? require_token;
49-
boolean advertise_service;
50-
u32 channel_opening_fee_ppm;
51-
u32 channel_over_provisioning_ppm;
52-
u64 min_channel_opening_fee_msat;
53-
u32 min_channel_lifetime;
54-
u32 max_client_to_self_delay;
55-
u64 min_payment_size_msat;
56-
u64 max_payment_size_msat;
57-
boolean client_trusts_lsp;
58-
};
18+
typedef dictionary LSPS2ServiceConfig;
5919

6020
interface NodeEntropy {
6121
[Name=from_bip39_mnemonic]
@@ -359,16 +319,7 @@ enum NodeError {
359319
"HrnParsingFailed",
360320
};
361321

362-
dictionary NodeStatus {
363-
boolean is_running;
364-
BestBlock current_best_block;
365-
u64? latest_lightning_wallet_sync_timestamp;
366-
u64? latest_onchain_wallet_sync_timestamp;
367-
u64? latest_fee_rate_cache_update_timestamp;
368-
u64? latest_rgs_snapshot_timestamp;
369-
u64? latest_pathfinding_scores_sync_timestamp;
370-
u64? latest_node_announcement_broadcast_timestamp;
371-
};
322+
typedef dictionary NodeStatus;
372323

373324
[Remote]
374325
dictionary BestBlock {
@@ -423,15 +374,7 @@ typedef dictionary LSPFeeLimits;
423374

424375
typedef enum ConfirmationStatus;
425376

426-
dictionary PaymentDetails {
427-
PaymentId id;
428-
PaymentKind kind;
429-
u64? amount_msat;
430-
u64? fee_paid_msat;
431-
PaymentDirection direction;
432-
PaymentStatus status;
433-
u64 latest_update_timestamp;
434-
};
377+
typedef dictionary PaymentDetails;
435378

436379
[Remote]
437380
dictionary RouteParametersConfig {
@@ -441,10 +384,7 @@ dictionary RouteParametersConfig {
441384
u8 max_channel_saturation_power_of_half;
442385
};
443386

444-
dictionary CustomTlvRecord {
445-
u64 type_num;
446-
sequence<u8> value;
447-
};
387+
typedef dictionary CustomTlvRecord;
448388

449389
[Remote]
450390
dictionary LSPS1OrderStatus {
@@ -517,47 +457,9 @@ dictionary OutPoint {
517457
u32 vout;
518458
};
519459

520-
dictionary ChannelDetails {
521-
ChannelId channel_id;
522-
PublicKey counterparty_node_id;
523-
OutPoint? funding_txo;
524-
ScriptBuf? funding_redeem_script;
525-
u64? short_channel_id;
526-
u64? outbound_scid_alias;
527-
u64? inbound_scid_alias;
528-
u64 channel_value_sats;
529-
u64? unspendable_punishment_reserve;
530-
UserChannelId user_channel_id;
531-
u32 feerate_sat_per_1000_weight;
532-
u64 outbound_capacity_msat;
533-
u64 inbound_capacity_msat;
534-
u32? confirmations_required;
535-
u32? confirmations;
536-
boolean is_outbound;
537-
boolean is_channel_ready;
538-
boolean is_usable;
539-
boolean is_announced;
540-
u16? cltv_expiry_delta;
541-
u64 counterparty_unspendable_punishment_reserve;
542-
u64? counterparty_outbound_htlc_minimum_msat;
543-
u64? counterparty_outbound_htlc_maximum_msat;
544-
u32? counterparty_forwarding_info_fee_base_msat;
545-
u32? counterparty_forwarding_info_fee_proportional_millionths;
546-
u16? counterparty_forwarding_info_cltv_expiry_delta;
547-
u64 next_outbound_htlc_limit_msat;
548-
u64 next_outbound_htlc_minimum_msat;
549-
u16? force_close_spend_delay;
550-
u64 inbound_htlc_minimum_msat;
551-
u64? inbound_htlc_maximum_msat;
552-
ChannelConfig config;
553-
};
554-
555-
dictionary PeerDetails {
556-
PublicKey node_id;
557-
SocketAddress address;
558-
boolean is_persisted;
559-
boolean is_connected;
560-
};
460+
typedef dictionary ChannelDetails;
461+
462+
typedef dictionary PeerDetails;
561463

562464
typedef enum LightningBalance;
563465

@@ -571,23 +473,9 @@ enum BalanceSource {
571473

572474
typedef enum PendingSweepBalance;
573475

574-
dictionary BalanceDetails {
575-
u64 total_onchain_balance_sats;
576-
u64 spendable_onchain_balance_sats;
577-
u64 total_anchor_channels_reserve_sats;
578-
u64 total_lightning_balance_sats;
579-
sequence<LightningBalance> lightning_balances;
580-
sequence<PendingSweepBalance> pending_balances_from_channel_closures;
581-
};
476+
typedef dictionary BalanceDetails;
582477

583-
dictionary ChannelConfig {
584-
u32 forwarding_fee_proportional_millionths;
585-
u32 forwarding_fee_base_msat;
586-
u16 cltv_expiry_delta;
587-
MaxDustHTLCExposure max_dust_htlc_exposure;
588-
u64 force_close_avoidance_max_fee_satoshis;
589-
boolean accept_underpaying_htlcs;
590-
};
478+
typedef dictionary ChannelConfig;
591479

592480
typedef enum MaxDustHTLCExposure;
593481

src/balance.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use lightning_types::payment::{PaymentHash, PaymentPreimage};
1717
///
1818
/// [`Node::list_balances`]: crate::Node::list_balances
1919
#[derive(Debug, Clone)]
20+
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
2021
pub struct BalanceDetails {
2122
/// The total balance of our on-chain wallet.
2223
pub total_onchain_balance_sats: u64,

src/config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ pub(crate) const EXTERNAL_PATHFINDING_SCORES_SYNC_TIMEOUT_SECS: u64 = 5;
108108
pub(crate) const HRN_RESOLUTION_TIMEOUT_SECS: u64 = 5;
109109

110110
#[derive(Debug, Clone)]
111+
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
111112
/// Represents the configuration of an [`Node`] instance.
112113
///
113114
/// ### Defaults
@@ -238,6 +239,7 @@ impl Default for Config {
238239
///
239240
/// [BOLT 3]: https://github.com/lightning/bolts/blob/master/03-transactions.md#htlc-timeout-and-htlc-success-transactions
240241
#[derive(Debug, Clone)]
242+
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
241243
pub struct AnchorChannelsConfig {
242244
/// A list of peers that we trust to get the required channel closing transactions confirmed
243245
/// on-chain.
@@ -353,6 +355,7 @@ pub(crate) fn default_user_config(config: &Config) -> UserConfig {
353355
/// | `lightning_wallet_sync_interval_secs` | 30 |
354356
/// | `fee_rate_cache_update_interval_secs` | 600 |
355357
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
358+
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
356359
pub struct BackgroundSyncConfig {
357360
/// The time in-between background sync attempts of the onchain wallet, in seconds.
358361
///
@@ -392,6 +395,7 @@ impl Default for BackgroundSyncConfig {
392395
/// | `tx_broadcast_timeout_secs` | 10 |
393396
/// | `per_request_timeout_secs` | 10 |
394397
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
398+
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
395399
pub struct SyncTimeoutsConfig {
396400
/// The timeout after which we abort syncing the onchain wallet.
397401
pub onchain_wallet_sync_timeout_secs: u64,
@@ -422,6 +426,7 @@ impl Default for SyncTimeoutsConfig {
422426
/// Background syncing is enabled by default, using the default values specified in
423427
/// [`BackgroundSyncConfig`].
424428
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
429+
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
425430
pub struct EsploraSyncConfig {
426431
/// Background sync configuration.
427432
///
@@ -448,6 +453,7 @@ impl Default for EsploraSyncConfig {
448453
/// Background syncing is enabled by default, using the default values specified in
449454
/// [`BackgroundSyncConfig`].
450455
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
456+
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
451457
pub struct ElectrumSyncConfig {
452458
/// Background sync configuration.
453459
///
@@ -481,6 +487,7 @@ pub struct BitcoindRestClientConfig {
481487
/// Options which apply on a per-channel basis and may change at runtime or based on negotiation
482488
/// with our counterparty.
483489
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
490+
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
484491
pub struct ChannelConfig {
485492
/// Amount (in millionths of a satoshi) charged per satoshi for payments forwarded outbound
486493
/// over the channel.

src/ffi/types.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,12 @@ impl VssClientHeaderProvider for VssHeaderProviderAdapter {
138138
}
139139

140140
use crate::builder::sanitize_alias;
141-
pub use crate::config::{
142-
default_config, AnchorChannelsConfig, BackgroundSyncConfig, ElectrumSyncConfig,
143-
EsploraSyncConfig, MaxDustHTLCExposure, SyncTimeoutsConfig,
144-
};
141+
pub use crate::config::{default_config, ElectrumSyncConfig, EsploraSyncConfig};
145142
pub use crate::entropy::{generate_entropy_mnemonic, EntropyError, NodeEntropy, WordCount};
146143
use crate::error::Error;
147144
pub use crate::graph::{ChannelInfo, ChannelUpdateInfo, NodeAnnouncementInfo, NodeInfo};
148-
pub use crate::liquidity::{LSPS1OrderStatus, LSPS2ServiceConfig};
145+
pub use crate::liquidity::LSPS1OrderStatus;
149146
pub use crate::logger::{LogLevel, LogRecord, LogWriter};
150-
pub use crate::payment::store::{PaymentDirection, PaymentKind, PaymentStatus};
151147
pub use crate::payment::UnifiedPaymentResult;
152148
use crate::{hex_utils, SocketAddress, UserChannelId};
153149

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,6 +1735,7 @@ impl Drop for Node {
17351735

17361736
/// Represents the status of the [`Node`].
17371737
#[derive(Clone, Debug, PartialEq, Eq)]
1738+
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
17381739
pub struct NodeStatus {
17391740
/// Indicates whether the [`Node`] is running.
17401741
pub is_running: bool,

src/liquidity.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ struct LSPS2Service {
9999
///
100100
/// [bLIP-52 / LSPS2]: https://github.com/lightning/blips/blob/master/blip-0052.md
101101
#[derive(Debug, Clone)]
102+
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
102103
pub struct LSPS2ServiceConfig {
103104
/// A token we may require to be sent by the clients.
104105
///

src/payment/store.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use crate::hex_utils;
2424

2525
/// Represents a payment.
2626
#[derive(Clone, Debug, PartialEq, Eq)]
27+
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
2728
pub struct PaymentDetails {
2829
/// The identifier of this payment.
2930
pub id: PaymentId,

src/types.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ impl fmt::Display for UserChannelId {
355355
///
356356
/// [`Node::list_channels`]: crate::Node::list_channels
357357
#[derive(Debug, Clone)]
358+
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
358359
pub struct ChannelDetails {
359360
/// The channel's ID (prior to initial channel setup this is a random 32 bytes, thereafter it
360361
/// is derived from channel funding or key material).
@@ -591,6 +592,7 @@ impl From<LdkChannelDetails> for ChannelDetails {
591592
///
592593
/// [`Node::list_peers`]: crate::Node::list_peers
593594
#[derive(Debug, Clone, PartialEq, Eq)]
595+
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
594596
pub struct PeerDetails {
595597
/// The node ID of the peer.
596598
pub node_id: PublicKey,
@@ -604,6 +606,7 @@ pub struct PeerDetails {
604606

605607
/// Custom TLV entry.
606608
#[derive(Debug, Clone, PartialEq, Eq)]
609+
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
607610
pub struct CustomTlvRecord {
608611
/// Type number.
609612
pub type_num: u64,

0 commit comments

Comments
 (0)