Skip to content

Commit 4024e92

Browse files
committed
Add HRN resolver to Node and UnifiedPayment
Introduce the hrn_resolver dependency into the main Node struct and plumb it through to the UnifiedPayment component. This is necessary to allow the node to resolve offers presented via a Human-Readable Name (HRN).
1 parent 6d9a957 commit 4024e92

File tree

4 files changed

+39
-8
lines changed

4 files changed

+39
-8
lines changed

src/builder.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ use bitcoin::bip32::{ChildNumber, Xpriv};
1919
use bitcoin::key::Secp256k1;
2020
use bitcoin::secp256k1::PublicKey;
2121
use bitcoin::{BlockHash, Network};
22+
23+
use bitcoin_payment_instructions::onion_message_resolver::LDKOnionMessageDNSSECHrnResolver;
24+
2225
use lightning::chain::{chainmonitor, BestBlock, Watch};
2326
use lightning::io::Cursor;
2427
use lightning::ln::channelmanager::{self, ChainParameters, ChannelManagerReadArgs};
@@ -1439,6 +1442,8 @@ fn build_with_store_internal(
14391442
})?;
14401443
}
14411444

1445+
let hrn_resolver = Arc::new(LDKOnionMessageDNSSECHrnResolver::new(Arc::clone(&network_graph)));
1446+
14421447
// Initialize the PeerManager
14431448
let onion_messenger: Arc<OnionMessenger> =
14441449
if let Some(AsyncPaymentsRole::Server) = async_payments_role {
@@ -1450,7 +1455,7 @@ fn build_with_store_internal(
14501455
message_router,
14511456
Arc::clone(&channel_manager),
14521457
Arc::clone(&channel_manager),
1453-
IgnoringMessageHandler {},
1458+
Arc::clone(&hrn_resolver),
14541459
IgnoringMessageHandler {},
14551460
))
14561461
} else {
@@ -1462,7 +1467,7 @@ fn build_with_store_internal(
14621467
message_router,
14631468
Arc::clone(&channel_manager),
14641469
Arc::clone(&channel_manager),
1465-
IgnoringMessageHandler {},
1470+
Arc::clone(&hrn_resolver),
14661471
IgnoringMessageHandler {},
14671472
))
14681473
};
@@ -1594,6 +1599,12 @@ fn build_with_store_internal(
15941599
Arc::clone(&keys_manager),
15951600
));
15961601

1602+
let peer_manager_clone = Arc::clone(&peer_manager);
1603+
1604+
hrn_resolver.register_post_queue_action(Box::new(move || {
1605+
peer_manager_clone.process_events();
1606+
}));
1607+
15971608
liquidity_source.as_ref().map(|l| l.set_peer_manager(Arc::clone(&peer_manager)));
15981609

15991610
gossip_source.set_gossip_verifier(
@@ -1701,6 +1712,7 @@ fn build_with_store_internal(
17011712
node_metrics,
17021713
om_mailbox,
17031714
async_payments_role,
1715+
hrn_resolver,
17041716
})
17051717
}
17061718

src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ use rand::Rng;
159159
use runtime::Runtime;
160160
use types::{
161161
Broadcaster, BumpTransactionEventHandler, ChainMonitor, ChannelManager, DynStore, Graph,
162-
KeysManager, OnionMessenger, PaymentStore, PeerManager, Router, Scorer, Sweeper, Wallet,
162+
HRNResolver, KeysManager, OnionMessenger, PaymentStore, PeerManager, Router, Scorer, Sweeper,
163+
Wallet,
163164
};
164165
pub use types::{ChannelDetails, CustomTlvRecord, PeerDetails, SyncAndAsyncKVStore, UserChannelId};
165166
pub use {
@@ -206,6 +207,7 @@ pub struct Node {
206207
node_metrics: Arc<RwLock<NodeMetrics>>,
207208
om_mailbox: Option<Arc<OnionMessageMailbox>>,
208209
async_payments_role: Option<AsyncPaymentsRole>,
210+
hrn_resolver: Arc<HRNResolver>,
209211
}
210212

211213
impl Node {
@@ -959,6 +961,7 @@ impl Node {
959961
self.bolt12_payment().into(),
960962
Arc::clone(&self.config),
961963
Arc::clone(&self.logger),
964+
Arc::clone(&self.hrn_resolver),
962965
)
963966
}
964967

@@ -979,6 +982,7 @@ impl Node {
979982
self.bolt12_payment(),
980983
Arc::clone(&self.config),
981984
Arc::clone(&self.logger),
985+
Arc::clone(&self.hrn_resolver),
982986
))
983987
}
984988

src/payment/unified.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
66
// accordance with one or both of these licenses.
77

8-
//! Holds a payment handler allowing to create [BIP 21] URIs with an on-chain, [BOLT 11], and [BOLT 12] payment
8+
//! Holds a payment handler allowing to create [BIP 21] URIs with on-chain, [BOLT 11], and [BOLT 12] payment
99
//! options.
1010
//!
11+
//! Also allows to send payments using these URIs as well as [BIP 353] HRNs.
12+
//!
1113
//! [BIP 21]: https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki
14+
//! [BIP 353]: https://github.com/bitcoin/bips/blob/master/bip-0353.mediawiki
1215
//! [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
1316
//! [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
1417
use std::sync::Arc;
@@ -27,6 +30,7 @@ use crate::error::Error;
2730
use crate::ffi::maybe_wrap;
2831
use crate::logger::{log_error, LdkLogger, Logger};
2932
use crate::payment::{Bolt11Payment, Bolt12Payment, OnchainPayment};
33+
use crate::types::HRNResolver;
3034
use crate::Config;
3135

3236
type Uri<'a> = bip21::Uri<'a, NetworkChecked, Extras>;
@@ -40,26 +44,31 @@ struct Extras {
4044
/// A payment handler allowing to create [BIP 21] URIs with an on-chain, [BOLT 11], and [BOLT 12] payment
4145
/// option.
4246
///
43-
/// Should be retrieved by calling [`Node::unified_qr_payment`]
47+
/// Should be retrieved by calling [`Node::unified_payment`]
48+
///
49+
/// This handler allows you to send payments to these URIs as well as [BIP 353] HRNs.
4450
///
4551
/// [BIP 21]: https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki
52+
/// [BIP 353]: https://github.com/bitcoin/bips/blob/master/bip-0353.mediawiki
4653
/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
4754
/// [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
48-
/// [`Node::unified_qr_payment`]: crate::Node::unified_qr_payment
55+
/// [`Node::unified_payment`]: crate::Node::unified_payment
4956
pub struct UnifiedPayment {
5057
onchain_payment: Arc<OnchainPayment>,
5158
bolt11_invoice: Arc<Bolt11Payment>,
5259
bolt12_payment: Arc<Bolt12Payment>,
5360
config: Arc<Config>,
5461
logger: Arc<Logger>,
62+
hrn_resolver: Arc<HRNResolver>,
5563
}
5664

5765
impl UnifiedPayment {
5866
pub(crate) fn new(
5967
onchain_payment: Arc<OnchainPayment>, bolt11_invoice: Arc<Bolt11Payment>,
6068
bolt12_payment: Arc<Bolt12Payment>, config: Arc<Config>, logger: Arc<Logger>,
69+
hrn_resolver: Arc<HRNResolver>,
6170
) -> Self {
62-
Self { onchain_payment, bolt11_invoice, bolt12_payment, config, logger }
71+
Self { onchain_payment, bolt11_invoice, bolt12_payment, config, logger, hrn_resolver }
6372
}
6473

6574
/// Generates a URI with an on-chain address, [BOLT 11] invoice and [BOLT 12] offer.
@@ -148,6 +157,8 @@ impl UnifiedPayment {
148157
let uri: bip21::Uri<NetworkUnchecked, Extras> =
149158
uri_str.parse().map_err(|_| Error::InvalidUri)?;
150159

160+
let _resolver = &self.hrn_resolver;
161+
151162
let uri_network_checked =
152163
uri.clone().require_network(self.config.network).map_err(|_| Error::InvalidNetwork)?;
153164

src/types.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ use lightning_block_sync::gossip::GossipVerifier;
2929
use lightning_liquidity::utils::time::DefaultTimeProvider;
3030
use lightning_net_tokio::SocketDescriptor;
3131

32+
use bitcoin_payment_instructions::onion_message_resolver::LDKOnionMessageDNSSECHrnResolver;
33+
3234
use crate::chain::bitcoind::UtxoSourceClient;
3335
use crate::chain::ChainSource;
3436
use crate::config::ChannelConfig;
@@ -276,10 +278,12 @@ pub(crate) type OnionMessenger = lightning::onion_message::messenger::OnionMesse
276278
Arc<MessageRouter>,
277279
Arc<ChannelManager>,
278280
Arc<ChannelManager>,
279-
IgnoringMessageHandler,
281+
Arc<HRNResolver>,
280282
IgnoringMessageHandler,
281283
>;
282284

285+
pub(crate) type HRNResolver = LDKOnionMessageDNSSECHrnResolver<Arc<Graph>, Arc<Logger>>;
286+
283287
pub(crate) type MessageRouter = lightning::onion_message::messenger::DefaultMessageRouter<
284288
Arc<Graph>,
285289
Arc<Logger>,

0 commit comments

Comments
 (0)