Skip to content

Commit 2f13d19

Browse files
committed
fixup! Add support for sending to human-readable names that resolve to Bolt12 Offers
1 parent c69b95f commit 2f13d19

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
@@ -280,6 +280,8 @@ impl Bolt12Payment {
280280
/// amount paid to be determined by the user.
281281
///
282282
/// If `dns_resolvers_node_ids` in [`Config.hrn_config`] is empty, this operation will fail.
283+
///
284+
/// [BIP 353]: https://github.com/bitcoin/bips/blob/master/bip-0353.mediawiki
283285
pub fn send_to_human_readable_name(
284286
&self, hrn: HumanReadableName, amount_msat: u64,
285287
) -> Result<PaymentId, Error> {
@@ -294,13 +296,14 @@ impl Bolt12Payment {
294296
let retry_strategy = Retry::Timeout(LDK_PAYMENT_RETRY_TIMEOUT);
295297
let max_total_routing_fee_msat = None;
296298

297-
let destinations: Vec<Destination> = self
298-
.config
299-
.hrn_config
300-
.dns_resolvers_node_ids
301-
.iter()
302-
.map(|node_id| Destination::Node(*node_id))
303-
.collect();
299+
let destinations: Vec<Destination> = match &self.config.hrn_config {
300+
Some(hrn_config) => Ok(hrn_config
301+
.dns_resolvers_node_ids
302+
.iter()
303+
.map(|node_id| Destination::Node(*node_id))
304+
.collect()),
305+
None => Err(Error::DnsResolversUnavailable),
306+
}?;
304307

305308
let hrn = maybe_convert_hrn(hrn);
306309

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)