Merge pull request #33 from TheBlueMatt/main
[ldk-java] / src / main / java / org / ldk / structs / APIError.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  * Indicates an error on the client's part (usually some variant of attempting to use too-low or
12  * too-high values)
13  */
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class APIError extends CommonBase {
16         private APIError(Object _dummy, long ptr) { super(ptr); }
17         @Override @SuppressWarnings("deprecation")
18         protected void finalize() throws Throwable {
19                 super.finalize();
20                 if (ptr != 0) { bindings.APIError_free(ptr); }
21         }
22         static APIError constr_from_ptr(long ptr) {
23                 bindings.LDKAPIError raw_val = bindings.LDKAPIError_ref_from_ptr(ptr);
24                 if (raw_val.getClass() == bindings.LDKAPIError.APIMisuseError.class) {
25                         return new APIMisuseError(ptr, (bindings.LDKAPIError.APIMisuseError)raw_val);
26                 }
27                 if (raw_val.getClass() == bindings.LDKAPIError.FeeRateTooHigh.class) {
28                         return new FeeRateTooHigh(ptr, (bindings.LDKAPIError.FeeRateTooHigh)raw_val);
29                 }
30                 if (raw_val.getClass() == bindings.LDKAPIError.RouteError.class) {
31                         return new RouteError(ptr, (bindings.LDKAPIError.RouteError)raw_val);
32                 }
33                 if (raw_val.getClass() == bindings.LDKAPIError.ChannelUnavailable.class) {
34                         return new ChannelUnavailable(ptr, (bindings.LDKAPIError.ChannelUnavailable)raw_val);
35                 }
36                 if (raw_val.getClass() == bindings.LDKAPIError.MonitorUpdateFailed.class) {
37                         return new MonitorUpdateFailed(ptr, (bindings.LDKAPIError.MonitorUpdateFailed)raw_val);
38                 }
39                 assert false; return null; // Unreachable without extending the (internal) bindings interface
40         }
41
42         public final static class APIMisuseError extends APIError {
43                 /**
44                  * A human-readable error message
45                 */
46                 public final String err;
47                 private APIMisuseError(long ptr, bindings.LDKAPIError.APIMisuseError obj) {
48                         super(null, ptr);
49                         this.err = obj.err;
50                 }
51         }
52         public final static class FeeRateTooHigh extends APIError {
53                 /**
54                  * A human-readable error message
55                 */
56                 public final String err;
57                 /**
58                  * The feerate which was too high.
59                 */
60                 public final int feerate;
61                 private FeeRateTooHigh(long ptr, bindings.LDKAPIError.FeeRateTooHigh obj) {
62                         super(null, ptr);
63                         this.err = obj.err;
64                         this.feerate = obj.feerate;
65                 }
66         }
67         public final static class RouteError extends APIError {
68                 /**
69                  * A human-readable error message
70                 */
71                 public final String err;
72                 private RouteError(long ptr, bindings.LDKAPIError.RouteError obj) {
73                         super(null, ptr);
74                         this.err = obj.err;
75                 }
76         }
77         public final static class ChannelUnavailable extends APIError {
78                 /**
79                  * A human-readable error message
80                 */
81                 public final String err;
82                 private ChannelUnavailable(long ptr, bindings.LDKAPIError.ChannelUnavailable obj) {
83                         super(null, ptr);
84                         this.err = obj.err;
85                 }
86         }
87         public final static class MonitorUpdateFailed extends APIError {
88                 private MonitorUpdateFailed(long ptr, bindings.LDKAPIError.MonitorUpdateFailed obj) {
89                         super(null, ptr);
90                 }
91         }
92         /**
93          * Creates a copy of the APIError
94          */
95         public APIError clone() {
96                 long ret = bindings.APIError_clone(this.ptr);
97                 if (ret < 1024) { return null; }
98                 APIError ret_hu_conv = APIError.constr_from_ptr(ret);
99                 ret_hu_conv.ptrs_to.add(this);
100                 return ret_hu_conv;
101         }
102
103         /**
104          * Utility method to constructs a new APIMisuseError-variant APIError
105          */
106         public static APIError apimisuse_error(java.lang.String err) {
107                 long ret = bindings.APIError_apimisuse_error(err);
108                 if (ret < 1024) { return null; }
109                 APIError ret_hu_conv = APIError.constr_from_ptr(ret);
110                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
111                 return ret_hu_conv;
112         }
113
114         /**
115          * Utility method to constructs a new FeeRateTooHigh-variant APIError
116          */
117         public static APIError fee_rate_too_high(java.lang.String err, int feerate) {
118                 long ret = bindings.APIError_fee_rate_too_high(err, feerate);
119                 if (ret < 1024) { return null; }
120                 APIError ret_hu_conv = APIError.constr_from_ptr(ret);
121                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
122                 return ret_hu_conv;
123         }
124
125         /**
126          * Utility method to constructs a new RouteError-variant APIError
127          */
128         public static APIError route_error(java.lang.String err) {
129                 long ret = bindings.APIError_route_error(err);
130                 if (ret < 1024) { return null; }
131                 APIError ret_hu_conv = APIError.constr_from_ptr(ret);
132                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
133                 return ret_hu_conv;
134         }
135
136         /**
137          * Utility method to constructs a new ChannelUnavailable-variant APIError
138          */
139         public static APIError channel_unavailable(java.lang.String err) {
140                 long ret = bindings.APIError_channel_unavailable(err);
141                 if (ret < 1024) { return null; }
142                 APIError ret_hu_conv = APIError.constr_from_ptr(ret);
143                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
144                 return ret_hu_conv;
145         }
146
147         /**
148          * Utility method to constructs a new MonitorUpdateFailed-variant APIError
149          */
150         public static APIError monitor_update_failed() {
151                 long ret = bindings.APIError_monitor_update_failed();
152                 if (ret < 1024) { return null; }
153                 APIError ret_hu_conv = APIError.constr_from_ptr(ret);
154                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
155                 return ret_hu_conv;
156         }
157
158 }