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.AllFailedResendSafe.class) {
33 return new AllFailedResendSafe(ptr, (bindings.LDKPaymentSendFailure.AllFailedResendSafe)raw_val);
35 if (raw_val.getClass() == bindings.LDKPaymentSendFailure.DuplicatePayment.class) {
36 return new DuplicatePayment(ptr, (bindings.LDKPaymentSendFailure.DuplicatePayment)raw_val);
38 if (raw_val.getClass() == bindings.LDKPaymentSendFailure.PartialFailure.class) {
39 return new PartialFailure(ptr, (bindings.LDKPaymentSendFailure.PartialFailure)raw_val);
41 assert false; return null; // Unreachable without extending the (internal) bindings interface
45 * A parameter which was passed to send_payment was invalid, preventing us from attempting to
46 * send the payment at all.
48 * You can freely resend the payment in full (with the parameter error fixed).
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
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) {
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;
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.
68 * You can freely resend the payment in full (with the parameter error fixed).
70 * The results here are ordered the same as the paths in the route object which was passed to
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
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) {
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;
89 this.path_parameter_error = path_parameter_error_conv_22_arr;
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).
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
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) {
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;
114 this.all_failed_resend_safe = all_failed_resend_safe_conv_10_arr;
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`]).
122 * [`Event::PaymentSent`]: events::Event::PaymentSent
124 public final static class DuplicatePayment extends PaymentSendFailure {
125 private DuplicatePayment(long ptr, bindings.LDKPaymentSendFailure.DuplicatePayment obj) {
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.
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`].
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.
143 public final static class PartialFailure extends PaymentSendFailure {
145 * The errors themselves, in the same order as the route hops.
147 public final Result_NoneAPIErrorZ[] results;
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.
153 * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
155 @Nullable public final org.ldk.structs.RouteParameters failed_paths_retry;
157 * The payment id for the payment, which is now at least partially pending.
159 public final byte[] payment_id;
160 private PartialFailure(long ptr, bindings.LDKPaymentSendFailure.PartialFailure obj) {
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;
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;
179 long ret = bindings.PaymentSendFailure_clone_ptr(this.ptr);
180 Reference.reachabilityFence(this);
185 * Creates a copy of the PaymentSendFailure
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); };
197 * Utility method to constructs a new ParameterError-variant PaymentSendFailure
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); };
209 * Utility method to constructs a new PathParameterError-variant PaymentSendFailure
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); };
221 * Utility method to constructs a new AllFailedResendSafe-variant PaymentSendFailure
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); };
233 * Utility method to constructs a new DuplicatePayment-variant PaymentSendFailure
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); };
244 * Utility method to constructs a new PartialFailure-variant PaymentSendFailure
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); };