1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
11 * Indicates an error on the client's part (usually some variant of attempting to use too-low or
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 {
20 if (ptr != 0) { bindings.APIError_free(ptr); }
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);
27 if (raw_val.getClass() == bindings.LDKAPIError.FeeRateTooHigh.class) {
28 return new FeeRateTooHigh(ptr, (bindings.LDKAPIError.FeeRateTooHigh)raw_val);
30 if (raw_val.getClass() == bindings.LDKAPIError.RouteError.class) {
31 return new RouteError(ptr, (bindings.LDKAPIError.RouteError)raw_val);
33 if (raw_val.getClass() == bindings.LDKAPIError.ChannelUnavailable.class) {
34 return new ChannelUnavailable(ptr, (bindings.LDKAPIError.ChannelUnavailable)raw_val);
36 if (raw_val.getClass() == bindings.LDKAPIError.MonitorUpdateFailed.class) {
37 return new MonitorUpdateFailed(ptr, (bindings.LDKAPIError.MonitorUpdateFailed)raw_val);
39 if (raw_val.getClass() == bindings.LDKAPIError.IncompatibleShutdownScript.class) {
40 return new IncompatibleShutdownScript(ptr, (bindings.LDKAPIError.IncompatibleShutdownScript)raw_val);
42 assert false; return null; // Unreachable without extending the (internal) bindings interface
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.
49 public final static class APIMisuseError extends APIError {
51 * A human-readable error message
53 public final String err;
54 private APIMisuseError(long ptr, bindings.LDKAPIError.APIMisuseError obj) {
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.
64 public final static class FeeRateTooHigh extends APIError {
66 * A human-readable error message
68 public final String err;
70 * The feerate which was too high.
72 public final int feerate;
73 private FeeRateTooHigh(long ptr, bindings.LDKAPIError.FeeRateTooHigh obj) {
76 this.feerate = obj.feerate;
80 * A malformed Route was provided (eg overflowed value, node id mismatch, overly-looped route,
81 * too-many-hops, etc).
83 public final static class RouteError extends APIError {
85 * A human-readable error message
87 public final String err;
88 private RouteError(long ptr, bindings.LDKAPIError.RouteError obj) {
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.
98 public final static class ChannelUnavailable extends APIError {
100 * A human-readable error message
102 public final String err;
103 private ChannelUnavailable(long ptr, bindings.LDKAPIError.ChannelUnavailable obj) {
109 * An attempt to call watch/update_channel returned an Err (ie you did this!), causing the
110 * attempted action to fail.
112 public final static class MonitorUpdateFailed extends APIError {
113 private MonitorUpdateFailed(long ptr, bindings.LDKAPIError.MonitorUpdateFailed obj) {
118 * [`KeysInterface::get_shutdown_scriptpubkey`] returned a shutdown scriptpubkey incompatible
119 * with the channel counterparty as negotiated in [`InitFeatures`].
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).
124 * [`KeysInterface::get_shutdown_scriptpubkey`]: crate::chain::keysinterface::KeysInterface::get_shutdown_scriptpubkey
125 * [`InitFeatures`]: crate::ln::features::InitFeatures
127 public final static class IncompatibleShutdownScript extends APIError {
129 * The incompatible shutdown script.
131 public final ShutdownScript script;
132 private IncompatibleShutdownScript(long ptr, bindings.LDKAPIError.IncompatibleShutdownScript obj) {
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;
141 long ret = bindings.APIError_clone_ptr(this.ptr);
146 * Creates a copy of the APIError
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);
157 * Utility method to constructs a new APIMisuseError-variant APIError
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);
168 * Utility method to constructs a new FeeRateTooHigh-variant APIError
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);
179 * Utility method to constructs a new RouteError-variant APIError
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);
190 * Utility method to constructs a new ChannelUnavailable-variant APIError
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);
201 * Utility method to constructs a new MonitorUpdateFailed-variant APIError
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);
212 * Utility method to constructs a new IncompatibleShutdownScript-variant APIError
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);