Update auto-generated bindings
[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                 if (raw_val.getClass() == bindings.LDKAPIError.IncompatibleShutdownScript.class) {
40                         return new IncompatibleShutdownScript(ptr, (bindings.LDKAPIError.IncompatibleShutdownScript)raw_val);
41                 }
42                 assert false; return null; // Unreachable without extending the (internal) bindings interface
43         }
44
45         /**
46          * Indicates the API was wholly misused (see err for more). Cases where these can be returned
47          * are documented, but generally indicates some precondition of a function was violated.
48          */
49         public final static class APIMisuseError extends APIError {
50                 /**
51                  * A human-readable error message
52                 */
53                 public final String err;
54                 private APIMisuseError(long ptr, bindings.LDKAPIError.APIMisuseError obj) {
55                         super(null, ptr);
56                         this.err = obj.err;
57                 }
58         }
59         /**
60          * Due to a high feerate, we were unable to complete the request.
61          * For example, this may be returned if the feerate implies we cannot open a channel at the
62          * requested value, but opening a larger channel would succeed.
63          */
64         public final static class FeeRateTooHigh extends APIError {
65                 /**
66                  * A human-readable error message
67                 */
68                 public final String err;
69                 /**
70                  * The feerate which was too high.
71                 */
72                 public final int feerate;
73                 private FeeRateTooHigh(long ptr, bindings.LDKAPIError.FeeRateTooHigh obj) {
74                         super(null, ptr);
75                         this.err = obj.err;
76                         this.feerate = obj.feerate;
77                 }
78         }
79         /**
80          * A malformed Route was provided (eg overflowed value, node id mismatch, overly-looped route,
81          * too-many-hops, etc).
82          */
83         public final static class RouteError extends APIError {
84                 /**
85                  * A human-readable error message
86                 */
87                 public final String err;
88                 private RouteError(long ptr, bindings.LDKAPIError.RouteError obj) {
89                         super(null, ptr);
90                         this.err = obj.err;
91                 }
92         }
93         /**
94          * We were unable to complete the request as the Channel required to do so is unable to
95          * complete the request (or was not found). This can take many forms, including disconnected
96          * peer, channel at capacity, channel shutting down, etc.
97          */
98         public final static class ChannelUnavailable extends APIError {
99                 /**
100                  * A human-readable error message
101                 */
102                 public final String err;
103                 private ChannelUnavailable(long ptr, bindings.LDKAPIError.ChannelUnavailable obj) {
104                         super(null, ptr);
105                         this.err = obj.err;
106                 }
107         }
108         /**
109          * An attempt to call watch/update_channel returned an Err (ie you did this!), causing the
110          * attempted action to fail.
111          */
112         public final static class MonitorUpdateFailed extends APIError {
113                 private MonitorUpdateFailed(long ptr, bindings.LDKAPIError.MonitorUpdateFailed obj) {
114                         super(null, ptr);
115                 }
116         }
117         /**
118          * [`KeysInterface::get_shutdown_scriptpubkey`] returned a shutdown scriptpubkey incompatible
119          * with the channel counterparty as negotiated in [`InitFeatures`].
120          * 
121          * Using a SegWit v0 script should resolve this issue. If you cannot, you won't be able to open
122          * a channel or cooperatively close one with this peer (and will have to force-close instead).
123          * 
124          * [`KeysInterface::get_shutdown_scriptpubkey`]: crate::chain::keysinterface::KeysInterface::get_shutdown_scriptpubkey
125          * [`InitFeatures`]: crate::ln::features::InitFeatures
126          */
127         public final static class IncompatibleShutdownScript extends APIError {
128                 /**
129                  * The incompatible shutdown script.
130                 */
131                 public final ShutdownScript script;
132                 private IncompatibleShutdownScript(long ptr, bindings.LDKAPIError.IncompatibleShutdownScript obj) {
133                         super(null, ptr);
134                         long script = obj.script;
135                         ShutdownScript script_hu_conv = null; if (script < 0 || script > 4096) { script_hu_conv = new ShutdownScript(null, script); }
136                         script_hu_conv.ptrs_to.add(this);
137                         this.script = script_hu_conv;
138                 }
139         }
140         long clone_ptr() {
141                 long ret = bindings.APIError_clone_ptr(this.ptr);
142                 return ret;
143         }
144
145         /**
146          * Creates a copy of the APIError
147          */
148         public APIError clone() {
149                 long ret = bindings.APIError_clone(this.ptr);
150                 if (ret >= 0 && ret <= 4096) { return null; }
151                 APIError ret_hu_conv = APIError.constr_from_ptr(ret);
152                 ret_hu_conv.ptrs_to.add(this);
153                 return ret_hu_conv;
154         }
155
156         /**
157          * Utility method to constructs a new APIMisuseError-variant APIError
158          */
159         public static APIError apimisuse_error(java.lang.String err) {
160                 long ret = bindings.APIError_apimisuse_error(err);
161                 if (ret >= 0 && ret <= 4096) { return null; }
162                 APIError ret_hu_conv = APIError.constr_from_ptr(ret);
163                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
164                 return ret_hu_conv;
165         }
166
167         /**
168          * Utility method to constructs a new FeeRateTooHigh-variant APIError
169          */
170         public static APIError fee_rate_too_high(java.lang.String err, int feerate) {
171                 long ret = bindings.APIError_fee_rate_too_high(err, feerate);
172                 if (ret >= 0 && ret <= 4096) { return null; }
173                 APIError ret_hu_conv = APIError.constr_from_ptr(ret);
174                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
175                 return ret_hu_conv;
176         }
177
178         /**
179          * Utility method to constructs a new RouteError-variant APIError
180          */
181         public static APIError route_error(java.lang.String err) {
182                 long ret = bindings.APIError_route_error(err);
183                 if (ret >= 0 && ret <= 4096) { return null; }
184                 APIError ret_hu_conv = APIError.constr_from_ptr(ret);
185                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
186                 return ret_hu_conv;
187         }
188
189         /**
190          * Utility method to constructs a new ChannelUnavailable-variant APIError
191          */
192         public static APIError channel_unavailable(java.lang.String err) {
193                 long ret = bindings.APIError_channel_unavailable(err);
194                 if (ret >= 0 && ret <= 4096) { return null; }
195                 APIError ret_hu_conv = APIError.constr_from_ptr(ret);
196                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
197                 return ret_hu_conv;
198         }
199
200         /**
201          * Utility method to constructs a new MonitorUpdateFailed-variant APIError
202          */
203         public static APIError monitor_update_failed() {
204                 long ret = bindings.APIError_monitor_update_failed();
205                 if (ret >= 0 && ret <= 4096) { return null; }
206                 APIError ret_hu_conv = APIError.constr_from_ptr(ret);
207                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
208                 return ret_hu_conv;
209         }
210
211         /**
212          * Utility method to constructs a new IncompatibleShutdownScript-variant APIError
213          */
214         public static APIError incompatible_shutdown_script(ShutdownScript script) {
215                 long ret = bindings.APIError_incompatible_shutdown_script(script == null ? 0 : script.ptr & ~1);
216                 if (ret >= 0 && ret <= 4096) { return null; }
217                 APIError ret_hu_conv = APIError.constr_from_ptr(ret);
218                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
219                 return ret_hu_conv;
220         }
221
222 }