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 with [`ChannelManager::send_payment_with_route`], it can be in one
13 * of several states. This enum is returned as the Err() type describing which state the payment
14 * is in, see the description of individual enum states for more.
16 * [`ChannelManager::send_payment_with_route`]: crate::ln::channelmanager::ChannelManager::send_payment_with_route
18 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
19 public class PaymentSendFailure extends CommonBase {
20 private PaymentSendFailure(Object _dummy, long ptr) { super(ptr); }
21 @Override @SuppressWarnings("deprecation")
22 protected void finalize() throws Throwable {
24 if (ptr != 0) { bindings.PaymentSendFailure_free(ptr); }
26 static PaymentSendFailure constr_from_ptr(long ptr) {
27 bindings.LDKPaymentSendFailure raw_val = bindings.LDKPaymentSendFailure_ref_from_ptr(ptr);
28 if (raw_val.getClass() == bindings.LDKPaymentSendFailure.ParameterError.class) {
29 return new ParameterError(ptr, (bindings.LDKPaymentSendFailure.ParameterError)raw_val);
31 if (raw_val.getClass() == bindings.LDKPaymentSendFailure.PathParameterError.class) {
32 return new PathParameterError(ptr, (bindings.LDKPaymentSendFailure.PathParameterError)raw_val);
34 if (raw_val.getClass() == bindings.LDKPaymentSendFailure.AllFailedResendSafe.class) {
35 return new AllFailedResendSafe(ptr, (bindings.LDKPaymentSendFailure.AllFailedResendSafe)raw_val);
37 if (raw_val.getClass() == bindings.LDKPaymentSendFailure.DuplicatePayment.class) {
38 return new DuplicatePayment(ptr, (bindings.LDKPaymentSendFailure.DuplicatePayment)raw_val);
40 if (raw_val.getClass() == bindings.LDKPaymentSendFailure.PartialFailure.class) {
41 return new PartialFailure(ptr, (bindings.LDKPaymentSendFailure.PartialFailure)raw_val);
43 assert false; return null; // Unreachable without extending the (internal) bindings interface
47 * A parameter which was passed to send_payment was invalid, preventing us from attempting to
48 * send the payment at all.
50 * You can freely resend the payment in full (with the parameter error fixed).
52 * Because the payment failed outright, no payment tracking is done and no
53 * [`Event::PaymentPathFailed`] or [`Event::PaymentFailed`] events will be generated.
55 * [`Event::PaymentPathFailed`]: crate::events::Event::PaymentPathFailed
56 * [`Event::PaymentFailed`]: crate::events::Event::PaymentFailed
58 public final static class ParameterError extends PaymentSendFailure {
59 public final org.ldk.structs.APIError parameter_error;
60 private ParameterError(long ptr, bindings.LDKPaymentSendFailure.ParameterError obj) {
62 long parameter_error = obj.parameter_error;
63 org.ldk.structs.APIError parameter_error_hu_conv = org.ldk.structs.APIError.constr_from_ptr(parameter_error);
64 if (parameter_error_hu_conv != null) { parameter_error_hu_conv.ptrs_to.add(this); };
65 this.parameter_error = parameter_error_hu_conv;
69 * A parameter in a single path which was passed to send_payment was invalid, preventing us
70 * from attempting to send the payment at all.
72 * You can freely resend the payment in full (with the parameter error fixed).
74 * Because the payment failed outright, no payment tracking is done and no
75 * [`Event::PaymentPathFailed`] or [`Event::PaymentFailed`] events will be generated.
77 * The results here are ordered the same as the paths in the route object which was passed to
80 * [`Event::PaymentPathFailed`]: crate::events::Event::PaymentPathFailed
81 * [`Event::PaymentFailed`]: crate::events::Event::PaymentFailed
83 public final static class PathParameterError extends PaymentSendFailure {
84 public final Result_NoneAPIErrorZ[] path_parameter_error;
85 private PathParameterError(long ptr, bindings.LDKPaymentSendFailure.PathParameterError obj) {
87 long[] path_parameter_error = obj.path_parameter_error;
88 int path_parameter_error_conv_22_len = path_parameter_error.length;
89 Result_NoneAPIErrorZ[] path_parameter_error_conv_22_arr = new Result_NoneAPIErrorZ[path_parameter_error_conv_22_len];
90 for (int w = 0; w < path_parameter_error_conv_22_len; w++) {
91 long path_parameter_error_conv_22 = path_parameter_error[w];
92 Result_NoneAPIErrorZ path_parameter_error_conv_22_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(path_parameter_error_conv_22);
93 path_parameter_error_conv_22_arr[w] = path_parameter_error_conv_22_hu_conv;
95 this.path_parameter_error = path_parameter_error_conv_22_arr;
99 * All paths which were attempted failed to send, with no channel state change taking place.
100 * You can freely resend the payment in full (though you probably want to do so over different
101 * paths than the ones selected).
103 * Because the payment failed outright, no payment tracking is done and no
104 * [`Event::PaymentPathFailed`] or [`Event::PaymentFailed`] events will be generated.
106 * [`Event::PaymentPathFailed`]: crate::events::Event::PaymentPathFailed
107 * [`Event::PaymentFailed`]: crate::events::Event::PaymentFailed
109 public final static class AllFailedResendSafe extends PaymentSendFailure {
110 public final APIError[] all_failed_resend_safe;
111 private AllFailedResendSafe(long ptr, bindings.LDKPaymentSendFailure.AllFailedResendSafe obj) {
113 long[] all_failed_resend_safe = obj.all_failed_resend_safe;
114 int all_failed_resend_safe_conv_10_len = all_failed_resend_safe.length;
115 APIError[] all_failed_resend_safe_conv_10_arr = new APIError[all_failed_resend_safe_conv_10_len];
116 for (int k = 0; k < all_failed_resend_safe_conv_10_len; k++) {
117 long all_failed_resend_safe_conv_10 = all_failed_resend_safe[k];
118 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);
119 if (all_failed_resend_safe_conv_10_hu_conv != null) { all_failed_resend_safe_conv_10_hu_conv.ptrs_to.add(this); };
120 all_failed_resend_safe_conv_10_arr[k] = all_failed_resend_safe_conv_10_hu_conv;
122 this.all_failed_resend_safe = all_failed_resend_safe_conv_10_arr;
126 * Indicates that a payment for the provided [`PaymentId`] is already in-flight and has not
127 * yet completed (i.e. generated an [`Event::PaymentSent`] or [`Event::PaymentFailed`]).
129 * [`PaymentId`]: crate::ln::channelmanager::PaymentId
130 * [`Event::PaymentSent`]: crate::events::Event::PaymentSent
131 * [`Event::PaymentFailed`]: crate::events::Event::PaymentFailed
133 public final static class DuplicatePayment extends PaymentSendFailure {
134 private DuplicatePayment(long ptr, bindings.LDKPaymentSendFailure.DuplicatePayment obj) {
139 * Some paths that were attempted failed to send, though some paths may have succeeded. At least
140 * some paths have irrevocably committed to the HTLC.
142 * The results here are ordered the same as the paths in the route object that was passed to
145 * Any entries that contain `Err(APIError::MonitorUpdateInprogress)` will send once a
146 * [`MonitorEvent::Completed`] is provided for the next-hop channel with the latest update_id.
148 * [`MonitorEvent::Completed`]: crate::chain::channelmonitor::MonitorEvent::Completed
150 public final static class PartialFailure extends PaymentSendFailure {
152 * The errors themselves, in the same order as the paths from the route.
154 public final Result_NoneAPIErrorZ[] results;
156 * If some paths failed without irrevocably committing to the new HTLC(s), this will
157 * contain a [`RouteParameters`] object for the failing paths.
159 * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
161 @Nullable public final org.ldk.structs.RouteParameters failed_paths_retry;
163 * The payment id for the payment, which is now at least partially pending.
165 public final byte[] payment_id;
166 private PartialFailure(long ptr, bindings.LDKPaymentSendFailure.PartialFailure obj) {
168 long[] results = obj.results;
169 int results_conv_22_len = results.length;
170 Result_NoneAPIErrorZ[] results_conv_22_arr = new Result_NoneAPIErrorZ[results_conv_22_len];
171 for (int w = 0; w < results_conv_22_len; w++) {
172 long results_conv_22 = results[w];
173 Result_NoneAPIErrorZ results_conv_22_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(results_conv_22);
174 results_conv_22_arr[w] = results_conv_22_hu_conv;
176 this.results = results_conv_22_arr;
177 long failed_paths_retry = obj.failed_paths_retry;
178 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); }
179 if (failed_paths_retry_hu_conv != null) { failed_paths_retry_hu_conv.ptrs_to.add(this); };
180 this.failed_paths_retry = failed_paths_retry_hu_conv;
181 this.payment_id = obj.payment_id;
185 long ret = bindings.PaymentSendFailure_clone_ptr(this.ptr);
186 Reference.reachabilityFence(this);
191 * Creates a copy of the PaymentSendFailure
193 public PaymentSendFailure clone() {
194 long ret = bindings.PaymentSendFailure_clone(this.ptr);
195 Reference.reachabilityFence(this);
196 if (ret >= 0 && ret <= 4096) { return null; }
197 org.ldk.structs.PaymentSendFailure ret_hu_conv = org.ldk.structs.PaymentSendFailure.constr_from_ptr(ret);
198 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
203 * Utility method to constructs a new ParameterError-variant PaymentSendFailure
205 public static PaymentSendFailure parameter_error(org.ldk.structs.APIError a) {
206 long ret = bindings.PaymentSendFailure_parameter_error(a.ptr);
207 Reference.reachabilityFence(a);
208 if (ret >= 0 && ret <= 4096) { return null; }
209 org.ldk.structs.PaymentSendFailure ret_hu_conv = org.ldk.structs.PaymentSendFailure.constr_from_ptr(ret);
210 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
211 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a); };
216 * Utility method to constructs a new PathParameterError-variant PaymentSendFailure
218 public static PaymentSendFailure path_parameter_error(Result_NoneAPIErrorZ[] a) {
219 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);
220 Reference.reachabilityFence(a);
221 if (ret >= 0 && ret <= 4096) { return null; }
222 org.ldk.structs.PaymentSendFailure ret_hu_conv = org.ldk.structs.PaymentSendFailure.constr_from_ptr(ret);
223 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
228 * Utility method to constructs a new AllFailedResendSafe-variant PaymentSendFailure
230 public static PaymentSendFailure all_failed_resend_safe(APIError[] a) {
231 long ret = bindings.PaymentSendFailure_all_failed_resend_safe(a != null ? Arrays.stream(a).mapToLong(a_conv_10 -> a_conv_10.ptr).toArray() : null);
232 Reference.reachabilityFence(a);
233 if (ret >= 0 && ret <= 4096) { return null; }
234 org.ldk.structs.PaymentSendFailure ret_hu_conv = org.ldk.structs.PaymentSendFailure.constr_from_ptr(ret);
235 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
236 for (APIError a_conv_10: a) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a_conv_10); }; };
241 * Utility method to constructs a new DuplicatePayment-variant PaymentSendFailure
243 public static PaymentSendFailure duplicate_payment() {
244 long ret = bindings.PaymentSendFailure_duplicate_payment();
245 if (ret >= 0 && ret <= 4096) { return null; }
246 org.ldk.structs.PaymentSendFailure ret_hu_conv = org.ldk.structs.PaymentSendFailure.constr_from_ptr(ret);
247 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
252 * Utility method to constructs a new PartialFailure-variant PaymentSendFailure
254 public static PaymentSendFailure partial_failure(Result_NoneAPIErrorZ[] results, org.ldk.structs.RouteParameters failed_paths_retry, byte[] payment_id) {
255 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));
256 Reference.reachabilityFence(results);
257 Reference.reachabilityFence(failed_paths_retry);
258 Reference.reachabilityFence(payment_id);
259 if (ret >= 0 && ret <= 4096) { return null; }
260 org.ldk.structs.PaymentSendFailure ret_hu_conv = org.ldk.structs.PaymentSendFailure.constr_from_ptr(ret);
261 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
262 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(failed_paths_retry); };