Update auto-generated bindings
[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 javax.annotation.Nullable;
8
9
10 /**
11  * If a payment fails to send, it can be in one of several states. This enum is returned as the
12  * Err() type describing which state the payment is in, see the description of individual enum
13  * states for more.
14  */
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class PaymentSendFailure extends CommonBase {
17         private PaymentSendFailure(Object _dummy, long ptr) { super(ptr); }
18         @Override @SuppressWarnings("deprecation")
19         protected void finalize() throws Throwable {
20                 super.finalize();
21                 if (ptr != 0) { bindings.PaymentSendFailure_free(ptr); }
22         }
23         static PaymentSendFailure constr_from_ptr(long ptr) {
24                 bindings.LDKPaymentSendFailure raw_val = bindings.LDKPaymentSendFailure_ref_from_ptr(ptr);
25                 if (raw_val.getClass() == bindings.LDKPaymentSendFailure.ParameterError.class) {
26                         return new ParameterError(ptr, (bindings.LDKPaymentSendFailure.ParameterError)raw_val);
27                 }
28                 if (raw_val.getClass() == bindings.LDKPaymentSendFailure.PathParameterError.class) {
29                         return new PathParameterError(ptr, (bindings.LDKPaymentSendFailure.PathParameterError)raw_val);
30                 }
31                 if (raw_val.getClass() == bindings.LDKPaymentSendFailure.AllFailedRetrySafe.class) {
32                         return new AllFailedRetrySafe(ptr, (bindings.LDKPaymentSendFailure.AllFailedRetrySafe)raw_val);
33                 }
34                 if (raw_val.getClass() == bindings.LDKPaymentSendFailure.PartialFailure.class) {
35                         return new PartialFailure(ptr, (bindings.LDKPaymentSendFailure.PartialFailure)raw_val);
36                 }
37                 assert false; return null; // Unreachable without extending the (internal) bindings interface
38         }
39
40         /**
41          * A parameter which was passed to send_payment was invalid, preventing us from attempting to
42          * send the payment at all. No channel state has been changed or messages sent to peers, and
43          * once you've changed the parameter at error, you can freely retry the payment in full.
44          */
45         public final static class ParameterError extends PaymentSendFailure {
46                 public final APIError parameter_error;
47                 private ParameterError(long ptr, bindings.LDKPaymentSendFailure.ParameterError obj) {
48                         super(null, ptr);
49                         long parameter_error = obj.parameter_error;
50                         APIError parameter_error_hu_conv = APIError.constr_from_ptr(parameter_error);
51                         parameter_error_hu_conv.ptrs_to.add(this);
52                         this.parameter_error = parameter_error_hu_conv;
53                 }
54         }
55         /**
56          * A parameter in a single path which was passed to send_payment was invalid, preventing us
57          * from attempting to send the payment at all. No channel state has been changed or messages
58          * sent to peers, and once you've changed the parameter at error, you can freely retry the
59          * payment in full.
60          * 
61          * The results here are ordered the same as the paths in the route object which was passed to
62          * send_payment.
63          */
64         public final static class PathParameterError extends PaymentSendFailure {
65                 public final Result_NoneAPIErrorZ[] path_parameter_error;
66                 private PathParameterError(long ptr, bindings.LDKPaymentSendFailure.PathParameterError obj) {
67                         super(null, ptr);
68                         long[] path_parameter_error = obj.path_parameter_error;
69                         Result_NoneAPIErrorZ[] path_parameter_error_conv_22_arr = new Result_NoneAPIErrorZ[path_parameter_error.length];
70                         for (int w = 0; w < path_parameter_error.length; w++) {
71                                 long path_parameter_error_conv_22 = path_parameter_error[w];
72                                 Result_NoneAPIErrorZ path_parameter_error_conv_22_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(path_parameter_error_conv_22);
73                                 path_parameter_error_conv_22_arr[w] = path_parameter_error_conv_22_hu_conv;
74                         }
75                         this.path_parameter_error = path_parameter_error_conv_22_arr;
76                 }
77         }
78         /**
79          * All paths which were attempted failed to send, with no channel state change taking place.
80          * You can freely retry the payment in full (though you probably want to do so over different
81          * paths than the ones selected).
82          */
83         public final static class AllFailedRetrySafe extends PaymentSendFailure {
84                 public final APIError[] all_failed_retry_safe;
85                 private AllFailedRetrySafe(long ptr, bindings.LDKPaymentSendFailure.AllFailedRetrySafe obj) {
86                         super(null, ptr);
87                         long[] all_failed_retry_safe = obj.all_failed_retry_safe;
88                         APIError[] all_failed_retry_safe_conv_10_arr = new APIError[all_failed_retry_safe.length];
89                         for (int k = 0; k < all_failed_retry_safe.length; k++) {
90                                 long all_failed_retry_safe_conv_10 = all_failed_retry_safe[k];
91                                 APIError all_failed_retry_safe_conv_10_hu_conv = APIError.constr_from_ptr(all_failed_retry_safe_conv_10);
92                                 all_failed_retry_safe_conv_10_hu_conv.ptrs_to.add(this);
93                                 all_failed_retry_safe_conv_10_arr[k] = all_failed_retry_safe_conv_10_hu_conv;
94                         }
95                         this.all_failed_retry_safe = all_failed_retry_safe_conv_10_arr;
96                 }
97         }
98         /**
99          * Some paths which were attempted failed to send, though possibly not all. At least some
100          * paths have irrevocably committed to the HTLC and retrying the payment in full would result
101          * in over-/re-payment.
102          * 
103          * The results here are ordered the same as the paths in the route object which was passed to
104          * send_payment, and any Errs which are not APIError::MonitorUpdateFailed can be safely
105          * retried (though there is currently no API with which to do so).
106          * 
107          * Any entries which contain Err(APIError::MonitorUpdateFailed) or Ok(()) MUST NOT be retried
108          * as they will result in over-/re-payment. These HTLCs all either successfully sent (in the
109          * case of Ok(())) or will send once channel_monitor_updated is called on the next-hop channel
110          * with the latest update_id.
111          */
112         public final static class PartialFailure extends PaymentSendFailure {
113                 /**
114                  * The errors themselves, in the same order as the route hops.
115                 */
116                 public final Result_NoneAPIErrorZ[] results;
117                 /**
118                  * If some paths failed without irrevocably committing to the new HTLC(s), this will
119                  * contain a [`RouteParameters`] object which can be used to calculate a new route that
120                  * will pay all remaining unpaid balance.
121                  * 
122                  * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
123                 */
124                 @Nullable public final RouteParameters failed_paths_retry;
125                 /**
126                  * The payment id for the payment, which is now at least partially pending.
127                 */
128                 public final byte[] payment_id;
129                 private PartialFailure(long ptr, bindings.LDKPaymentSendFailure.PartialFailure obj) {
130                         super(null, ptr);
131                         long[] results = obj.results;
132                         Result_NoneAPIErrorZ[] results_conv_22_arr = new Result_NoneAPIErrorZ[results.length];
133                         for (int w = 0; w < results.length; w++) {
134                                 long results_conv_22 = results[w];
135                                 Result_NoneAPIErrorZ results_conv_22_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(results_conv_22);
136                                 results_conv_22_arr[w] = results_conv_22_hu_conv;
137                         }
138                         this.results = results_conv_22_arr;
139                         long failed_paths_retry = obj.failed_paths_retry;
140                         RouteParameters failed_paths_retry_hu_conv = null; if (failed_paths_retry < 0 || failed_paths_retry > 4096) { failed_paths_retry_hu_conv = new RouteParameters(null, failed_paths_retry); }
141                         failed_paths_retry_hu_conv.ptrs_to.add(this);
142                         this.failed_paths_retry = failed_paths_retry_hu_conv;
143                         this.payment_id = obj.payment_id;
144                 }
145         }
146         long clone_ptr() {
147                 long ret = bindings.PaymentSendFailure_clone_ptr(this.ptr);
148                 return ret;
149         }
150
151         /**
152          * Creates a copy of the PaymentSendFailure
153          */
154         public PaymentSendFailure clone() {
155                 long ret = bindings.PaymentSendFailure_clone(this.ptr);
156                 if (ret >= 0 && ret <= 4096) { return null; }
157                 PaymentSendFailure ret_hu_conv = PaymentSendFailure.constr_from_ptr(ret);
158                 ret_hu_conv.ptrs_to.add(this);
159                 return ret_hu_conv;
160         }
161
162         /**
163          * Utility method to constructs a new ParameterError-variant PaymentSendFailure
164          */
165         public static PaymentSendFailure parameter_error(APIError a) {
166                 long ret = bindings.PaymentSendFailure_parameter_error(a.ptr);
167                 if (ret >= 0 && ret <= 4096) { return null; }
168                 PaymentSendFailure ret_hu_conv = PaymentSendFailure.constr_from_ptr(ret);
169                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
170                 return ret_hu_conv;
171         }
172
173         /**
174          * Utility method to constructs a new PathParameterError-variant PaymentSendFailure
175          */
176         public static PaymentSendFailure path_parameter_error(Result_NoneAPIErrorZ[] a) {
177                 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);
178                 if (ret >= 0 && ret <= 4096) { return null; }
179                 PaymentSendFailure ret_hu_conv = PaymentSendFailure.constr_from_ptr(ret);
180                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
181                 return ret_hu_conv;
182         }
183
184         /**
185          * Utility method to constructs a new AllFailedRetrySafe-variant PaymentSendFailure
186          */
187         public static PaymentSendFailure all_failed_retry_safe(APIError[] a) {
188                 long ret = bindings.PaymentSendFailure_all_failed_retry_safe(a != null ? Arrays.stream(a).mapToLong(a_conv_10 -> a_conv_10.ptr).toArray() : null);
189                 if (ret >= 0 && ret <= 4096) { return null; }
190                 PaymentSendFailure ret_hu_conv = PaymentSendFailure.constr_from_ptr(ret);
191                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
192                 return ret_hu_conv;
193         }
194
195         /**
196          * Utility method to constructs a new PartialFailure-variant PaymentSendFailure
197          */
198         public static PaymentSendFailure partial_failure(Result_NoneAPIErrorZ[] results, RouteParameters failed_paths_retry, byte[] payment_id) {
199                 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 & ~1, InternalUtils.check_arr_len(payment_id, 32));
200                 if (ret >= 0 && ret <= 4096) { return null; }
201                 PaymentSendFailure ret_hu_conv = PaymentSendFailure.constr_from_ptr(ret);
202                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
203                 return ret_hu_conv;
204         }
205
206 }