Skip to content

Commit 4f14432

Browse files
committed
Introduce Bolt12PaymentHandler
1 parent dd89399 commit 4f14432

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-1
lines changed

bindings/ldk_node.udl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ interface Node {
5454
PublicKey node_id();
5555
sequence<SocketAddress>? listening_addresses();
5656
Bolt11Payment bolt11_payment();
57+
Bolt12PaymentHandler bolt12_payment();
5758
SpontaneousPayment spontaneous_payment();
5859
OnchainPayment onchain_payment();
5960
[Throws=NodeError]
@@ -99,6 +100,9 @@ interface Bolt11Payment {
99100
Bolt11Invoice receive_variable_amount_via_jit_channel([ByRef]string description, u32 expiry_secs, u64? max_proportional_lsp_fee_limit_ppm_msat);
100101
};
101102

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

src/lib.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ use event::{EventHandler, EventQueue};
130130
use gossip::GossipSource;
131131
use liquidity::LiquiditySource;
132132
use payment::payment_store::PaymentStore;
133-
use payment::{Bolt11Payment, OnchainPayment, PaymentDetails, SpontaneousPayment};
133+
use payment::{
134+
Bolt11Payment, Bolt12PaymentHandler, OnchainPayment, PaymentDetails, SpontaneousPayment,
135+
};
134136
use peer_store::{PeerInfo, PeerStore};
135137
use types::{
136138
Broadcaster, ChainMonitor, ChannelManager, DynStore, FeeEstimator, KeysManager, NetworkGraph,
@@ -846,6 +848,22 @@ impl Node {
846848
))
847849
}
848850

851+
/// Returns a payment handler allowing to create and pay [BOLT 12] offers and refunds.
852+
///
853+
/// [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
854+
pub fn bolt12_payment(&self) -> Arc<Bolt12PaymentHandler> {
855+
Arc::new(Bolt12PaymentHandler::new(
856+
Arc::clone(&self.runtime),
857+
Arc::clone(&self.channel_manager),
858+
Arc::clone(&self.connection_manager),
859+
Arc::clone(&self.keys_manager),
860+
Arc::clone(&self.payment_store),
861+
Arc::clone(&self.peer_store),
862+
Arc::clone(&self.config),
863+
Arc::clone(&self.logger),
864+
))
865+
}
866+
849867
/// Returns a payment handler allowing to send spontaneous ("keysend") payments.
850868
#[cfg(not(feature = "uniffi"))]
851869
pub fn spontaneous_payment(&self) -> SpontaneousPayment {

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::Bolt11Payment;
10+
pub use bolt12::Bolt12PaymentHandler;
911
pub use onchain::OnchainPayment;
1012
pub use payment_store::{LSPFeeLimits, PaymentDetails, PaymentDirection, PaymentStatus};
1113
pub use spontaneous::SpontaneousPayment;

0 commit comments

Comments
 (0)