1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
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
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 {
22 if (ptr != 0) { bindings.PaymentSendFailure_free(ptr); }
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);
29 if (raw_val.getClass() == bindings.LDKPaymentSendFailure.PathParameterError.class) {
30 return new PathParameterError(ptr, (bindings.LDKPaymentSendFailure.PathParameterError)raw_val);
32 if (raw_val.getClass() == bindings.LDKPaymentSendFailure.AllFailedRetrySafe.class) {
33 return new AllFailedRetrySafe(ptr, (bindings.LDKPaymentSendFailure.AllFailedRetrySafe)raw_val);
35 if (raw_val.getClass() == bindings.LDKPaymentSendFailure.PartialFailure.class) {
36 return new PartialFailure(ptr, (bindings.LDKPaymentSendFailure.PartialFailure)raw_val);
38 assert false; return null; // Unreachable without extending the (internal) bindings interface
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.
46 public final static class ParameterError extends PaymentSendFailure {
47 public final APIError parameter_error;
48 private ParameterError(long ptr, bindings.LDKPaymentSendFailure.ParameterError obj) {
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;
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
62 * The results here are ordered the same as the paths in the route object which was passed to
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) {
69 long[] path_parameter_error = obj.path_parameter_error;
70 int path_parameter_error_conv_22_len = path_parameter_error.length;
71 Result_NoneAPIErrorZ[] path_parameter_error_conv_22_arr = new Result_NoneAPIErrorZ[path_parameter_error_conv_22_len];
72 for (int w = 0; w < path_parameter_error_conv_22_len; w++) {
73 long path_parameter_error_conv_22 = path_parameter_error[w];
74 Result_NoneAPIErrorZ path_parameter_error_conv_22_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(path_parameter_error_conv_22);
75 path_parameter_error_conv_22_arr[w] = path_parameter_error_conv_22_hu_conv;
77 this.path_parameter_error = path_parameter_error_conv_22_arr;
81 * All paths which were attempted failed to send, with no channel state change taking place.
82 * You can freely retry the payment in full (though you probably want to do so over different
83 * paths than the ones selected).
85 public final static class AllFailedRetrySafe extends PaymentSendFailure {
86 public final APIError[] all_failed_retry_safe;
87 private AllFailedRetrySafe(long ptr, bindings.LDKPaymentSendFailure.AllFailedRetrySafe obj) {
89 long[] all_failed_retry_safe = obj.all_failed_retry_safe;
90 int all_failed_retry_safe_conv_10_len = all_failed_retry_safe.length;
91 APIError[] all_failed_retry_safe_conv_10_arr = new APIError[all_failed_retry_safe_conv_10_len];
92 for (int k = 0; k < all_failed_retry_safe_conv_10_len; k++) {
93 long all_failed_retry_safe_conv_10 = all_failed_retry_safe[k];
94 APIError all_failed_retry_safe_conv_10_hu_conv = APIError.constr_from_ptr(all_failed_retry_safe_conv_10);
95 all_failed_retry_safe_conv_10_hu_conv.ptrs_to.add(this);
96 all_failed_retry_safe_conv_10_arr[k] = all_failed_retry_safe_conv_10_hu_conv;
98 this.all_failed_retry_safe = all_failed_retry_safe_conv_10_arr;
102 * Some paths which were attempted failed to send, though possibly not all. At least some
103 * paths have irrevocably committed to the HTLC and retrying the payment in full would result
104 * in over-/re-payment.
106 * The results here are ordered the same as the paths in the route object which was passed to
107 * send_payment, and any Errs which are not APIError::MonitorUpdateFailed can be safely
108 * retried (though there is currently no API with which to do so).
110 * Any entries which contain Err(APIError::MonitorUpdateFailed) or Ok(()) MUST NOT be retried
111 * as they will result in over-/re-payment. These HTLCs all either successfully sent (in the
112 * case of Ok(())) or will send once channel_monitor_updated is called on the next-hop channel
113 * with the latest update_id.
115 public final static class PartialFailure extends PaymentSendFailure {
117 * The errors themselves, in the same order as the route hops.
119 public final Result_NoneAPIErrorZ[] results;
121 * If some paths failed without irrevocably committing to the new HTLC(s), this will
122 * contain a [`RouteParameters`] object which can be used to calculate a new route that
123 * will pay all remaining unpaid balance.
125 * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
127 @Nullable public final RouteParameters failed_paths_retry;
129 * The payment id for the payment, which is now at least partially pending.
131 public final byte[] payment_id;
132 private PartialFailure(long ptr, bindings.LDKPaymentSendFailure.PartialFailure obj) {
134 long[] results = obj.results;
135 int results_conv_22_len = results.length;
136 Result_NoneAPIErrorZ[] results_conv_22_arr = new Result_NoneAPIErrorZ[results_conv_22_len];
137 for (int w = 0; w < results_conv_22_len; w++) {
138 long results_conv_22 = results[w];
139 Result_NoneAPIErrorZ results_conv_22_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(results_conv_22);
140 results_conv_22_arr[w] = results_conv_22_hu_conv;
142 this.results = results_conv_22_arr;
143 long failed_paths_retry = obj.failed_paths_retry;
144 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); }
145 failed_paths_retry_hu_conv.ptrs_to.add(this);
146 this.failed_paths_retry = failed_paths_retry_hu_conv;
147 this.payment_id = obj.payment_id;
151 long ret = bindings.PaymentSendFailure_clone_ptr(this.ptr);
152 Reference.reachabilityFence(this);
157 * Creates a copy of the PaymentSendFailure
159 public PaymentSendFailure clone() {
160 long ret = bindings.PaymentSendFailure_clone(this.ptr);
161 Reference.reachabilityFence(this);
162 if (ret >= 0 && ret <= 4096) { return null; }
163 PaymentSendFailure ret_hu_conv = PaymentSendFailure.constr_from_ptr(ret);
164 ret_hu_conv.ptrs_to.add(this);
169 * Utility method to constructs a new ParameterError-variant PaymentSendFailure
171 public static PaymentSendFailure parameter_error(APIError a) {
172 long ret = bindings.PaymentSendFailure_parameter_error(a.ptr);
173 Reference.reachabilityFence(a);
174 if (ret >= 0 && ret <= 4096) { return null; }
175 PaymentSendFailure ret_hu_conv = PaymentSendFailure.constr_from_ptr(ret);
176 ret_hu_conv.ptrs_to.add(ret_hu_conv);
181 * Utility method to constructs a new PathParameterError-variant PaymentSendFailure
183 public static PaymentSendFailure path_parameter_error(Result_NoneAPIErrorZ[] a) {
184 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);
185 Reference.reachabilityFence(a);
186 if (ret >= 0 && ret <= 4096) { return null; }
187 PaymentSendFailure ret_hu_conv = PaymentSendFailure.constr_from_ptr(ret);
188 ret_hu_conv.ptrs_to.add(ret_hu_conv);
193 * Utility method to constructs a new AllFailedRetrySafe-variant PaymentSendFailure
195 public static PaymentSendFailure all_failed_retry_safe(APIError[] a) {
196 long ret = bindings.PaymentSendFailure_all_failed_retry_safe(a != null ? Arrays.stream(a).mapToLong(a_conv_10 -> a_conv_10.ptr).toArray() : null);
197 Reference.reachabilityFence(a);
198 if (ret >= 0 && ret <= 4096) { return null; }
199 PaymentSendFailure ret_hu_conv = PaymentSendFailure.constr_from_ptr(ret);
200 ret_hu_conv.ptrs_to.add(ret_hu_conv);
205 * Utility method to constructs a new PartialFailure-variant PaymentSendFailure
207 public static PaymentSendFailure partial_failure(Result_NoneAPIErrorZ[] results, RouteParameters failed_paths_retry, byte[] payment_id) {
208 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));
209 Reference.reachabilityFence(results);
210 Reference.reachabilityFence(failed_paths_retry);
211 Reference.reachabilityFence(payment_id);
212 if (ret >= 0 && ret <= 4096) { return null; }
213 PaymentSendFailure ret_hu_conv = PaymentSendFailure.constr_from_ptr(ret);
214 ret_hu_conv.ptrs_to.add(ret_hu_conv);