Skip to content

Commit ca6ca03

Browse files
committed
fixup! Add support for sending to human-readable names that resolve to Bolt12 Offers
1 parent 83c5e40 commit ca6ca03

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

bindings/ldk_node.udl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ interface LSPS1Liquidity {
256256
};
257257

258258
interface HumanReadableName {
259-
[Name=from_encoded]
259+
[Throws=NodeError, Name=from_encoded]
260260
constructor([ByRef] string encoded);
261261
string user();
262262
string domain();

src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub enum Error {
123123
/// Parsing a Human-Readable Name has failed
124124
HrnParsingFailed,
125125
/// The given operation failed due to `dns-resolvers` not being configured in builder.
126-
DnsResolversNotConfigured,
126+
DnsResolversUnavailable,
127127
}
128128

129129
impl fmt::Display for Error {
@@ -200,7 +200,7 @@ impl fmt::Display for Error {
200200
Self::HrnParsingFailed => {
201201
write!(f, "Failed to parse a human-readable name.")
202202
},
203-
Self::DnsResolversNotConfigured => {
203+
Self::DnsResolversUnavailable => {
204204
write!(f, "The given operation failed due to `dns-resolvers` not being configured in builder.")
205205
},
206206
}

src/payment/bolt12.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ impl Bolt12Payment {
295295
/// amount paid to be determined by the user.
296296
///
297297
/// If `dns_resolvers_node_ids` in [`Config.hrn_config`] is empty, this operation will fail.
298+
///
299+
/// [BIP 353]: https://github.com/bitcoin/bips/blob/master/bip-0353.mediawiki
298300
pub fn send_to_human_readable_name(
299301
&self, hrn: HumanReadableName, amount_msat: u64,
300302
) -> Result<PaymentId, Error> {
@@ -309,13 +311,14 @@ impl Bolt12Payment {
309311
let retry_strategy = Retry::Timeout(LDK_PAYMENT_RETRY_TIMEOUT);
310312
let max_total_routing_fee_msat = None;
311313

312-
let destinations: Vec<Destination> = self
313-
.config
314-
.hrn_config
315-
.dns_resolvers_node_ids
316-
.iter()
317-
.map(|node_id| Destination::Node(*node_id))
318-
.collect();
314+
let destinations: Vec<Destination> = match &self.config.hrn_config {
315+
Some(hrn_config) => Ok(hrn_config
316+
.dns_resolvers_node_ids
317+
.iter()
318+
.map(|node_id| Destination::Node(*node_id))
319+
.collect()),
320+
None => Err(Error::DnsResolversUnavailable),
321+
}?;
319322

320323
let hrn = maybe_convert_hrn(hrn);
321324

src/uniffi_types.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -667,13 +667,13 @@ impl HumanReadableName {
667667
self.inner.clone()
668668
}
669669

670-
pub fn from_encoded(encoded: &str) -> Self {
670+
pub fn from_encoded(encoded: &str) -> Result<Self, Error> {
671671
let hrn = match LdkHumanReadableName::from_encoded(encoded) {
672672
Ok(hrn) => Ok(hrn),
673-
Err(e) => Err(format!("Error creating HRN {:?}", e)),
674-
};
673+
Err(_) => Err(Error::HrnParsingFailed),
674+
}?;
675675

676-
Self { inner: hrn.expect("Error creating HRN") }
676+
Ok(Self { inner: hrn })
677677
}
678678

679679
pub fn user(&self) -> String {

0 commit comments

Comments
 (0)