[Java] Update auto-generated Java bindings for 0.0.113
[ldk-java] / src / main / java / org / ldk / structs / PaymentSendFailure.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10
11 /**
12  * If a payment fails to send, it can be in one of several states. This enum is returned as the
13  * Err() type describing which state the payment is in, see the description of individual enum
14  * states for more.
15  */
16 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
17 public class PaymentSendFailure extends CommonBase {
18         private PaymentSendFailure(Object _dummy, long ptr) { super(ptr); }
19         @Override @SuppressWarnings("deprecation")
20         protected void finalize() throws Throwable {
21                 super.finalize();
22                 if (ptr != 0) { bindings.PaymentSendFailure_free(ptr); }
23         }
24         static PaymentSendFailure constr_from_ptr(long ptr) {
25                 bindings.LDKPaymentSendFailure raw_val = bindings.LDKPaymentSendFailure_ref_from_ptr(ptr);
26                 if (raw_val.getClass() == bindings.LDKPaymentSendFailure.ParameterError.class) {
27                         return new ParameterError(ptr, (bindings.LDKPaymentSendFailure.ParameterError)raw_val);
28                 }
29                 if (raw_val.getClass() == bindings.LDKPaymentSendFailure.PathParameterError.class) {
30                         return new PathParameterError(ptr, (bindings.LDKPaymentSendFailure.PathParameterError)raw_val);
31                 }
32                 if (raw_val.getClass() == bindings.LDKPaymentSendFailure.AllFailedResendSafe.class) {
33                         return new AllFailedResendSafe(ptr, (bindings.LDKPaymentSendFailure.AllFailedResendSafe)raw_val);
34                 }
35                 if (raw_val.getClass() == bindings.LDKPaymentSendFailure.DuplicatePayment.class) {
36                         return new DuplicatePayment(ptr, (bindings.LDKPaymentSendFailure.DuplicatePayment)raw_val);
37                 }
38                 if (raw_val.getClass() == bindings.LDKPaymentSendFailure.PartialFailure.class) {
39                         return new PartialFailure(ptr, (bindings.LDKPaymentSendFailure.PartialFailure)raw_val);
40                 }
41                 assert false; return null; // Unreachable without extending the (internal) bindings interface
42         }
43
44         /**
45          * A parameter which was passed to send_payment was invalid, preventing us from attempting to
46          * send the payment at all.
47          * 
48          * You can freely resend the payment in full (with the parameter error fixed).
49          * 
50          * Because the payment failed outright, no payment tracking is done, you do not need to call
51          * [`ChannelManager::abandon_payment`] and [`ChannelManager::retry_payment`] will *not* work
52          * for this payment.
53          */
54         public final static class ParameterError extends PaymentSendFailure {
55                 public final org.ldk.structs.APIError parameter_error;
56                 private ParameterError(long ptr, bindings.LDKPaymentSendFailure.ParameterError obj) {
57                         super(null, ptr);
58                         long parameter_error = obj.parameter_error;
59                         org.ldk.structs.APIError parameter_error_hu_conv = org.ldk.structs.APIError.constr_from_ptr(parameter_error);
60                         if (parameter_error_hu_conv != null) { parameter_error_hu_conv.ptrs_to.add(this); };
61                         this.parameter_error = parameter_error_hu_conv;
62                 }
63         }
64         /**
65          * A parameter in a single path which was passed to send_payment was invalid, preventing us
66          * from attempting to send the payment at all.
67          * 
68          * You can freely resend the payment in full (with the parameter error fixed).
69          * 
70          * The results here are ordered the same as the paths in the route object which was passed to
71          * send_payment.
72          * 
73          * Because the payment failed outright, no payment tracking is done, you do not need to call
74          * [`ChannelManager::abandon_payment`] and [`ChannelManager::retry_payment`] will *not* work
75          * for this payment.
76          */
77         public final static class PathParameterError extends PaymentSendFailure {
78                 public final Result_NoneAPIErrorZ[] path_parameter_error;
79                 private PathParameterError(long ptr, bindings.LDKPaymentSendFailure.PathParameterError obj) {
80                         super(null, ptr);
81                         long[] path_parameter_error = obj.path_parameter_error;
82                         int path_parameter_error_conv_22_len = path_parameter_error.length;
83                         Result_NoneAPIErrorZ[] path_parameter_error_conv_22_arr = new Result_NoneAPIErrorZ[path_parameter_error_conv_22_len];
84                         for (int w = 0; w < path_parameter_error_conv_22_len; w++) {
85                                 long path_parameter_error_conv_22 = path_parameter_error[w];
86                                 Result_NoneAPIErrorZ path_parameter_error_conv_22_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(path_parameter_error_conv_22);
87                                 path_parameter_error_conv_22_arr[w] = path_parameter_error_conv_22_hu_conv;
88                         }
89                         this.path_parameter_error = path_parameter_error_conv_22_arr;
90                 }
91         }
92         /**
93          * All paths which were attempted failed to send, with no channel state change taking place.
94          * You can freely resend the payment in full (though you probably want to do so over different
95          * paths than the ones selected).
96          * 
97          * Because the payment failed outright, no payment tracking is done, you do not need to call
98          * [`ChannelManager::abandon_payment`] and [`ChannelManager::retry_payment`] will *not* work
99          * for this payment.
100          */
101         public final static class AllFailedResendSafe extends PaymentSendFailure {
102                 public final APIError[] all_failed_resend_safe;
103                 private AllFailedResendSafe(long ptr, bindings.LDKPaymentSendFailure.AllFailedResendSafe obj) {
104                         super(null, ptr);
105                         long[] all_failed_resend_safe = obj.all_failed_resend_safe;
106                         int all_failed_resend_safe_conv_10_len = all_failed_resend_safe.length;
107                         APIError[] all_failed_resend_safe_conv_10_arr = new APIError[all_failed_resend_safe_conv_10_len];
108                         for (int k = 0; k < all_failed_resend_safe_conv_10_len; k++) {
109                                 long all_failed_resend_safe_conv_10 = all_failed_resend_safe[k];
110                                 org.ldk.structs.APIError all_failed_resend_safe_conv_10_hu_conv = org.ldk.structs.APIError.constr_from_ptr(all_failed_resend_safe_conv_10);
111                                 if (all_failed_resend_safe_conv_10_hu_conv != null) { all_failed_resend_safe_conv_10_hu_conv.ptrs_to.add(this); };
112                                 all_failed_resend_safe_conv_10_arr[k] = all_failed_resend_safe_conv_10_hu_conv;
113                         }
114                         this.all_failed_resend_safe = all_failed_resend_safe_conv_10_arr;
115                 }
116         }
117         /**
118          * Indicates that a payment for the provided [`PaymentId`] is already in-flight and has not
119          * yet completed (i.e. generated an [`Event::PaymentSent`]) or been abandoned (via
120          * [`ChannelManager::abandon_payment`]).
121          * 
122          * [`Event::PaymentSent`]: events::Event::PaymentSent
123          */
124         public final static class DuplicatePayment extends PaymentSendFailure {
125                 private DuplicatePayment(long ptr, bindings.LDKPaymentSendFailure.DuplicatePayment obj) {
126                         super(null, ptr);
127                 }
128         }
129         /**
130          * Some paths which were attempted failed to send, though possibly not all. At least some
131          * paths have irrevocably committed to the HTLC and retrying the payment in full would result
132          * in over-/re-payment.
133          * 
134          * The results here are ordered the same as the paths in the route object which was passed to
135          * send_payment, and any `Err`s which are not [`APIError::MonitorUpdateInProgress`] can be
136          * safely retried via [`ChannelManager::retry_payment`].
137          * 
138          * Any entries which contain `Err(APIError::MonitorUpdateInprogress)` or `Ok(())` MUST NOT be
139          * retried as they will result in over-/re-payment. These HTLCs all either successfully sent
140          * (in the case of `Ok(())`) or will send once a [`MonitorEvent::Completed`] is provided for
141          * the next-hop channel with the latest update_id.
142          */
143         public final static class PartialFailure extends PaymentSendFailure {
144                 /**
145                  * The errors themselves, in the same order as the route hops.
146                 */
147                 public final Result_NoneAPIErrorZ[] results;
148                 /**
149                  * If some paths failed without irrevocably committing to the new HTLC(s), this will
150                  * contain a [`RouteParameters`] object which can be used to calculate a new route that
151                  * will pay all remaining unpaid balance.
152                  * 
153                  * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
154                 */
155                 @Nullable public final org.ldk.structs.RouteParameters failed_paths_retry;
156                 /**
157                  * The payment id for the payment, which is now at least partially pending.
158                 */
159                 public final byte[] payment_id;
160                 private PartialFailure(long ptr, bindings.LDKPaymentSendFailure.PartialFailure obj) {
161                         super(null, ptr);
162                         long[] results = obj.results;
163                         int results_conv_22_len = results.length;
164                         Result_NoneAPIErrorZ[] results_conv_22_arr = new Result_NoneAPIErrorZ[results_conv_22_len];
165                         for (int w = 0; w < results_conv_22_len; w++) {
166                                 long results_conv_22 = results[w];
167                                 Result_NoneAPIErrorZ results_conv_22_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(results_conv_22);
168                                 results_conv_22_arr[w] = results_conv_22_hu_conv;
169                         }
170                         this.results = results_conv_22_arr;
171                         long failed_paths_retry = obj.failed_paths_retry;
172                         org.ldk.structs.RouteParameters failed_paths_retry_hu_conv = null; if (failed_paths_retry < 0 || failed_paths_retry > 4096) { failed_paths_retry_hu_conv = new org.ldk.structs.RouteParameters(null, failed_paths_retry); }
173                         if (failed_paths_retry_hu_conv != null) { failed_paths_retry_hu_conv.ptrs_to.add(this); };
174                         this.failed_paths_retry = failed_paths_retry_hu_conv;
175                         this.payment_id = obj.payment_id;
176                 }
177         }
178         long clone_ptr() {
179                 long ret = bindings.PaymentSendFailure_clone_ptr(this.ptr);
180                 Reference.reachabilityFence(this);
181                 return ret;
182         }
183
184         /**
185          * Creates a copy of the PaymentSendFailure
186          */
187         public PaymentSendFailure clone() {
188                 long ret = bindings.PaymentSendFailure_clone(this.ptr);
189                 Reference.reachabilityFence(this);
190                 if (ret >= 0 && ret <= 4096) { return null; }
191                 org.ldk.structs.PaymentSendFailure ret_hu_conv = org.ldk.structs.PaymentSendFailure.constr_from_ptr(ret);
192                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
193                 return ret_hu_conv;
194         }
195
196         /**
197          * Utility method to constructs a new ParameterError-variant PaymentSendFailure
198          */
199         public static PaymentSendFailure parameter_error(org.ldk.structs.APIError a) {
200                 long ret = bindings.PaymentSendFailure_parameter_error(a.ptr);
201                 Reference.reachabilityFence(a);
202                 if (ret >= 0 && ret <= 4096) { return null; }
203                 org.ldk.structs.PaymentSendFailure ret_hu_conv = org.ldk.structs.PaymentSendFailure.constr_from_ptr(ret);
204                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
205                 return ret_hu_conv;
206         }
207
208         /**
209          * Utility method to constructs a new PathParameterError-variant PaymentSendFailure
210          */
211         public static PaymentSendFailure path_parameter_error(Result_NoneAPIErrorZ[] a) {
212                 long ret = bindings.PaymentSendFailure_path_parameter_error(a != null ? Arrays.stream(a).mapToLong(a_conv_22 -> a_conv_22 != null ? a_conv_22.ptr : 0).toArray() : null);
213                 Reference.reachabilityFence(a);
214                 if (ret >= 0 && ret <= 4096) { return null; }
215                 org.ldk.structs.PaymentSendFailure ret_hu_conv = org.ldk.structs.PaymentSendFailure.constr_from_ptr(ret);
216                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
217                 return ret_hu_conv;
218         }
219
220         /**
221          * Utility method to constructs a new AllFailedResendSafe-variant PaymentSendFailure
222          */
223         public static PaymentSendFailure all_failed_resend_safe(APIError[] a) {
224                 long ret = bindings.PaymentSendFailure_all_failed_resend_safe(a != null ? Arrays.stream(a).mapToLong(a_conv_10 -> a_conv_10.ptr).toArray() : null);
225                 Reference.reachabilityFence(a);
226                 if (ret >= 0 && ret <= 4096) { return null; }
227                 org.ldk.structs.PaymentSendFailure ret_hu_conv = org.ldk.structs.PaymentSendFailure.constr_from_ptr(ret);
228                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
229                 return ret_hu_conv;
230         }
231
232         /**
233          * Utility method to constructs a new DuplicatePayment-variant PaymentSendFailure
234          */
235         public static PaymentSendFailure duplicate_payment() {
236                 long ret = bindings.PaymentSendFailure_duplicate_payment();
237                 if (ret >= 0 && ret <= 4096) { return null; }
238                 org.ldk.structs.PaymentSendFailure ret_hu_conv = org.ldk.structs.PaymentSendFailure.constr_from_ptr(ret);
239                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
240                 return ret_hu_conv;
241         }
242
243         /**
244          * Utility method to constructs a new PartialFailure-variant PaymentSendFailure
245          */
246         public static PaymentSendFailure partial_failure(Result_NoneAPIErrorZ[] results, org.ldk.structs.RouteParameters failed_paths_retry, byte[] payment_id) {
247                 long ret = bindings.PaymentSendFailure_partial_failure(results != null ? Arrays.stream(results).mapToLong(results_conv_22 -> results_conv_22 != null ? results_conv_22.ptr : 0).toArray() : null, failed_paths_retry == null ? 0 : failed_paths_retry.ptr, InternalUtils.check_arr_len(payment_id, 32));
248                 Reference.reachabilityFence(results);
249                 Reference.reachabilityFence(failed_paths_retry);
250                 Reference.reachabilityFence(payment_id);
251                 if (ret >= 0 && ret <= 4096) { return null; }
252                 org.ldk.structs.PaymentSendFailure ret_hu_conv = org.ldk.structs.PaymentSendFailure.constr_from_ptr(ret);
253                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
254                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(failed_paths_retry); };
255                 return ret_hu_conv;
256         }
257
258 }