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