Skip to content

Commit f5e70c1

Browse files
committed
Migrate NetworkGraph, NodeEntropy, and LSPS1Liquidity interfaces to UniFFI proc-macro export
Move these three simple Object types from UDL interface definitions to `#[derive(uniffi::Object)]` + `#[uniffi::export]` proc-macro annotations, replacing their UDL interface blocks with `typedef interface` references. Generated with the assistance of AI (Claude). Co-Authored-By: HAL 9000
1 parent fc94280 commit f5e70c1

File tree

5 files changed

+32
-35
lines changed

5 files changed

+32
-35
lines changed

bindings/ldk_node.udl

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,7 @@ typedef dictionary ElectrumSyncConfig;
1717

1818
typedef dictionary LSPS2ServiceConfig;
1919

20-
interface NodeEntropy {
21-
[Name=from_bip39_mnemonic]
22-
constructor(Mnemonic mnemonic, string? passphrase);
23-
[Throws=EntropyError, Name=from_seed_bytes]
24-
constructor(bytes seed_bytes);
25-
[Throws=EntropyError, Name=from_seed_path]
26-
constructor(string seed_path);
27-
};
20+
typedef interface NodeEntropy;
2821

2922
typedef enum EntropyError;
3023

@@ -239,12 +232,7 @@ interface UnifiedPayment {
239232
UnifiedPaymentResult send([ByRef]string uri_str, u64? amount_msat, RouteParametersConfig? route_parameters);
240233
};
241234

242-
interface LSPS1Liquidity {
243-
[Throws=NodeError]
244-
LSPS1OrderStatus request_channel(u64 lsp_balance_sat, u64 client_balance_sat, u32 channel_expiry_blocks, boolean announce_channel);
245-
[Throws=NodeError]
246-
LSPS1OrderStatus check_order_status(LSPS1OrderId order_id);
247-
};
235+
typedef interface LSPS1Liquidity;
248236

