Update auto-generated bindings
[ldk-java] / src / main / java / org / ldk / structs / PaymentError.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
8
9
10 /**
11  * An error that may occur when making a payment.
12  */
13 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
14 public class PaymentError extends CommonBase {
15         private PaymentError(Object _dummy, long ptr) { super(ptr); }
16         @Override @SuppressWarnings("deprecation")
17         protected void finalize() throws Throwable {
18                 super.finalize();
19                 if (ptr != 0) { bindings.PaymentError_free(ptr); }
20         }
21         static PaymentError constr_from_ptr(long ptr) {
22                 bindings.LDKPaymentError raw_val = bindings.LDKPaymentError_ref_from_ptr(ptr);
23                 if (raw_val.getClass() == bindings.LDKPaymentError.Invoice.class) {
24                         return new Invoice(ptr, (bindings.LDKPaymentError.Invoice)raw_val);
25                 }
26                 if (raw_val.getClass() == bindings.LDKPaymentError.Routing.class) {
27                         return new Routing(ptr, (bindings.LDKPaymentError.Routing)raw_val);
28                 }
29                 if (raw_val.getClass() == bindings.LDKPaymentError.Sending.class) {
30                         return new Sending(ptr, (bindings.LDKPaymentError.Sending)raw_val);
31                 }
32                 assert false; return null; // Unreachable without extending the (internal) bindings interface
33         }
34
35         /**
36          * An error resulting from the provided [`Invoice`] or payment hash.
37          */
38         public final static class Invoice extends PaymentError {
39                 public final String invoice;
40                 private Invoice(long ptr, bindings.LDKPaymentError.Invoice obj) {
41                         super(null, ptr);
42                         this.invoice = obj.invoice;
43                 }
44         }
45         /**
46          * An error occurring when finding a route.
47          */
48         public final static class Routing extends PaymentError {
49                 public final LightningError routing;
50                 private Routing(long ptr, bindings.LDKPaymentError.Routing obj) {
51                         super(null, ptr);
52                         long routing = obj.routing;
53                         LightningError routing_hu_conv = null; if (routing < 0 || routing > 4096) { routing_hu_conv = new LightningError(null, routing); }
54                         routing_hu_conv.ptrs_to.add(this);
55                         this.routing = routing_hu_conv;
56                 }
57         }
58         /**
59          * An error occurring when sending a payment.
60          */
61         public final static class Sending extends PaymentError {
62                 public final PaymentSendFailure sending;
63                 private Sending(long ptr, bindings.LDKPaymentError.Sending obj) {
64                         super(null, ptr);
65                         long sending = obj.sending;
66                         PaymentSendFailure sending_hu_conv = PaymentSendFailure.constr_from_ptr(sending);
67                         sending_hu_conv.ptrs_to.add(this);
68                         this.sending = sending_hu_conv;
69                 }
70         }
71         long clone_ptr() {
72                 long ret = bindings.PaymentError_clone_ptr(this.ptr);
73                 return ret;
74         }
75
76         /**
77          * Creates a copy of the PaymentError
78          */
79         public PaymentError clone() {
80                 long ret = bindings.PaymentError_clone(this.ptr);
81                 if (ret >= 0 && ret <= 4096) { return null; }
82                 PaymentError ret_hu_conv = PaymentError.constr_from_ptr(ret);
83                 ret_hu_conv.ptrs_to.add(this);
84                 return ret_hu_conv;
85         }
86
87         /**
88          * Utility method to constructs a new Invoice-variant PaymentError
89          */
90         public static PaymentError invoice(java.lang.String a) {
91                 long ret = bindings.PaymentError_invoice(a);
92                 if (ret >= 0 && ret <= 4096) { return null; }
93                 PaymentError ret_hu_conv = PaymentError.constr_from_ptr(ret);
94                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
95                 return ret_hu_conv;
96         }
97
98         /**
99          * Utility method to constructs a new Routing-variant PaymentError
100          */
101         public static PaymentError routing(LightningError a) {
102                 long ret = bindings.PaymentError_routing(a == null ? 0 : a.ptr & ~1);
103                 if (ret >= 0 && ret <= 4096) { return null; }
104                 PaymentError ret_hu_conv = PaymentError.constr_from_ptr(ret);
105                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
106                 return ret_hu_conv;
107         }
108
109         /**
110          * Utility method to constructs a new Sending-variant PaymentError
111          */
112         public static PaymentError sending(PaymentSendFailure a) {
113                 long ret = bindings.PaymentError_sending(a.ptr);
114                 if (ret >= 0 && ret <= 4096) { return null; }
115                 PaymentError ret_hu_conv = PaymentError.constr_from_ptr(ret);
116                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
117                 return ret_hu_conv;
118         }
119
120 }