ldk_node/payment/mod.rs
1// This file is Copyright its original authors, visible in version control history.
2//
3// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
6// accordance with one or both of these licenses.
7
8//! Objects for different types of payments.
9
10mod bolt11;
11mod bolt12;
12mod onchain;
13mod spontaneous;
14pub(crate) mod store;
15mod unified_qr;
16
17pub use bolt11::Bolt11Payment;
18pub use bolt12::Bolt12Payment;
19pub use onchain::OnchainPayment;
20pub use spontaneous::SpontaneousPayment;
21pub use store::{
22 ConfirmationStatus, LSPFeeLimits, PaymentDetails, PaymentDirection, PaymentKind, PaymentStatus,
23};
24pub use unified_qr::{QrPaymentResult, UnifiedQrPayment};
25
26/// Represents information used to send a payment.
27#[derive(Clone, Debug, PartialEq)]
28pub struct SendingParameters {
29 /// The maximum total fees, in millisatoshi, that may accrue during route finding.
30 ///
31 /// This limit also applies to the total fees that may arise while retrying failed payment
32 /// paths.
33 ///
34 /// Note that values below a few sats may result in some paths being spuriously ignored.
35 #[cfg(not(feature = "uniffi"))]
36 pub max_total_routing_fee_msat: Option<Option<u64>>,
37 /// The maximum total fees, in millisatoshi, that may accrue during route finding.
38 ///
39 /// This limit also applies to the total fees that may arise while retrying failed payment
40 /// paths.
41 ///
42 /// Note that values below a few sats may result in some paths being spuriously ignored.
43 #[cfg(feature = "uniffi")]
44 pub max_total_routing_fee_msat: Option<MaxTotalRoutingFeeLimit>,
45 /// The maximum total CLTV delta we accept for the route.
46 ///
47 /// Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
48 ///
49 /// [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`]: lightning::routing::router::DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA
50 pub max_total_cltv_expiry_delta: Option<u32>,
51 /// The maximum number of paths that may be used by (MPP) payments.
52 ///
53 /// Defaults to [`DEFAULT_MAX_PATH_COUNT`].
54 ///
55 /// [`DEFAULT_MAX_PATH_COUNT`]: lightning::routing::router::DEFAULT_MAX_PATH_COUNT
56 pub max_path_count: Option<u8>,
57 /// Selects the maximum share of a channel's total capacity which will be sent over a channel,
58 /// as a power of 1/2.
59 ///
60 /// A higher value prefers to send the payment using more MPP parts whereas
61 /// a lower value prefers to send larger MPP parts, potentially saturating channels and
62 /// increasing failure probability for those paths.
63 ///
64 /// Note that this restriction will be relaxed during pathfinding after paths which meet this
65 /// restriction have been found. While paths which meet this criteria will be searched for, it
66 /// is ultimately up to the scorer to select them over other paths.
67 ///
68 /// Examples:
69 ///
70 /// | Value | Max Proportion of Channel Capacity Used |
71 /// |-------|-----------------------------------------|
72 /// | 0 | Up to 100% of the channel’s capacity |
73 /// | 1 | Up to 50% of the channel’s capacity |
74 /// | 2 | Up to 25% of the channel’s capacity |
75 /// | 3 | Up to 12.5% of the channel’s capacity |
76 ///
77 /// Default value: 2
78 pub max_channel_saturation_power_of_half: Option<u8>,
79}
80
81/// Represents the possible states of [`SendingParameters::max_total_routing_fee_msat`].
82//
83// Required only in bindings as UniFFI can't expose `Option<Option<..>>`.
84#[cfg(feature = "uniffi")]
85#[derive(Copy, Clone, Debug, PartialEq, Eq)]
86pub enum MaxTotalRoutingFeeLimit {
87 None,
88 Some { amount_msat: u64 },
89}
90
91#[cfg(feature = "uniffi")]
92impl From<MaxTotalRoutingFeeLimit> for Option<u64> {
93 fn from(value: MaxTotalRoutingFeeLimit) -> Self {
94 match value {
95 MaxTotalRoutingFeeLimit::Some { amount_msat } => Some(amount_msat),
96 MaxTotalRoutingFeeLimit::None => None,
97 }
98 }
99}
100
101#[cfg(feature = "uniffi")]
102impl From<Option<u64>> for MaxTotalRoutingFeeLimit {
103 fn from(value: Option<u64>) -> Self {
104 value.map_or(MaxTotalRoutingFeeLimit::None, |amount_msat| MaxTotalRoutingFeeLimit::Some {
105 amount_msat,
106 })
107 }
108}