249237
[Error]
250238
enum NodeError {
@@ -438,12 +426,7 @@ typedef dictionary ChannelConfig;
438426

439427
typedef enum MaxDustHTLCExposure;
440428

441-
interface NetworkGraph {
442-
sequence<u64> list_channels();
443-
ChannelInfo? channel(u64 short_channel_id);
444-
sequence<NodeId> list_nodes();
445-
NodeInfo? node([ByRef]NodeId node_id);
446-
};
429+
typedef interface NetworkGraph;
447430

448431
typedef dictionary ChannelInfo;
449432

src/entropy.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,38 @@ impl std::error::Error for EntropyError {}
4040
///
4141
/// [`Node`]: crate::Node
4242
#[derive(Copy, Clone)]
43+
#[cfg_attr(feature = "uniffi", derive(uniffi::Object))]
4344
pub struct NodeEntropy([u8; WALLET_KEYS_SEED_LEN]);
4445

46+
impl NodeEntropy {
47+
/// Configures the [`Node`] instance to source its wallet entropy from the given
48+
/// [`WALLET_KEYS_SEED_LEN`] seed bytes.
49+
///
50+
/// [`Node`]: crate::Node
51+
#[cfg(not(feature = "uniffi"))]
52+
pub fn from_seed_bytes(seed_bytes: [u8; WALLET_KEYS_SEED_LEN]) -> Self {
53+
Self(seed_bytes)
54+
}
55+
56+
pub(crate) fn to_seed_bytes(&self) -> [u8; WALLET_KEYS_SEED_LEN] {
57+
self.0
58+
}
59+
}
60+
61+
#[cfg_attr(feature = "uniffi", uniffi::export)]
4562
impl NodeEntropy {
4663
/// Configures the [`Node`] instance to source its wallet entropy from a [BIP 39] mnemonic.
4764
///
4865
/// [BIP 39]: https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki
4966
/// [`Node`]: crate::Node
67+
#[cfg_attr(feature = "uniffi", uniffi::constructor)]
5068
pub fn from_bip39_mnemonic(mnemonic: Mnemonic, passphrase: Option<String>) -> Self {
5169
match passphrase {
5270
Some(passphrase) => Self(mnemonic.to_seed(passphrase)),
5371
None => Self(mnemonic.to_seed("")),
5472
}
5573
}
5674

57-
/// Configures the [`Node`] instance to source its wallet entropy from the given
58-
/// [`WALLET_KEYS_SEED_LEN`] seed bytes.
59-
///
60-
/// [`Node`]: crate::Node
61-
#[cfg(not(feature = "uniffi"))]
62-
pub fn from_seed_bytes(seed_bytes: [u8; WALLET_KEYS_SEED_LEN]) -> Self {
63-
Self(seed_bytes)
64-
}
65-
6675
/// Configures the [`Node`] instance to source its wallet entropy from the given
6776
/// [`WALLET_KEYS_SEED_LEN`] seed bytes.
6877
///
@@ -71,6 +80,7 @@ impl NodeEntropy {
7180
///
7281
/// [`Node`]: crate::Node
7382
#[cfg(feature = "uniffi")]
83+
#[uniffi::constructor]
7484
pub fn from_seed_bytes(seed_bytes: Vec<u8>) -> Result<NodeEntropy, EntropyError> {
7585
if seed_bytes.len() != WALLET_KEYS_SEED_LEN {
7686
return Err(EntropyError::InvalidSeedBytes);
@@ -86,16 +96,13 @@ impl NodeEntropy {
8696
/// stored at the given location.
8797
///
8898
/// [`Node`]: crate::Node
99+
#[cfg_attr(feature = "uniffi", uniffi::constructor)]
89100
pub fn from_seed_path(seed_path: String) -> Result<Self, EntropyError> {
90101
Ok(Self(
91102
io::utils::read_or_generate_seed_file(&seed_path)
92103
.map_err(|_| EntropyError::InvalidSeedFile)?,
93104
))
94105
}
95-
96-
pub(crate) fn to_seed_bytes(&self) -> [u8; WALLET_KEYS_SEED_LEN] {
97-
self.0
98-
}
99106
}
100107

101108
impl fmt::Display for NodeEntropy {

src/ffi/types.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,8 @@ impl VssClientHeaderProvider for VssHeaderProviderAdapter {
139139

140140
use crate::builder::sanitize_alias;
141141
pub use crate::config::{default_config, ElectrumSyncConfig, EsploraSyncConfig};
142-
pub use crate::entropy::{generate_entropy_mnemonic, EntropyError, NodeEntropy, WordCount};
142+
pub use crate::entropy::{generate_entropy_mnemonic, NodeEntropy, WordCount};
143143
use crate::error::Error;
144-
pub use crate::graph::{ChannelInfo, NodeInfo};
145144
pub use crate::liquidity::LSPS1OrderStatus;
146145
pub use crate::logger::{LogLevel, LogRecord, LogWriter};
147146
pub use crate::payment::UnifiedPaymentResult;

src/graph.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use lightning::routing::gossip::{ChannelInfo, NodeInfo};
2020
use crate::types::Graph;
2121

2222
/// Represents the network as nodes and channels between them.
23+
#[cfg_attr(feature = "uniffi", derive(uniffi::Object))]
2324
pub struct NetworkGraph {
2425
inner: Arc<Graph>,
2526
}
@@ -28,7 +29,10 @@ impl NetworkGraph {
2829
pub(crate) fn new(inner: Arc<Graph>) -> Self {
2930
Self { inner }
3031
}
32+
}
3133

34+
#[cfg_attr(feature = "uniffi", uniffi::export)]
35+
impl NetworkGraph {
3236
/// Returns the list of channels in the graph
3337
pub fn list_channels(&self) -> Vec<u64> {
3438
self.inner.read_only().channels().unordered_keys().map(|c| *c).collect()

src/liquidity.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,7 @@ pub(crate) struct LSPS2BuyResponse {
14511451
/// [`Node::lsps1_liquidity`]: crate::Node::lsps1_liquidity
14521452
/// [`Bolt11Payment::receive_via_jit_channel`]: crate::payment::Bolt11Payment::receive_via_jit_channel
14531453
#[derive(Clone)]
1454+
#[cfg_attr(feature = "uniffi", derive(uniffi::Object))]
14541455
pub struct LSPS1Liquidity {
14551456
runtime: Arc<Runtime>,
14561457
wallet: Arc<Wallet>,
@@ -1467,7 +1468,10 @@ impl LSPS1Liquidity {
14671468
) -> Self {
14681469
Self { runtime, wallet, connection_manager, liquidity_source, logger }
14691470
}
1471+
}
14701472

1473+
#[cfg_attr(feature = "uniffi", uniffi::export)]
1474+
impl LSPS1Liquidity {
14711475
/// Connects to the configured LSP and places an order for an inbound channel.
14721476
///
14731477
/// The channel will be opened after one of the returned payment options has successfully been

0 commit comments

Comments
 (0)