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 * Errors that may occur when [sending an onion message].
14 * [sending an onion message]: OnionMessenger::send_onion_message
16 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
17 public class SendError extends CommonBase {
18 private SendError(Object _dummy, long ptr) { super(ptr); }
19 @Override @SuppressWarnings("deprecation")
20 protected void finalize() throws Throwable {
22 if (ptr != 0) { bindings.SendError_free(ptr); }
24 static SendError constr_from_ptr(long ptr) {
25 bindings.LDKSendError raw_val = bindings.LDKSendError_ref_from_ptr(ptr);
26 if (raw_val.getClass() == bindings.LDKSendError.Secp256k1.class) {
27 return new Secp256k1(ptr, (bindings.LDKSendError.Secp256k1)raw_val);
29 if (raw_val.getClass() == bindings.LDKSendError.TooBigPacket.class) {
30 return new TooBigPacket(ptr, (bindings.LDKSendError.TooBigPacket)raw_val);
32 if (raw_val.getClass() == bindings.LDKSendError.TooFewBlindedHops.class) {
33 return new TooFewBlindedHops(ptr, (bindings.LDKSendError.TooFewBlindedHops)raw_val);
35 if (raw_val.getClass() == bindings.LDKSendError.InvalidFirstHop.class) {
36 return new InvalidFirstHop(ptr, (bindings.LDKSendError.InvalidFirstHop)raw_val);
38 if (raw_val.getClass() == bindings.LDKSendError.BufferFull.class) {
39 return new BufferFull(ptr, (bindings.LDKSendError.BufferFull)raw_val);
41 assert false; return null; // Unreachable without extending the (internal) bindings interface
45 * Errored computing onion message packet keys.
47 public final static class Secp256k1 extends SendError {
48 public final org.ldk.enums.Secp256k1Error secp256k1;
49 private Secp256k1(long ptr, bindings.LDKSendError.Secp256k1 obj) {
51 this.secp256k1 = obj.secp256k1;
55 * Because implementations such as Eclair will drop onion messages where the message packet
56 * exceeds 32834 bytes, we refuse to send messages where the packet exceeds this size.
58 public final static class TooBigPacket extends SendError {
59 private TooBigPacket(long ptr, bindings.LDKSendError.TooBigPacket obj) {
64 * The provided [`Destination`] was an invalid [`BlindedRoute`], due to having fewer than two
67 public final static class TooFewBlindedHops extends SendError {
68 private TooFewBlindedHops(long ptr, bindings.LDKSendError.TooFewBlindedHops obj) {
73 * Our next-hop peer was offline or does not support onion message forwarding.
75 public final static class InvalidFirstHop extends SendError {
76 private InvalidFirstHop(long ptr, bindings.LDKSendError.InvalidFirstHop obj) {
81 * Our next-hop peer's buffer was full or our total outbound buffer was full.
83 public final static class BufferFull extends SendError {
84 private BufferFull(long ptr, bindings.LDKSendError.BufferFull obj) {
89 long ret = bindings.SendError_clone_ptr(this.ptr);
90 Reference.reachabilityFence(this);
95 * Creates a copy of the SendError
97 public SendError clone() {
98 long ret = bindings.SendError_clone(this.ptr);
99 Reference.reachabilityFence(this);
100 if (ret >= 0 && ret <= 4096) { return null; }
101 org.ldk.structs.SendError ret_hu_conv = org.ldk.structs.SendError.constr_from_ptr(ret);
102 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
107 * Utility method to constructs a new Secp256k1-variant SendError
109 public static SendError secp256k1(org.ldk.enums.Secp256k1Error a) {
110 long ret = bindings.SendError_secp256k1(a);
111 Reference.reachabilityFence(a);
112 if (ret >= 0 && ret <= 4096) { return null; }
113 org.ldk.structs.SendError ret_hu_conv = org.ldk.structs.SendError.constr_from_ptr(ret);
114 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
119 * Utility method to constructs a new TooBigPacket-variant SendError
121 public static SendError too_big_packet() {
122 long ret = bindings.SendError_too_big_packet();
123 if (ret >= 0 && ret <= 4096) { return null; }
124 org.ldk.structs.SendError ret_hu_conv = org.ldk.structs.SendError.constr_from_ptr(ret);
125 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
130 * Utility method to constructs a new TooFewBlindedHops-variant SendError
132 public static SendError too_few_blinded_hops() {
133 long ret = bindings.SendError_too_few_blinded_hops();
134 if (ret >= 0 && ret <= 4096) { return null; }
135 org.ldk.structs.SendError ret_hu_conv = org.ldk.structs.SendError.constr_from_ptr(ret);
136 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
141 * Utility method to constructs a new InvalidFirstHop-variant SendError
143 public static SendError invalid_first_hop() {
144 long ret = bindings.SendError_invalid_first_hop();
145 if (ret >= 0 && ret <= 4096) { return null; }
146 org.ldk.structs.SendError ret_hu_conv = org.ldk.structs.SendError.constr_from_ptr(ret);
147 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
152 * Utility method to constructs a new BufferFull-variant SendError
154 public static SendError buffer_full() {
155 long ret = bindings.SendError_buffer_full();
156 if (ret >= 0 && ret <= 4096) { return null; }
157 org.ldk.structs.SendError ret_hu_conv = org.ldk.structs.SendError.constr_from_ptr(ret);
158 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };