Skip to content

Commit 7c1a2db

Browse files
committed
Add hrn_resolver to Node and pass into UnifiedPayment
This commit adds a HRN Resolver to the Node struct which will be useful for resolving HRNs when making BIP 353 payments. It also passes the HRN Resolver into UnifiedPayment.
1 parent 3564b5e commit 7c1a2db

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

src/builder.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ use std::sync::{Arc, Mutex, Once, RwLock};
8080
use std::time::SystemTime;
8181
use vss_client::headers::{FixedHeaders, LnurlAuthToJwtProvider, VssHeaderProvider};
8282

83+
use bitcoin_payment_instructions::onion_message_resolver::LDKOnionMessageDNSSECHrnResolver;
84+
8385
const VSS_HARDENED_CHILD_INDEX: u32 = 877;
8486
const VSS_LNURL_AUTH_HARDENED_CHILD_INDEX: u32 = 138;
8587
const LSPS_HARDENED_CHILD_INDEX: u32 = 577;
@@ -1454,6 +1456,8 @@ fn build_with_store_internal(
14541456
})?;
14551457
}
14561458

1459+
let hrn_resolver = Arc::new(LDKOnionMessageDNSSECHrnResolver::new(Arc::clone(&network_graph)));
1460+
14571461
// Initialize the PeerManager
14581462
let onion_messenger: Arc<OnionMessenger> = Arc::new(OnionMessenger::new(
14591463
Arc::clone(&keys_manager),
@@ -1463,7 +1467,7 @@ fn build_with_store_internal(
14631467
message_router,
14641468
Arc::clone(&channel_manager),
14651469
IgnoringMessageHandler {},
1466-
IgnoringMessageHandler {},
1470+
Arc::clone(&hrn_resolver),
14671471
IgnoringMessageHandler {},
14681472
));
14691473
let ephemeral_bytes: [u8; 32] = keys_manager.get_secure_random_bytes();
@@ -1589,6 +1593,12 @@ fn build_with_store_internal(
15891593
Arc::clone(&keys_manager),
15901594
));
15911595

1596+
let peer_manager_clone = Arc::clone(&peer_manager);
1597+
1598+
hrn_resolver.register_post_queue_action(Box::new(move || {
1599+
peer_manager_clone.process_events();
1600+
}));
1601+
15921602
liquidity_source.as_ref().map(|l| l.set_peer_manager(Arc::clone(&peer_manager)));
15931603

15941604
gossip_source.set_gossip_verifier(
@@ -1696,6 +1706,7 @@ fn build_with_store_internal(
16961706
is_running,
16971707
is_listening,
16981708
node_metrics,
1709+
hrn_resolver,
16991710
})
17001711
}
17011712

src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ use peer_store::{PeerInfo, PeerStore};
145145
use runtime::Runtime;
146146
use types::{
147147
Broadcaster, BumpTransactionEventHandler, ChainMonitor, ChannelManager, DynStore, Graph,
148-
KeysManager, OnionMessenger, PaymentStore, PeerManager, Router, Scorer, Sweeper, Wallet,
148+
HRNResolver, KeysManager, OnionMessenger, PaymentStore, PeerManager, Router, Scorer, Sweeper,
149+
Wallet,
149150
};
150151
pub use types::{ChannelDetails, CustomTlvRecord, PeerDetails, UserChannelId};
151152

@@ -205,6 +206,7 @@ pub struct Node {
205206
is_running: Arc<RwLock<bool>>,
206207
is_listening: Arc<AtomicBool>,
207208
node_metrics: Arc<RwLock<NodeMetrics>>,
209+
hrn_resolver: Arc<HRNResolver>,
208210
}
209211

210212
impl Node {
@@ -899,6 +901,7 @@ impl Node {
899901
self.bolt12_payment().into(),
900902
Arc::clone(&self.config),
901903
Arc::clone(&self.logger),
904+
Arc::clone(&self.hrn_resolver),
902905
)
903906
}
904907

@@ -919,6 +922,7 @@ impl Node {
919922
self.bolt12_payment(),
920923
Arc::clone(&self.config),
921924
Arc::clone(&self.logger),
925+
Arc::clone(&self.hrn_resolver),
922926
))
923927
}
924928

src/payment/unified.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,20 @@
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 crate::error::Error;
1518
use crate::ffi::maybe_wrap;
1619
use crate::logger::{log_error, LdkLogger, Logger};
1720
use crate::payment::{Bolt11Payment, Bolt12Payment, OnchainPayment};
21+
use crate::types::HRNResolver;
1822
use crate::Config;
1923

2024
use lightning::ln::channelmanager::PaymentId;
@@ -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.

src/types.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ use lightning_net_tokio::SocketDescriptor;
3636
use bitcoin::secp256k1::PublicKey;
3737
use bitcoin::OutPoint;
3838

39+
use bitcoin_payment_instructions::onion_message_resolver::LDKOnionMessageDNSSECHrnResolver;
40+
3941
use std::sync::{Arc, Mutex};
4042

4143
pub(crate) type DynStore = dyn KVStore + Sync + Send;
@@ -117,10 +119,12 @@ pub(crate) type OnionMessenger = lightning::onion_message::messenger::OnionMesse
117119
Arc<MessageRouter>,
118120
Arc<ChannelManager>,
119121
IgnoringMessageHandler,
120-
IgnoringMessageHandler,
122+
Arc<HRNResolver>,
121123
IgnoringMessageHandler,
122124
>;
123125

126+
pub(crate) type HRNResolver = LDKOnionMessageDNSSECHrnResolver<Arc<Graph>, Arc<Logger>>;
127+
124128
pub(crate) type MessageRouter = lightning::onion_message::messenger::DefaultMessageRouter<
125129
Arc<Graph>,
126130
Arc<Logger>,

0 commit comments

Comments
 (0)