Skip to content

Commit 0a9379a

Browse files
committed
fixup! Allow setting default DNS resolvers for HRNs
1 parent 5a00c7c commit 0a9379a

File tree

5 files changed

+36
-30
lines changed

5 files changed

+36
-30
lines changed

bindings/ldk_node.udl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ dictionary Config {
1313
u64 probing_liquidity_limit_multiplier;
1414
AnchorChannelsConfig? anchor_channels_config;
1515
SendingParameters? sending_parameters;
16-
sequence<PublicKey>? dns_resolvers_node_ids;
16+
HumanReadableNamesConfig hrn_config;
17+
};
18+
19+
dictionary HumanReadableNamesConfig {
20+
sequence<PublicKey> dns_resolvers_node_ids;
1721
};
1822

1923
dictionary AnchorChannelsConfig {
@@ -94,8 +98,7 @@ interface Builder {
9498
void set_announcement_addresses(sequence<SocketAddress> announcement_addresses);
9599
[Throws=BuildError]
96100
void set_node_alias(string node_alias);
97-
[Throws=BuildError]
98-
void set_dns_resolvers(sequence<PublicKey> dns_resolvers_node_ids);
101+
void set_hrn_config(HumanReadableNamesConfig hrn_config);
99102
[Throws=BuildError]
100103
Node build();
101104
[Throws=BuildError]

src/builder.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
use crate::chain::{ChainSource, DEFAULT_ESPLORA_SERVER_URL};
99
use crate::config::{
1010
default_user_config, may_announce_channel, AnnounceError, Config, ElectrumSyncConfig,
11-
EsploraSyncConfig, DEFAULT_LOG_FILENAME, DEFAULT_LOG_LEVEL, WALLET_KEYS_SEED_LEN,
11+
EsploraSyncConfig, HumanReadableNamesConfig, DEFAULT_LOG_FILENAME, DEFAULT_LOG_LEVEL,
12+
WALLET_KEYS_SEED_LEN,
1213
};
1314

1415
use crate::connection::ConnectionManager;
@@ -464,15 +465,10 @@ impl NodeBuilder {
464465
Ok(self)
465466
}
466467

467-
/// Sets the default dns_resolvers to be used when sending payments to HRNs.
468-
pub fn set_dns_resolvers(
469-
&mut self, dns_resolvers_node_ids: Vec<PublicKey>,
470-
) -> Result<&mut Self, BuildError> {
471-
if dns_resolvers_node_ids.is_empty() {
472-
return Err(BuildError::DnsResolversEmpty);
473-
}
474-
self.config.dns_resolvers_node_ids = Some(dns_resolvers_node_ids);
475-
Ok(self)
468+
/// Sets the default [`Config::hrn_config`] to be used when sending payments to HRNs.
469+
pub fn set_hrn_config(&mut self, hrn_config: HumanReadableNamesConfig) -> &mut Self {
470+
self.config.hrn_config = hrn_config;
471+
self
476472
}
477473

478474
/// Builds a [`Node`] instance with a [`SqliteStore`] backend and according to the options
@@ -856,11 +852,9 @@ impl ArcedNodeBuilder {
856852
self.inner.write().unwrap().set_node_alias(node_alias).map(|_| ())
857853
}
858854

859-
/// Sets the default dns_resolvers to be used when sending payments to HRNs.
860-
pub fn set_dns_resolvers(
861-
&self, dns_resolvers_node_ids: Vec<PublicKey>,
862-
) -> Result<(), BuildError> {
863-
self.inner.write().unwrap().set_dns_resolvers(dns_resolvers_node_ids).map(|_| ())
855+
/// Sets the default [`Config::hrn_config`] to be used when sending payments to HRNs.
856+
pub fn set_hrn_config(&self, hrn_config: HumanReadableNamesConfig) {
857+
self.inner.write().unwrap().set_hrn_config(hrn_config);
864858
}
865859

866860
/// Builds a [`Node`] instance with a [`SqliteStore`] backend and according to the options

src/config.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,8 @@ pub struct Config {
168168
/// **Note:** If unset, default parameters will be used, and you will be able to override the
169169
/// parameters on a per-payment basis in the corresponding method calls.
170170
pub sending_parameters: Option<SendingParameters>,
171-
/// The dns_resolvers node_ids to be used for resolving Human-readable Names.
172-
///
173-
/// If set to `Some`, the values set will be used as dns_resolvers when sending to HRNs.
174-
/// **Note:** If set to `None`, payments to HRNs will fail.
175-
pub dns_resolvers_node_ids: Option<Vec<PublicKey>>,
171+
/// Configuration Options for Human-readable Names.
172+
pub hrn_config: HumanReadableNamesConfig,
176173
}
177174

178175
impl Default for Config {
@@ -187,11 +184,28 @@ impl Default for Config {
187184
anchor_channels_config: Some(AnchorChannelsConfig::default()),
188185
sending_parameters: None,
189186
node_alias: None,
190-
dns_resolvers_node_ids: None,
187+
hrn_config: HumanReadableNamesConfig::default(),
191188
}
192189
}
193190
}
194191

192+
/// Configuration options for Human-readable Names
193+
#[derive(Debug, Clone)]
194+
pub struct HumanReadableNamesConfig {
195+
/// The DNS resolvers to be used for resolving Human-readable Names.
196+
///
197+
/// If not empty, the values set will be used as DNS resolvers when sending to HRNs.
198+
///
199+
/// **Note:** If empty, payments to HRNs will fail.
200+
pub dns_resolvers_node_ids: Vec<PublicKey>,
201+
}
202+
203+
impl Default for HumanReadableNamesConfig {
204+
fn default() -> Self {
205+
Self { dns_resolvers_node_ids: vec![] }
206+
}
207+
}
208+
195209
/// Configuration options pertaining to 'Anchor' channels, i.e., channels for which the
196210
/// `option_anchors_zero_fee_htlc_tx` channel type is negotiated.
197211
///

src/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -829,11 +829,6 @@ impl Node {
829829
self.config.node_alias
830830
}
831831

832-
/// Returns the list of dns_resolvers that will be used to resolve HRNs.
833-
pub fn dns_resolvers(&self) -> Option<Vec<PublicKey>> {
834-
self.config.dns_resolvers_node_ids.clone()
835-
}
836-
837832
/// Returns a payment handler allowing to create and pay [BOLT 11] invoices.
838833
///
839834
/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md

src/uniffi_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
pub use crate::config::{
1414
default_config, AnchorChannelsConfig, BackgroundSyncConfig, ElectrumSyncConfig,
15-
EsploraSyncConfig, MaxDustHTLCExposure,
15+
EsploraSyncConfig, HumanReadableNamesConfig, MaxDustHTLCExposure,
1616
};
1717
pub use crate::graph::{ChannelInfo, ChannelUpdateInfo, NodeAnnouncementInfo, NodeInfo};
1818
pub use crate::liquidity::{LSPS1OrderStatus, LSPS2ServiceConfig, OnchainPaymentInfo, PaymentInfo};

0 commit comments

Comments
 (0)