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 * An error that may occur when making a payment.
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class PaymentError extends CommonBase {
16 private PaymentError(Object _dummy, long ptr) { super(ptr); }
17 @Override @SuppressWarnings("deprecation")
18 protected void finalize() throws Throwable {
20 if (ptr != 0) { bindings.PaymentError_free(ptr); }
22 static PaymentError constr_from_ptr(long ptr) {
23 bindings.LDKPaymentError raw_val = bindings.LDKPaymentError_ref_from_ptr(ptr);
24 if (raw_val.getClass() == bindings.LDKPaymentError.Invoice.class) {
25 return new Invoice(ptr, (bindings.LDKPaymentError.Invoice)raw_val);
27 if (raw_val.getClass() == bindings.LDKPaymentError.Routing.class) {
28 return new Routing(ptr, (bindings.LDKPaymentError.Routing)raw_val);
30 if (raw_val.getClass() == bindings.LDKPaymentError.Sending.class) {
31 return new Sending(ptr, (bindings.LDKPaymentError.Sending)raw_val);
33 assert false; return null; // Unreachable without extending the (internal) bindings interface
37 * An error resulting from the provided [`Invoice`] or payment hash.
39 public final static class Invoice extends PaymentError {
40 public final String invoice;
41 private Invoice(long ptr, bindings.LDKPaymentError.Invoice obj) {
43 this.invoice = obj.invoice;
47 * An error occurring when finding a route.
49 public final static class Routing extends PaymentError {
50 public final LightningError routing;
51 private Routing(long ptr, bindings.LDKPaymentError.Routing obj) {
53 long routing = obj.routing;
54 LightningError routing_hu_conv = null; if (routing < 0 || routing > 4096) { routing_hu_conv = new LightningError(null, routing); }
55 routing_hu_conv.ptrs_to.add(this);
56 this.routing = routing_hu_conv;
60 * An error occurring when sending a payment.
62 public final static class Sending extends PaymentError {
63 public final PaymentSendFailure sending;
64 private Sending(long ptr, bindings.LDKPaymentError.Sending obj) {
66 long sending = obj.sending;
67 PaymentSendFailure sending_hu_conv = PaymentSendFailure.constr_from_ptr(sending);
68 sending_hu_conv.ptrs_to.add(this);
69 this.sending = sending_hu_conv;
73 long ret = bindings.PaymentError_clone_ptr(this.ptr);
74 Reference.reachabilityFence(this);
79 * Creates a copy of the PaymentError
81 public PaymentError clone() {
82 long ret = bindings.PaymentError_clone(this.ptr);
83 Reference.reachabilityFence(this);
84 if (ret >= 0 && ret <= 4096) { return null; }
85 PaymentError ret_hu_conv = PaymentError.constr_from_ptr(ret);
86 ret_hu_conv.ptrs_to.add(this);
91 * Utility method to constructs a new Invoice-variant PaymentError
93 public static PaymentError invoice(java.lang.String a) {
94 long ret = bindings.PaymentError_invoice(a);
95 Reference.reachabilityFence(a);
96 if (ret >= 0 && ret <= 4096) { return null; }
97 PaymentError ret_hu_conv = PaymentError.constr_from_ptr(ret);
98 ret_hu_conv.ptrs_to.add(ret_hu_conv);
103 * Utility method to constructs a new Routing-variant PaymentError
105 public static PaymentError routing(LightningError a) {
106 long ret = bindings.PaymentError_routing(a == null ? 0 : a.ptr & ~1);
107 Reference.reachabilityFence(a);
108 if (ret >= 0 && ret <= 4096) { return null; }
109 PaymentError ret_hu_conv = PaymentError.constr_from_ptr(ret);
110 ret_hu_conv.ptrs_to.add(ret_hu_conv);
115 * Utility method to constructs a new Sending-variant PaymentError
117 public static PaymentError sending(PaymentSendFailure a) {
118 long ret = bindings.PaymentError_sending(a.ptr);
119 Reference.reachabilityFence(a);
120 if (ret >= 0 && ret <= 4096) { return null; }
121 PaymentError ret_hu_conv = PaymentError.constr_from_ptr(ret);
122 ret_hu_conv.ptrs_to.add(ret_hu_conv);