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 * Indicates an error on the client's part (usually some variant of attempting to use too-low or
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class APIError extends CommonBase {
17 private APIError(Object _dummy, long ptr) { super(ptr); }
18 @Override @SuppressWarnings("deprecation")
19 protected void finalize() throws Throwable {
21 if (ptr != 0) { bindings.APIError_free(ptr); }
23 static APIError constr_from_ptr(long ptr) {
24 bindings.LDKAPIError raw_val = bindings.LDKAPIError_ref_from_ptr(ptr);
25 if (raw_val.getClass() == bindings.LDKAPIError.APIMisuseError.class) {
26 return new APIMisuseError(ptr, (bindings.LDKAPIError.APIMisuseError)raw_val);
28 if (raw_val.getClass() == bindings.LDKAPIError.FeeRateTooHigh.class) {
29 return new FeeRateTooHigh(ptr, (bindings.LDKAPIError.FeeRateTooHigh)raw_val);
31 if (raw_val.getClass() == bindings.LDKAPIError.RouteError.class) {
32 return new RouteError(ptr, (bindings.LDKAPIError.RouteError)raw_val);
34 if (raw_val.getClass() == bindings.LDKAPIError.ChannelUnavailable.class) {
35 return new ChannelUnavailable(ptr, (bindings.LDKAPIError.ChannelUnavailable)raw_val);
37 if (raw_val.getClass() == bindings.LDKAPIError.MonitorUpdateFailed.class) {
38 return new MonitorUpdateFailed(ptr, (bindings.LDKAPIError.MonitorUpdateFailed)raw_val);
40 if (raw_val.getClass() == bindings.LDKAPIError.IncompatibleShutdownScript.class) {
41 return new IncompatibleShutdownScript(ptr, (bindings.LDKAPIError.IncompatibleShutdownScript)raw_val);
43 assert false; return null; // Unreachable without extending the (internal) bindings interface
47 * Indicates the API was wholly misused (see err for more). Cases where these can be returned
48 * are documented, but generally indicates some precondition of a function was violated.
50 public final static class APIMisuseError extends APIError {
52 * A human-readable error message
54 public final java.lang.String err;
55 private APIMisuseError(long ptr, bindings.LDKAPIError.APIMisuseError obj) {
61 * Due to a high feerate, we were unable to complete the request.
62 * For example, this may be returned if the feerate implies we cannot open a channel at the
63 * requested value, but opening a larger channel would succeed.
65 public final static class FeeRateTooHigh extends APIError {
67 * A human-readable error message
69 public final java.lang.String err;
71 * The feerate which was too high.
73 public final int feerate;
74 private FeeRateTooHigh(long ptr, bindings.LDKAPIError.FeeRateTooHigh obj) {
77 this.feerate = obj.feerate;
81 * A malformed Route was provided (eg overflowed value, node id mismatch, overly-looped route,
82 * too-many-hops, etc).
84 public final static class RouteError extends APIError {
86 * A human-readable error message
88 public final java.lang.String err;
89 private RouteError(long ptr, bindings.LDKAPIError.RouteError obj) {
95 * We were unable to complete the request as the Channel required to do so is unable to
96 * complete the request (or was not found). This can take many forms, including disconnected
97 * peer, channel at capacity, channel shutting down, etc.
99 public final static class ChannelUnavailable extends APIError {
101 * A human-readable error message
103 public final java.lang.String err;
104 private ChannelUnavailable(long ptr, bindings.LDKAPIError.ChannelUnavailable obj) {
110 * An attempt to call watch/update_channel returned an Err (ie you did this!), causing the
111 * attempted action to fail.
113 public final static class MonitorUpdateFailed extends APIError {
114 private MonitorUpdateFailed(long ptr, bindings.LDKAPIError.MonitorUpdateFailed obj) {
119 * [`KeysInterface::get_shutdown_scriptpubkey`] returned a shutdown scriptpubkey incompatible
120 * with the channel counterparty as negotiated in [`InitFeatures`].
122 * Using a SegWit v0 script should resolve this issue. If you cannot, you won't be able to open
123 * a channel or cooperatively close one with this peer (and will have to force-close instead).
125 * [`KeysInterface::get_shutdown_scriptpubkey`]: crate::chain::keysinterface::KeysInterface::get_shutdown_scriptpubkey
126 * [`InitFeatures`]: crate::ln::features::InitFeatures
128 public final static class IncompatibleShutdownScript extends APIError {
130 * The incompatible shutdown script.
132 public final org.ldk.structs.ShutdownScript script;
133 private IncompatibleShutdownScript(long ptr, bindings.LDKAPIError.IncompatibleShutdownScript obj) {
135 long script = obj.script;
136 ShutdownScript script_hu_conv = null; if (script < 0 || script > 4096) { script_hu_conv = new ShutdownScript(null, script); }
137 script_hu_conv.ptrs_to.add(this);
138 this.script = script_hu_conv;
142 long ret = bindings.APIError_clone_ptr(this.ptr);
143 Reference.reachabilityFence(this);
148 * Creates a copy of the APIError
150 public APIError clone() {
151 long ret = bindings.APIError_clone(this.ptr);
152 Reference.reachabilityFence(this);
153 if (ret >= 0 && ret <= 4096) { return null; }
154 org.ldk.structs.APIError ret_hu_conv = org.ldk.structs.APIError.constr_from_ptr(ret);
155 ret_hu_conv.ptrs_to.add(this);
160 * Utility method to constructs a new APIMisuseError-variant APIError
162 public static APIError apimisuse_error(java.lang.String err) {
163 long ret = bindings.APIError_apimisuse_error(err);
164 Reference.reachabilityFence(err);
165 if (ret >= 0 && ret <= 4096) { return null; }
166 org.ldk.structs.APIError ret_hu_conv = org.ldk.structs.APIError.constr_from_ptr(ret);
167 ret_hu_conv.ptrs_to.add(ret_hu_conv);
172 * Utility method to constructs a new FeeRateTooHigh-variant APIError
174 public static APIError fee_rate_too_high(java.lang.String err, int feerate) {
175 long ret = bindings.APIError_fee_rate_too_high(err, feerate);
176 Reference.reachabilityFence(err);
177 Reference.reachabilityFence(feerate);
178 if (ret >= 0 && ret <= 4096) { return null; }
179 org.ldk.structs.APIError ret_hu_conv = org.ldk.structs.APIError.constr_from_ptr(ret);
180 ret_hu_conv.ptrs_to.add(ret_hu_conv);
185 * Utility method to constructs a new RouteError-variant APIError
187 public static APIError route_error(java.lang.String err) {
188 long ret = bindings.APIError_route_error(err);
189 Reference.reachabilityFence(err);
190 if (ret >= 0 && ret <= 4096) { return null; }
191 org.ldk.structs.APIError ret_hu_conv = org.ldk.structs.APIError.constr_from_ptr(ret);
192 ret_hu_conv.ptrs_to.add(ret_hu_conv);
197 * Utility method to constructs a new ChannelUnavailable-variant APIError
199 public static APIError channel_unavailable(java.lang.String err) {
200 long ret = bindings.APIError_channel_unavailable(err);
201 Reference.reachabilityFence(err);
202 if (ret >= 0 && ret <= 4096) { return null; }
203 org.ldk.structs.APIError ret_hu_conv = org.ldk.structs.APIError.constr_from_ptr(ret);
204 ret_hu_conv.ptrs_to.add(ret_hu_conv);
209 * Utility method to constructs a new MonitorUpdateFailed-variant APIError
211 public static APIError monitor_update_failed() {
212 long ret = bindings.APIError_monitor_update_failed();
213 if (ret >= 0 && ret <= 4096) { return null; }
214 org.ldk.structs.APIError ret_hu_conv = org.ldk.structs.APIError.constr_from_ptr(ret);
215 ret_hu_conv.ptrs_to.add(ret_hu_conv);
220 * Utility method to constructs a new IncompatibleShutdownScript-variant APIError
222 public static APIError incompatible_shutdown_script(ShutdownScript script) {
223 long ret = bindings.APIError_incompatible_shutdown_script(script == null ? 0 : script.ptr & ~1);
224 Reference.reachabilityFence(script);
225 if (ret >= 0 && ret <= 4096) { return null; }
226 org.ldk.structs.APIError ret_hu_conv = org.ldk.structs.APIError.constr_from_ptr(ret);
227 ret_hu_conv.ptrs_to.add(ret_hu_conv);