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.Sending.class) {
28 return new Sending(ptr, (bindings.LDKPaymentError.Sending)raw_val);
30 assert false; return null; // Unreachable without extending the (internal) bindings interface
34 * An error resulting from the provided [`Bolt11Invoice`] or payment hash.
36 public final static class Invoice extends PaymentError {
37 public final java.lang.String invoice;
38 private Invoice(long ptr, bindings.LDKPaymentError.Invoice obj) {
40 this.invoice = obj.invoice;
44 * An error occurring when sending a payment.
46 public final static class Sending extends PaymentError {
47 public final org.ldk.enums.RetryableSendFailure sending;
48 private Sending(long ptr, bindings.LDKPaymentError.Sending obj) {
50 this.sending = obj.sending;
54 long ret = bindings.PaymentError_clone_ptr(this.ptr);
55 Reference.reachabilityFence(this);
60 * Creates a copy of the PaymentError
62 public PaymentError clone() {
63 long ret = bindings.PaymentError_clone(this.ptr);
64 Reference.reachabilityFence(this);
65 if (ret >= 0 && ret <= 4096) { return null; }
66 org.ldk.structs.PaymentError ret_hu_conv = org.ldk.structs.PaymentError.constr_from_ptr(ret);
67 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
72 * Utility method to constructs a new Invoice-variant PaymentError
74 public static PaymentError invoice(java.lang.String a) {
75 long ret = bindings.PaymentError_invoice(a);
76 Reference.reachabilityFence(a);
77 if (ret >= 0 && ret <= 4096) { return null; }
78 org.ldk.structs.PaymentError ret_hu_conv = org.ldk.structs.PaymentError.constr_from_ptr(ret);
79 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
84 * Utility method to constructs a new Sending-variant PaymentError
86 public static PaymentError sending(org.ldk.enums.RetryableSendFailure a) {
87 long ret = bindings.PaymentError_sending(a);
88 Reference.reachabilityFence(a);
89 if (ret >= 0 && ret <= 4096) { return null; }
90 org.ldk.structs.PaymentError ret_hu_conv = org.ldk.structs.PaymentError.constr_from_ptr(ret);
91 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
96 * Checks if two PaymentErrors contain equal inner contents.
97 * This ignores pointers and is_owned flags and looks at the values in fields.
99 public boolean eq(org.ldk.structs.PaymentError b) {
100 boolean ret = bindings.PaymentError_eq(this.ptr, b == null ? 0 : b.ptr);
101 Reference.reachabilityFence(this);
102 Reference.reachabilityFence(b);
106 @Override public boolean equals(Object o) {
107 if (!(o instanceof PaymentError)) return false;
108 return this.eq((PaymentError)o);