Skip to content

Commit 5f28108

Browse files
committed
Introduce Bolt12PaymentHandler
1 parent f2bbafc commit 5f28108

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed

bindings/ldk_node.udl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ interface Node {
5252
PublicKey node_id();
5353
sequence<SocketAddress>? listening_addresses();
5454
Bolt11PaymentHandler bolt11_payment();
55+
Bolt12PaymentHandler bolt12_payment();
5556
SpontaneousPaymentHandler spontaneous_payment();
5657
OnchainPaymentHandler onchain_payment();
5758
[Throws=NodeError]
@@ -98,6 +99,9 @@ interface Bolt11PaymentHandler {
9899
Bolt11Invoice receive_variable_amount_via_jit_channel([ByRef]string description, u32 expiry_secs, u64? max_proportional_lsp_fee_limit_ppm_msat);
99100
};
100101

102+
interface Bolt12PaymentHandler {
103+
};
104+
101105
interface SpontaneousPaymentHandler {
102106
[Throws=NodeError]
103107
PaymentHash send(u64 amount_msat, PublicKey node_id);

src/lib.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ use gossip::GossipSource;
131131
use liquidity::LiquiditySource;
132132
use payment::payment_store::PaymentStore;
133133
use payment::{
134-
Bolt11PaymentHandler, OnchainPaymentHandler, PaymentDetails, SpontaneousPaymentHandler,
134+
Bolt11PaymentHandler, Bolt12PaymentHandler, OnchainPaymentHandler, PaymentDetails,
135+
SpontaneousPaymentHandler,
135136
};
136137
use peer_store::{PeerInfo, PeerStore};
137138
use types::{
@@ -758,6 +759,22 @@ impl Node {
758759
))
759760
}
760761

762+
/// Returns a payment handler allowing to create and pay [BOLT 12] offers and refunds.
763+
///
764+
/// [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
765+
pub fn bolt12_payment(&self) -> Arc<Bolt12PaymentHandler> {
766+
Arc::new(Bolt12PaymentHandler::new(
767+
Arc::clone(&self.runtime),
768+
Arc::clone(&self.channel_manager),
769+
Arc::clone(&self.connection_manager),
770+
Arc::clone(&self.keys_manager),
771+
Arc::clone(&self.payment_store),
772+
Arc::clone(&self.peer_store),
773+
Arc::clone(&self.config),
774+
Arc::clone(&self.logger),
775+
))
776+
}
777+
761778
/// Returns a payment handler allowing to send spontaneous ("keysend") payments.
762779
pub fn spontaneous_payment(&self) -> Arc<SpontaneousPaymentHandler> {
763780
Arc::new(SpontaneousPaymentHandler::new(

src/payment/bolt12.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//! Holds a payment handler allowing to create and pay [BOLT 12] offers and refunds.
2+
//!
3+
//! [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
4+
5+
use crate::config::Config;
6+
use crate::connection::ConnectionManager;
7+
use crate::logger::FilesystemLogger;
8+
use crate::payment::payment_store::PaymentStore;
9+
use crate::peer_store::PeerStore;
10+
use crate::types::{ChannelManager, KeysManager};
11+
12+
use std::sync::{Arc, RwLock};
13+
14+
/// A payment handler allowing to create and pay [BOLT 12] offers and refunds.
15+
///
16+
/// Should be retrieved by calling [`Node::bolt12_payment`].
17+
///
18+
/// [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
19+
/// [`Node::bolt12_payment`]: crate::Node::bolt12_payment
20+
pub struct Bolt12PaymentHandler {
21+
runtime: Arc<RwLock<Option<tokio::runtime::Runtime>>>,
22+
channel_manager: Arc<ChannelManager>,
23+
connection_manager: Arc<ConnectionManager<Arc<FilesystemLogger>>>,
24+
keys_manager: Arc<KeysManager>,
25+
payment_store: Arc<PaymentStore<Arc<FilesystemLogger>>>,
26+
peer_store: Arc<PeerStore<Arc<FilesystemLogger>>>,
27+
config: Arc<Config>,
28+
logger: Arc<FilesystemLogger>,
29+
}
30+
31+
impl Bolt12PaymentHandler {
32+
pub(crate) fn new(
33+
runtime: Arc<RwLock<Option<tokio::runtime::Runtime>>>,
34+
channel_manager: Arc<ChannelManager>,
35+
connection_manager: Arc<ConnectionManager<Arc<FilesystemLogger>>>,
36+
keys_manager: Arc<KeysManager>, payment_store: Arc<PaymentStore<Arc<FilesystemLogger>>>,
37+
peer_store: Arc<PeerStore<Arc<FilesystemLogger>>>, config: Arc<Config>,
38+
logger: Arc<FilesystemLogger>,
39+
) -> Self {
40+
Self {
41+
runtime,
42+
channel_manager,
43+
connection_manager,
44+
keys_manager,
45+
payment_store,
46+
peer_store,
47+
config,
48+
logger,
49+
}
50+
}
51+
}

src/payment/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
//! Objects for different types of payments.
22
33
mod bolt11;
4+
mod bolt12;
45
mod onchain;
56
pub(crate) mod payment_store;
67
mod spontaneous;
78

89
pub use bolt11::Bolt11PaymentHandler;
10+
pub use bolt12::Bolt12PaymentHandler;
911
pub use onchain::OnchainPaymentHandler;
1012
pub use payment_store::{LSPFeeLimits, PaymentDetails, PaymentDirection, PaymentStatus};
1113
pub use spontaneous::SpontaneousPaymentHandler;

0 commit comments

Comments
 (0)