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 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;
76 this.path_parameter_error = path_parameter_error_conv_22_arr;
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).
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) {
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;
96 this.all_failed_retry_safe = all_failed_retry_safe_conv_10_arr;
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.
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).
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.
113 public final static class PartialFailure extends PaymentSendFailure {
115 * The errors themselves, in the same order as the route hops.
117 public final Result_NoneAPIErrorZ[] results;
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.
123 * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
125 @Nullable public final RouteParameters failed_paths_retry;
127 * The payment id for the payment, which is now at least partially pending.
129 public final byte[] payment_id;
130 private PartialFailure(long ptr, bindings.LDKPaymentSendFailure.PartialFailure obj) {
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;
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;
148 long ret = bindings.PaymentSendFailure_clone_ptr(this.ptr);
149 Reference.reachabilityFence(this);
154 * Creates a copy of the PaymentSendFailure
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);
166 * Utility method to constructs a new ParameterError-variant PaymentSendFailure
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);
178 * Utility method to constructs a new PathParameterError-variant PaymentSendFailure
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);
190 * Utility method to constructs a new AllFailedRetrySafe-variant PaymentSendFailure
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);
202 * Utility method to constructs a new PartialFailure-variant PaymentSendFailure
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);