05afcdc2b8e1681ec8516947ee27189d5001a48b
[ldk-c-bindings] / lightning-c-bindings / src / lightning / ln / outbound_payment.rs
1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
3 //
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
8
9 //! Utilities to send payments and manage outbound payment information.
10
11 use alloc::str::FromStr;
12 use core::ffi::c_void;
13 use core::convert::Infallible;
14 use bitcoin::hashes::Hash;
15 use crate::c_types::*;
16 #[cfg(feature="no-std")]
17 use alloc::{vec::Vec, boxed::Box};
18
19 /// Strategies available to retry payment path failures.
20 #[derive(Clone)]
21 #[must_use]
22 #[repr(C)]
23 pub enum Retry {
24         /// Max number of attempts to retry payment.
25         ///
26         /// Each attempt may be multiple HTLCs along multiple paths if the router decides to split up a
27         /// retry, and may retry multiple failed HTLCs at once if they failed around the same time and
28         /// were retried along a route from a single call to [`Router::find_route_with_id`].
29         Attempts(
30                 usize),
31         /// Time elapsed before abandoning retries for a payment. At least one attempt at payment is made;
32         /// see [`PaymentParameters::expiry_time`] to avoid any attempt at payment after a specific time.
33         ///
34         /// [`PaymentParameters::expiry_time`]: crate::routing::router::PaymentParameters::expiry_time
35         Timeout(
36                 u64),
37 }
38 use lightning::ln::outbound_payment::Retry as RetryImport;
39 pub(crate) type nativeRetry = RetryImport;
40
41 impl Retry {
42         #[allow(unused)]
43         pub(crate) fn to_native(&self) -> nativeRetry {
44                 match self {
45                         Retry::Attempts (ref a, ) => {
46                                 let mut a_nonref = Clone::clone(a);
47                                 nativeRetry::Attempts (
48                                         a_nonref,
49                                 )
50                         },
51                         Retry::Timeout (ref a, ) => {
52                                 let mut a_nonref = Clone::clone(a);
53                                 nativeRetry::Timeout (
54                                         core::time::Duration::from_secs(a_nonref),
55                                 )
56                         },
57                 }
58         }
59         #[allow(unused)]
60         pub(crate) fn into_native(self) -> nativeRetry {
61                 match self {
62                         Retry::Attempts (mut a, ) => {
63                                 nativeRetry::Attempts (
64                                         a,
65                                 )
66                         },
67                         Retry::Timeout (mut a, ) => {
68                                 nativeRetry::Timeout (
69                                         core::time::Duration::from_secs(a),
70                                 )
71                         },
72                 }
73         }
74         #[allow(unused)]
75         pub(crate) fn from_native(native: &nativeRetry) -> Self {
76                 match native {
77                         nativeRetry::Attempts (ref a, ) => {
78                                 let mut a_nonref = Clone::clone(a);
79                                 Retry::Attempts (
80                                         a_nonref,
81                                 )
82                         },
83                         nativeRetry::Timeout (ref a, ) => {
84                                 let mut a_nonref = Clone::clone(a);
85                                 Retry::Timeout (
86                                         a_nonref.as_secs(),
87                                 )
88                         },
89                 }
90         }
91         #[allow(unused)]
92         pub(crate) fn native_into(native: nativeRetry) -> Self {
93                 match native {
94                         nativeRetry::Attempts (mut a, ) => {
95                                 Retry::Attempts (
96                                         a,
97                                 )
98                         },
99                         nativeRetry::Timeout (mut a, ) => {
100                                 Retry::Timeout (
101                                         a.as_secs(),
102                                 )
103                         },
104                 }
105         }
106 }
107 /// Frees any resources used by the Retry
108 #[no_mangle]
109 pub extern "C" fn Retry_free(this_ptr: Retry) { }
110 /// Creates a copy of the Retry
111 #[no_mangle]
112 pub extern "C" fn Retry_clone(orig: &Retry) -> Retry {
113         orig.clone()
114 }
115 #[no_mangle]
116 /// Utility method to constructs a new Attempts-variant Retry
117 pub extern "C" fn Retry_attempts(a: usize) -> Retry {
118         Retry::Attempts(a, )
119 }
120 #[no_mangle]
121 /// Utility method to constructs a new Timeout-variant Retry
122 pub extern "C" fn Retry_timeout(a: u64) -> Retry {
123         Retry::Timeout(a, )
124 }
125 /// Checks if two Retrys contain equal inner contents.
126 /// This ignores pointers and is_owned flags and looks at the values in fields.
127 #[no_mangle]
128 pub extern "C" fn Retry_eq(a: &Retry, b: &Retry) -> bool {
129         if &a.to_native() == &b.to_native() { true } else { false }
130 }
131 /// Generates a non-cryptographic 64-bit hash of the Retry.
132 #[no_mangle]
133 pub extern "C" fn Retry_hash(o: &Retry) -> u64 {
134         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
135         #[allow(deprecated)]
136         let mut hasher = core::hash::SipHasher::new();
137         core::hash::Hash::hash(&o.to_native(), &mut hasher);
138         core::hash::Hasher::finish(&hasher)
139 }
140 /// Indicates an immediate error on [`ChannelManager::send_payment`]. Further errors may be
141 /// surfaced later via [`Event::PaymentPathFailed`] and [`Event::PaymentFailed`].
142 ///
143 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
144 /// [`Event::PaymentPathFailed`]: crate::events::Event::PaymentPathFailed
145 /// [`Event::PaymentFailed`]: crate::events::Event::PaymentFailed
146 #[derive(Clone)]
147 #[must_use]
148 #[repr(C)]
149 pub enum RetryableSendFailure {
150         /// The provided [`PaymentParameters::expiry_time`] indicated that the payment has expired. Note
151         /// that this error is *not* caused by [`Retry::Timeout`].
152         ///
153         /// [`PaymentParameters::expiry_time`]: crate::routing::router::PaymentParameters::expiry_time
154         PaymentExpired,
155         /// We were unable to find a route to the destination.
156         RouteNotFound,
157         /// Indicates that a payment for the provided [`PaymentId`] is already in-flight and has not
158         /// yet completed (i.e. generated an [`Event::PaymentSent`] or [`Event::PaymentFailed`]).
159         ///
160         /// [`PaymentId`]: crate::ln::channelmanager::PaymentId
161         /// [`Event::PaymentSent`]: crate::events::Event::PaymentSent
162         /// [`Event::PaymentFailed`]: crate::events::Event::PaymentFailed
163         DuplicatePayment,
164 }
165 use lightning::ln::outbound_payment::RetryableSendFailure as RetryableSendFailureImport;
166 pub(crate) type nativeRetryableSendFailure = RetryableSendFailureImport;
167
168 impl RetryableSendFailure {
169         #[allow(unused)]
170         pub(crate) fn to_native(&self) -> nativeRetryableSendFailure {
171                 match self {
172                         RetryableSendFailure::PaymentExpired => nativeRetryableSendFailure::PaymentExpired,
173                         RetryableSendFailure::RouteNotFound => nativeRetryableSendFailure::RouteNotFound,
174                         RetryableSendFailure::DuplicatePayment => nativeRetryableSendFailure::DuplicatePayment,
175                 }
176         }
177         #[allow(unused)]
178         pub(crate) fn into_native(self) -> nativeRetryableSendFailure {
179                 match self {
180                         RetryableSendFailure::PaymentExpired => nativeRetryableSendFailure::PaymentExpired,
181                         RetryableSendFailure::RouteNotFound => nativeRetryableSendFailure::RouteNotFound,
182                         RetryableSendFailure::DuplicatePayment => nativeRetryableSendFailure::DuplicatePayment,
183                 }
184         }
185         #[allow(unused)]
186         pub(crate) fn from_native(native: &nativeRetryableSendFailure) -> Self {
187                 match native {
188                         nativeRetryableSendFailure::PaymentExpired => RetryableSendFailure::PaymentExpired,
189                         nativeRetryableSendFailure::RouteNotFound => RetryableSendFailure::RouteNotFound,
190                         nativeRetryableSendFailure::DuplicatePayment => RetryableSendFailure::DuplicatePayment,
191                 }
192         }
193         #[allow(unused)]
194         pub(crate) fn native_into(native: nativeRetryableSendFailure) -> Self {
195                 match native {
196                         nativeRetryableSendFailure::PaymentExpired => RetryableSendFailure::PaymentExpired,
197                         nativeRetryableSendFailure::RouteNotFound => RetryableSendFailure::RouteNotFound,
198                         nativeRetryableSendFailure::DuplicatePayment => RetryableSendFailure::DuplicatePayment,
199                 }
200         }
201 }
202 /// Creates a copy of the RetryableSendFailure
203 #[no_mangle]
204 pub extern "C" fn RetryableSendFailure_clone(orig: &RetryableSendFailure) -> RetryableSendFailure {
205         orig.clone()
206 }
207 #[no_mangle]
208 /// Utility method to constructs a new PaymentExpired-variant RetryableSendFailure
209 pub extern "C" fn RetryableSendFailure_payment_expired() -> RetryableSendFailure {
210         RetryableSendFailure::PaymentExpired}
211 #[no_mangle]
212 /// Utility method to constructs a new RouteNotFound-variant RetryableSendFailure
213 pub extern "C" fn RetryableSendFailure_route_not_found() -> RetryableSendFailure {
214         RetryableSendFailure::RouteNotFound}
215 #[no_mangle]
216 /// Utility method to constructs a new DuplicatePayment-variant RetryableSendFailure
217 pub extern "C" fn RetryableSendFailure_duplicate_payment() -> RetryableSendFailure {
218         RetryableSendFailure::DuplicatePayment}
219 /// Checks if two RetryableSendFailures contain equal inner contents.
220 /// This ignores pointers and is_owned flags and looks at the values in fields.
221 #[no_mangle]
222 pub extern "C" fn RetryableSendFailure_eq(a: &RetryableSendFailure, b: &RetryableSendFailure) -> bool {
223         if &a.to_native() == &b.to_native() { true } else { false }
224 }
225 /// If a payment fails to send with [`ChannelManager::send_payment_with_route`], it can be in one
226 /// of several states. This enum is returned as the Err() type describing which state the payment
227 /// is in, see the description of individual enum states for more.
228 ///
229 /// [`ChannelManager::send_payment_with_route`]: crate::ln::channelmanager::ChannelManager::send_payment_with_route
230 #[derive(Clone)]
231 #[must_use]
232 #[repr(C)]
233 pub enum PaymentSendFailure {
234         /// A parameter which was passed to send_payment was invalid, preventing us from attempting to
235         /// send the payment at all.
236         ///
237         /// You can freely resend the payment in full (with the parameter error fixed).
238         ///
239         /// Because the payment failed outright, no payment tracking is done and no
240         /// [`Event::PaymentPathFailed`] or [`Event::PaymentFailed`] events will be generated.
241         ///
242         /// [`Event::PaymentPathFailed`]: crate::events::Event::PaymentPathFailed
243         /// [`Event::PaymentFailed`]: crate::events::Event::PaymentFailed
244         ParameterError(
245                 crate::lightning::util::errors::APIError),
246         /// A parameter in a single path which was passed to send_payment was invalid, preventing us
247         /// from attempting to send the payment at all.
248         ///
249         /// You can freely resend the payment in full (with the parameter error fixed).
250         ///
251         /// Because the payment failed outright, no payment tracking is done and no
252         /// [`Event::PaymentPathFailed`] or [`Event::PaymentFailed`] events will be generated.
253         ///
254         /// The results here are ordered the same as the paths in the route object which was passed to
255         /// send_payment.
256         ///
257         /// [`Event::PaymentPathFailed`]: crate::events::Event::PaymentPathFailed
258         /// [`Event::PaymentFailed`]: crate::events::Event::PaymentFailed
259         PathParameterError(
260                 crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ),
261         /// All paths which were attempted failed to send, with no channel state change taking place.
262         /// You can freely resend the payment in full (though you probably want to do so over different
263         /// paths than the ones selected).
264         ///
265         /// Because the payment failed outright, no payment tracking is done and no
266         /// [`Event::PaymentPathFailed`] or [`Event::PaymentFailed`] events will be generated.
267         ///
268         /// [`Event::PaymentPathFailed`]: crate::events::Event::PaymentPathFailed
269         /// [`Event::PaymentFailed`]: crate::events::Event::PaymentFailed
270         AllFailedResendSafe(
271                 crate::c_types::derived::CVec_APIErrorZ),
272         /// Indicates that a payment for the provided [`PaymentId`] is already in-flight and has not
273         /// yet completed (i.e. generated an [`Event::PaymentSent`] or [`Event::PaymentFailed`]).
274         ///
275         /// [`PaymentId`]: crate::ln::channelmanager::PaymentId
276         /// [`Event::PaymentSent`]: crate::events::Event::PaymentSent
277         /// [`Event::PaymentFailed`]: crate::events::Event::PaymentFailed
278         DuplicatePayment,
279         /// Some paths that were attempted failed to send, though some paths may have succeeded. At least
280         /// some paths have irrevocably committed to the HTLC.
281         ///
282         /// The results here are ordered the same as the paths in the route object that was passed to
283         /// send_payment.
284         ///
285         /// Any entries that contain `Err(APIError::MonitorUpdateInprogress)` will send once a
286         /// [`MonitorEvent::Completed`] is provided for the next-hop channel with the latest update_id.
287         ///
288         /// [`MonitorEvent::Completed`]: crate::chain::channelmonitor::MonitorEvent::Completed
289         PartialFailure {
290                 /// The errors themselves, in the same order as the paths from the route.
291                 results: crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ,
292                 /// If some paths failed without irrevocably committing to the new HTLC(s), this will
293                 /// contain a [`RouteParameters`] object for the failing paths.
294                 ///
295                 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
296                 failed_paths_retry: crate::lightning::routing::router::RouteParameters,
297                 /// The payment id for the payment, which is now at least partially pending.
298                 payment_id: crate::c_types::ThirtyTwoBytes,
299         },
300 }
301 use lightning::ln::outbound_payment::PaymentSendFailure as PaymentSendFailureImport;
302 pub(crate) type nativePaymentSendFailure = PaymentSendFailureImport;
303
304 impl PaymentSendFailure {
305         #[allow(unused)]
306         pub(crate) fn to_native(&self) -> nativePaymentSendFailure {
307                 match self {
308                         PaymentSendFailure::ParameterError (ref a, ) => {
309                                 let mut a_nonref = Clone::clone(a);
310                                 nativePaymentSendFailure::ParameterError (
311                                         a_nonref.into_native(),
312                                 )
313                         },
314                         PaymentSendFailure::PathParameterError (ref a, ) => {
315                                 let mut a_nonref = Clone::clone(a);
316                                 let mut local_a_nonref = Vec::new(); for mut item in a_nonref.into_rust().drain(..) { local_a_nonref.push( { let mut local_a_nonref_0 = match item.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.result)) })*/ }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.err)) }).into_native() })}; local_a_nonref_0 }); };
317                                 nativePaymentSendFailure::PathParameterError (
318                                         local_a_nonref,
319                                 )
320                         },
321                         PaymentSendFailure::AllFailedResendSafe (ref a, ) => {
322                                 let mut a_nonref = Clone::clone(a);
323                                 let mut local_a_nonref = Vec::new(); for mut item in a_nonref.into_rust().drain(..) { local_a_nonref.push( { item.into_native() }); };
324                                 nativePaymentSendFailure::AllFailedResendSafe (
325                                         local_a_nonref,
326                                 )
327                         },
328                         PaymentSendFailure::DuplicatePayment => nativePaymentSendFailure::DuplicatePayment,
329                         PaymentSendFailure::PartialFailure {ref results, ref failed_paths_retry, ref payment_id, } => {
330                                 let mut results_nonref = Clone::clone(results);
331                                 let mut local_results_nonref = Vec::new(); for mut item in results_nonref.into_rust().drain(..) { local_results_nonref.push( { let mut local_results_nonref_0 = match item.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.result)) })*/ }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.err)) }).into_native() })}; local_results_nonref_0 }); };
332                                 let mut failed_paths_retry_nonref = Clone::clone(failed_paths_retry);
333                                 let mut local_failed_paths_retry_nonref = if failed_paths_retry_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(failed_paths_retry_nonref.take_inner()) } }) };
334                                 let mut payment_id_nonref = Clone::clone(payment_id);
335                                 nativePaymentSendFailure::PartialFailure {
336                                         results: local_results_nonref,
337                                         failed_paths_retry: local_failed_paths_retry_nonref,
338                                         payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
339                                 }
340                         },
341                 }
342         }
343         #[allow(unused)]
344         pub(crate) fn into_native(self) -> nativePaymentSendFailure {
345                 match self {
346                         PaymentSendFailure::ParameterError (mut a, ) => {
347                                 nativePaymentSendFailure::ParameterError (
348                                         a.into_native(),
349                                 )
350                         },
351                         PaymentSendFailure::PathParameterError (mut a, ) => {
352                                 let mut local_a = Vec::new(); for mut item in a.into_rust().drain(..) { local_a.push( { let mut local_a_0 = match item.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.result)) })*/ }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.err)) }).into_native() })}; local_a_0 }); };
353                                 nativePaymentSendFailure::PathParameterError (
354                                         local_a,
355                                 )
356                         },
357                         PaymentSendFailure::AllFailedResendSafe (mut a, ) => {
358                                 let mut local_a = Vec::new(); for mut item in a.into_rust().drain(..) { local_a.push( { item.into_native() }); };
359                                 nativePaymentSendFailure::AllFailedResendSafe (
360                                         local_a,
361                                 )
362                         },
363                         PaymentSendFailure::DuplicatePayment => nativePaymentSendFailure::DuplicatePayment,
364                         PaymentSendFailure::PartialFailure {mut results, mut failed_paths_retry, mut payment_id, } => {
365                                 let mut local_results = Vec::new(); for mut item in results.into_rust().drain(..) { local_results.push( { let mut local_results_0 = match item.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.result)) })*/ }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.err)) }).into_native() })}; local_results_0 }); };
366                                 let mut local_failed_paths_retry = if failed_paths_retry.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(failed_paths_retry.take_inner()) } }) };
367                                 nativePaymentSendFailure::PartialFailure {
368                                         results: local_results,
369                                         failed_paths_retry: local_failed_paths_retry,
370                                         payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
371                                 }
372                         },
373                 }
374         }
375         #[allow(unused)]
376         pub(crate) fn from_native(native: &nativePaymentSendFailure) -> Self {
377                 match native {
378                         nativePaymentSendFailure::ParameterError (ref a, ) => {
379                                 let mut a_nonref = Clone::clone(a);
380                                 PaymentSendFailure::ParameterError (
381                                         crate::lightning::util::errors::APIError::native_into(a_nonref),
382                                 )
383                         },
384                         nativePaymentSendFailure::PathParameterError (ref a, ) => {
385                                 let mut a_nonref = Clone::clone(a);
386                                 let mut local_a_nonref = Vec::new(); for mut item in a_nonref.drain(..) { local_a_nonref.push( { let mut local_a_nonref_0 = match item { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() }; local_a_nonref_0 }); };
387                                 PaymentSendFailure::PathParameterError (
388                                         local_a_nonref.into(),
389                                 )
390                         },
391                         nativePaymentSendFailure::AllFailedResendSafe (ref a, ) => {
392                                 let mut a_nonref = Clone::clone(a);
393                                 let mut local_a_nonref = Vec::new(); for mut item in a_nonref.drain(..) { local_a_nonref.push( { crate::lightning::util::errors::APIError::native_into(item) }); };
394                                 PaymentSendFailure::AllFailedResendSafe (
395                                         local_a_nonref.into(),
396                                 )
397                         },
398                         nativePaymentSendFailure::DuplicatePayment => PaymentSendFailure::DuplicatePayment,
399                         nativePaymentSendFailure::PartialFailure {ref results, ref failed_paths_retry, ref payment_id, } => {
400                                 let mut results_nonref = Clone::clone(results);
401                                 let mut local_results_nonref = Vec::new(); for mut item in results_nonref.drain(..) { local_results_nonref.push( { let mut local_results_nonref_0 = match item { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() }; local_results_nonref_0 }); };
402                                 let mut failed_paths_retry_nonref = Clone::clone(failed_paths_retry);
403                                 let mut local_failed_paths_retry_nonref = crate::lightning::routing::router::RouteParameters { inner: if failed_paths_retry_nonref.is_none() { core::ptr::null_mut() } else {  { ObjOps::heap_alloc((failed_paths_retry_nonref.unwrap())) } }, is_owned: true };
404                                 let mut payment_id_nonref = Clone::clone(payment_id);
405                                 PaymentSendFailure::PartialFailure {
406                                         results: local_results_nonref.into(),
407                                         failed_paths_retry: local_failed_paths_retry_nonref,
408                                         payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
409                                 }
410                         },
411                 }
412         }
413         #[allow(unused)]
414         pub(crate) fn native_into(native: nativePaymentSendFailure) -> Self {
415                 match native {
416                         nativePaymentSendFailure::ParameterError (mut a, ) => {
417                                 PaymentSendFailure::ParameterError (
418                                         crate::lightning::util::errors::APIError::native_into(a),
419                                 )
420                         },
421                         nativePaymentSendFailure::PathParameterError (mut a, ) => {
422                                 let mut local_a = Vec::new(); for mut item in a.drain(..) { local_a.push( { let mut local_a_0 = match item { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() }; local_a_0 }); };
423                                 PaymentSendFailure::PathParameterError (
424                                         local_a.into(),
425                                 )
426                         },
427                         nativePaymentSendFailure::AllFailedResendSafe (mut a, ) => {
428                                 let mut local_a = Vec::new(); for mut item in a.drain(..) { local_a.push( { crate::lightning::util::errors::APIError::native_into(item) }); };
429                                 PaymentSendFailure::AllFailedResendSafe (
430                                         local_a.into(),
431                                 )
432                         },
433                         nativePaymentSendFailure::DuplicatePayment => PaymentSendFailure::DuplicatePayment,
434                         nativePaymentSendFailure::PartialFailure {mut results, mut failed_paths_retry, mut payment_id, } => {
435                                 let mut local_results = Vec::new(); for mut item in results.drain(..) { local_results.push( { let mut local_results_0 = match item { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::util::errors::APIError::native_into(e) }).into() }; local_results_0 }); };
436                                 let mut local_failed_paths_retry = crate::lightning::routing::router::RouteParameters { inner: if failed_paths_retry.is_none() { core::ptr::null_mut() } else {  { ObjOps::heap_alloc((failed_paths_retry.unwrap())) } }, is_owned: true };
437                                 PaymentSendFailure::PartialFailure {
438                                         results: local_results.into(),
439                                         failed_paths_retry: local_failed_paths_retry,
440                                         payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
441                                 }
442                         },
443                 }
444         }
445 }
446 /// Frees any resources used by the PaymentSendFailure
447 #[no_mangle]
448 pub extern "C" fn PaymentSendFailure_free(this_ptr: PaymentSendFailure) { }
449 /// Creates a copy of the PaymentSendFailure
450 #[no_mangle]
451 pub extern "C" fn PaymentSendFailure_clone(orig: &PaymentSendFailure) -> PaymentSendFailure {
452         orig.clone()
453 }
454 #[no_mangle]
455 /// Utility method to constructs a new ParameterError-variant PaymentSendFailure
456 pub extern "C" fn PaymentSendFailure_parameter_error(a: crate::lightning::util::errors::APIError) -> PaymentSendFailure {
457         PaymentSendFailure::ParameterError(a, )
458 }
459 #[no_mangle]
460 /// Utility method to constructs a new PathParameterError-variant PaymentSendFailure
461 pub extern "C" fn PaymentSendFailure_path_parameter_error(a: crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ) -> PaymentSendFailure {
462         PaymentSendFailure::PathParameterError(a, )
463 }
464 #[no_mangle]
465 /// Utility method to constructs a new AllFailedResendSafe-variant PaymentSendFailure
466 pub extern "C" fn PaymentSendFailure_all_failed_resend_safe(a: crate::c_types::derived::CVec_APIErrorZ) -> PaymentSendFailure {
467         PaymentSendFailure::AllFailedResendSafe(a, )
468 }
469 #[no_mangle]
470 /// Utility method to constructs a new DuplicatePayment-variant PaymentSendFailure
471 pub extern "C" fn PaymentSendFailure_duplicate_payment() -> PaymentSendFailure {
472         PaymentSendFailure::DuplicatePayment}
473 #[no_mangle]
474 /// Utility method to constructs a new PartialFailure-variant PaymentSendFailure
475 pub extern "C" fn PaymentSendFailure_partial_failure(results: crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ, failed_paths_retry: crate::lightning::routing::router::RouteParameters, payment_id: crate::c_types::ThirtyTwoBytes) -> PaymentSendFailure {
476         PaymentSendFailure::PartialFailure {
477                 results,
478                 failed_paths_retry,
479                 payment_id,
480         }
481 }
482
483 use lightning::ln::outbound_payment::RecipientOnionFields as nativeRecipientOnionFieldsImport;
484 pub(crate) type nativeRecipientOnionFields = nativeRecipientOnionFieldsImport;
485
486 /// Information which is provided, encrypted, to the payment recipient when sending HTLCs.
487 ///
488 /// This should generally be constructed with data communicated to us from the recipient (via a
489 /// BOLT11 or BOLT12 invoice).
490 #[must_use]
491 #[repr(C)]
492 pub struct RecipientOnionFields {
493         /// A pointer to the opaque Rust object.
494
495         /// Nearly everywhere, inner must be non-null, however in places where
496         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
497         pub inner: *mut nativeRecipientOnionFields,
498         /// Indicates that this is the only struct which contains the same pointer.
499
500         /// Rust functions which take ownership of an object provided via an argument require
501         /// this to be true and invalidate the object pointed to by inner.
502         pub is_owned: bool,
503 }
504
505 impl Drop for RecipientOnionFields {
506         fn drop(&mut self) {
507                 if self.is_owned && !<*mut nativeRecipientOnionFields>::is_null(self.inner) {
508                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
509                 }
510         }
511 }
512 /// Frees any resources used by the RecipientOnionFields, if is_owned is set and inner is non-NULL.
513 #[no_mangle]
514 pub extern "C" fn RecipientOnionFields_free(this_obj: RecipientOnionFields) { }
515 #[allow(unused)]
516 /// Used only if an object of this type is returned as a trait impl by a method
517 pub(crate) extern "C" fn RecipientOnionFields_free_void(this_ptr: *mut c_void) {
518         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRecipientOnionFields) };
519 }
520 #[allow(unused)]
521 impl RecipientOnionFields {
522         pub(crate) fn get_native_ref(&self) -> &'static nativeRecipientOnionFields {
523                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
524         }
525         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRecipientOnionFields {
526                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
527         }
528         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
529         pub(crate) fn take_inner(mut self) -> *mut nativeRecipientOnionFields {
530                 assert!(self.is_owned);
531                 let ret = ObjOps::untweak_ptr(self.inner);
532                 self.inner = core::ptr::null_mut();
533                 ret
534         }
535 }
536 /// The [`PaymentSecret`] is an arbitrary 32 bytes provided by the recipient for us to repeat
537 /// in the onion. It is unrelated to `payment_hash` (or [`PaymentPreimage`]) and exists to
538 /// authenticate the sender to the recipient and prevent payment-probing (deanonymization)
539 /// attacks.
540 ///
541 /// If you do not have one, the [`Route`] you pay over must not contain multiple paths as
542 /// multi-path payments require a recipient-provided secret.
543 ///
544 /// Some implementations may reject spontaneous payments with payment secrets, so you may only
545 /// want to provide a secret for a spontaneous payment if MPP is needed and you know your
546 /// recipient will not reject it.
547 #[no_mangle]
548 pub extern "C" fn RecipientOnionFields_get_payment_secret(this_ptr: &RecipientOnionFields) -> crate::c_types::derived::COption_PaymentSecretZ {
549         let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_secret;
550         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_PaymentSecretZ::None } else { crate::c_types::derived::COption_PaymentSecretZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option<Enum> is otherwise un-expressable. */ { crate::c_types::ThirtyTwoBytes { data: (*inner_val.as_ref().unwrap()).clone().0 } }) };
551         local_inner_val
552 }
553 /// The [`PaymentSecret`] is an arbitrary 32 bytes provided by the recipient for us to repeat
554 /// in the onion. It is unrelated to `payment_hash` (or [`PaymentPreimage`]) and exists to
555 /// authenticate the sender to the recipient and prevent payment-probing (deanonymization)
556 /// attacks.
557 ///
558 /// If you do not have one, the [`Route`] you pay over must not contain multiple paths as
559 /// multi-path payments require a recipient-provided secret.
560 ///
561 /// Some implementations may reject spontaneous payments with payment secrets, so you may only
562 /// want to provide a secret for a spontaneous payment if MPP is needed and you know your
563 /// recipient will not reject it.
564 #[no_mangle]
565 pub extern "C" fn RecipientOnionFields_set_payment_secret(this_ptr: &mut RecipientOnionFields, mut val: crate::c_types::derived::COption_PaymentSecretZ) {
566         let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { ::lightning::ln::PaymentSecret({ val_opt.take() }.data) }})} };
567         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_secret = local_val;
568 }
569 /// The payment metadata serves a similar purpose as [`Self::payment_secret`] but is of
570 /// arbitrary length. This gives recipients substantially more flexibility to receive
571 /// additional data.
572 ///
573 /// In LDK, while the [`Self::payment_secret`] is fixed based on an internal authentication
574 /// scheme to authenticate received payments against expected payments and invoices, this field
575 /// is not used in LDK for received payments, and can be used to store arbitrary data in
576 /// invoices which will be received with the payment.
577 ///
578 /// Note that this field was added to the lightning specification more recently than
579 /// [`Self::payment_secret`] and while nearly all lightning senders support secrets, metadata
580 /// may not be supported as universally.
581 ///
582 /// Returns a copy of the field.
583 #[no_mangle]
584 pub extern "C" fn RecipientOnionFields_get_payment_metadata(this_ptr: &RecipientOnionFields) -> crate::c_types::derived::COption_CVec_u8ZZ {
585         let mut inner_val = this_ptr.get_native_mut_ref().payment_metadata.clone();
586         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_CVec_u8ZZ::None } else { crate::c_types::derived::COption_CVec_u8ZZ::Some( { let mut local_inner_val_0 = Vec::new(); for mut item in inner_val.unwrap().drain(..) { local_inner_val_0.push( { item }); }; local_inner_val_0.into() }) };
587         local_inner_val
588 }
589 /// The payment metadata serves a similar purpose as [`Self::payment_secret`] but is of
590 /// arbitrary length. This gives recipients substantially more flexibility to receive
591 /// additional data.
592 ///
593 /// In LDK, while the [`Self::payment_secret`] is fixed based on an internal authentication
594 /// scheme to authenticate received payments against expected payments and invoices, this field
595 /// is not used in LDK for received payments, and can be used to store arbitrary data in
596 /// invoices which will be received with the payment.
597 ///
598 /// Note that this field was added to the lightning specification more recently than
599 /// [`Self::payment_secret`] and while nearly all lightning senders support secrets, metadata
600 /// may not be supported as universally.
601 #[no_mangle]
602 pub extern "C" fn RecipientOnionFields_set_payment_metadata(this_ptr: &mut RecipientOnionFields, mut val: crate::c_types::derived::COption_CVec_u8ZZ) {
603         let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { let mut local_val_0 = Vec::new(); for mut item in { val_opt.take() }.into_rust().drain(..) { local_val_0.push( { item }); }; local_val_0 }})} };
604         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_metadata = local_val;
605 }
606 /// Constructs a new RecipientOnionFields given each field
607 #[must_use]
608 #[no_mangle]
609 pub extern "C" fn RecipientOnionFields_new(mut payment_secret_arg: crate::c_types::derived::COption_PaymentSecretZ, mut payment_metadata_arg: crate::c_types::derived::COption_CVec_u8ZZ) -> RecipientOnionFields {
610         let mut local_payment_secret_arg = { /*payment_secret_arg*/ let payment_secret_arg_opt = payment_secret_arg; if payment_secret_arg_opt.is_none() { None } else { Some({ { ::lightning::ln::PaymentSecret({ payment_secret_arg_opt.take() }.data) }})} };
611         let mut local_payment_metadata_arg = { /*payment_metadata_arg*/ let payment_metadata_arg_opt = payment_metadata_arg; if payment_metadata_arg_opt.is_none() { None } else { Some({ { let mut local_payment_metadata_arg_0 = Vec::new(); for mut item in { payment_metadata_arg_opt.take() }.into_rust().drain(..) { local_payment_metadata_arg_0.push( { item }); }; local_payment_metadata_arg_0 }})} };
612         RecipientOnionFields { inner: ObjOps::heap_alloc(nativeRecipientOnionFields {
613                 payment_secret: local_payment_secret_arg,
614                 payment_metadata: local_payment_metadata_arg,
615         }), is_owned: true }
616 }
617 impl Clone for RecipientOnionFields {
618         fn clone(&self) -> Self {
619                 Self {
620                         inner: if <*mut nativeRecipientOnionFields>::is_null(self.inner) { core::ptr::null_mut() } else {
621                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
622                         is_owned: true,
623                 }
624         }
625 }
626 #[allow(unused)]
627 /// Used only if an object of this type is returned as a trait impl by a method
628 pub(crate) extern "C" fn RecipientOnionFields_clone_void(this_ptr: *const c_void) -> *mut c_void {
629         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRecipientOnionFields)).clone() })) as *mut c_void
630 }
631 #[no_mangle]
632 /// Creates a copy of the RecipientOnionFields
633 pub extern "C" fn RecipientOnionFields_clone(orig: &RecipientOnionFields) -> RecipientOnionFields {
634         orig.clone()
635 }
636 /// Checks if two RecipientOnionFieldss contain equal inner contents.
637 /// This ignores pointers and is_owned flags and looks at the values in fields.
638 /// Two objects with NULL inner values will be considered "equal" here.
639 #[no_mangle]
640 pub extern "C" fn RecipientOnionFields_eq(a: &RecipientOnionFields, b: &RecipientOnionFields) -> bool {
641         if a.inner == b.inner { return true; }
642         if a.inner.is_null() || b.inner.is_null() { return false; }
643         if a.get_native_ref() == b.get_native_ref() { true } else { false }
644 }
645 #[no_mangle]
646 /// Serialize the RecipientOnionFields object into a byte array which can be read by RecipientOnionFields_read
647 pub extern "C" fn RecipientOnionFields_write(obj: &crate::lightning::ln::outbound_payment::RecipientOnionFields) -> crate::c_types::derived::CVec_u8Z {
648         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
649 }
650 #[no_mangle]
651 pub(crate) extern "C" fn RecipientOnionFields_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
652         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRecipientOnionFields) })
653 }
654 #[no_mangle]
655 /// Read a RecipientOnionFields from a byte array, created by RecipientOnionFields_write
656 pub extern "C" fn RecipientOnionFields_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RecipientOnionFieldsDecodeErrorZ {
657         let res: Result<lightning::ln::outbound_payment::RecipientOnionFields, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
658         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::outbound_payment::RecipientOnionFields { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
659         local_res
660 }
661 /// Creates a [`RecipientOnionFields`] from only a [`PaymentSecret`]. This is the most common
662 /// set of onion fields for today's BOLT11 invoices - most nodes require a [`PaymentSecret`]
663 /// but do not require or provide any further data.
664 #[must_use]
665 #[no_mangle]
666 pub extern "C" fn RecipientOnionFields_secret_only(mut payment_secret: crate::c_types::ThirtyTwoBytes) -> crate::lightning::ln::outbound_payment::RecipientOnionFields {
667         let mut ret = lightning::ln::outbound_payment::RecipientOnionFields::secret_only(::lightning::ln::PaymentSecret(payment_secret.data));
668         crate::lightning::ln::outbound_payment::RecipientOnionFields { inner: ObjOps::heap_alloc(ret), is_owned: true }
669 }
670
671 /// Creates a new [`RecipientOnionFields`] with no fields. This generally does not create
672 /// payable HTLCs except for single-path spontaneous payments, i.e. this should generally
673 /// only be used for calls to [`ChannelManager::send_spontaneous_payment`]. If you are sending
674 /// a spontaneous MPP this will not work as all MPP require payment secrets; you may
675 /// instead want to use [`RecipientOnionFields::secret_only`].
676 ///
677 /// [`ChannelManager::send_spontaneous_payment`]: super::channelmanager::ChannelManager::send_spontaneous_payment
678 /// [`RecipientOnionFields::secret_only`]: RecipientOnionFields::secret_only
679 #[must_use]
680 #[no_mangle]
681 pub extern "C" fn RecipientOnionFields_spontaneous_empty() -> crate::lightning::ln::outbound_payment::RecipientOnionFields {
682         let mut ret = lightning::ln::outbound_payment::RecipientOnionFields::spontaneous_empty();
683         crate::lightning::ln::outbound_payment::RecipientOnionFields { inner: ObjOps::heap_alloc(ret), is_owned: true }
684 }
685