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_custom_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.InvalidMessage.class) {
39 return new InvalidMessage(ptr, (bindings.LDKSendError.InvalidMessage)raw_val);
41 if (raw_val.getClass() == bindings.LDKSendError.BufferFull.class) {
42 return new BufferFull(ptr, (bindings.LDKSendError.BufferFull)raw_val);
44 assert false; return null; // Unreachable without extending the (internal) bindings interface
48 * Errored computing onion message packet keys.
50 public final static class Secp256k1 extends SendError {
51 public final org.ldk.enums.Secp256k1Error secp256k1;
52 private Secp256k1(long ptr, bindings.LDKSendError.Secp256k1 obj) {
54 this.secp256k1 = obj.secp256k1;
58 * Because implementations such as Eclair will drop onion messages where the message packet
59 * exceeds 32834 bytes, we refuse to send messages where the packet exceeds this size.
61 public final static class TooBigPacket extends SendError {
62 private TooBigPacket(long ptr, bindings.LDKSendError.TooBigPacket obj) {
67 * The provided [`Destination`] was an invalid [`BlindedRoute`], due to having fewer than two
70 public final static class TooFewBlindedHops extends SendError {
71 private TooFewBlindedHops(long ptr, bindings.LDKSendError.TooFewBlindedHops obj) {
76 * Our next-hop peer was offline or does not support onion message forwarding.
78 public final static class InvalidFirstHop extends SendError {
79 private InvalidFirstHop(long ptr, bindings.LDKSendError.InvalidFirstHop obj) {
84 * Onion message contents must have a TLV type >= 64.
86 public final static class InvalidMessage extends SendError {
87 private InvalidMessage(long ptr, bindings.LDKSendError.InvalidMessage obj) {
92 * Our next-hop peer's buffer was full or our total outbound buffer was full.
94 public final static class BufferFull extends SendError {
95 private BufferFull(long ptr, bindings.LDKSendError.BufferFull obj) {
100 long ret = bindings.SendError_clone_ptr(this.ptr);
101 Reference.reachabilityFence(this);
106 * Creates a copy of the SendError
108 public SendError clone() {
109 long ret = bindings.SendError_clone(this.ptr);
110 Reference.reachabilityFence(this);
111 if (ret >= 0 && ret <= 4096) { return null; }
112 org.ldk.structs.SendError ret_hu_conv = org.ldk.structs.SendError.constr_from_ptr(ret);
113 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
118 * Utility method to constructs a new Secp256k1-variant SendError
120 public static SendError secp256k1(org.ldk.enums.Secp256k1Error a) {
121 long ret = bindings.SendError_secp256k1(a);
122 Reference.reachabilityFence(a);
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 TooBigPacket-variant SendError
132 public static SendError too_big_packet() {
133 long ret = bindings.SendError_too_big_packet();
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 TooFewBlindedHops-variant SendError
143 public static SendError too_few_blinded_hops() {
144 long ret = bindings.SendError_too_few_blinded_hops();
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 InvalidFirstHop-variant SendError
154 public static SendError invalid_first_hop() {
155 long ret = bindings.SendError_invalid_first_hop();
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); };
163 * Utility method to constructs a new InvalidMessage-variant SendError
165 public static SendError invalid_message() {
166 long ret = bindings.SendError_invalid_message();
167 if (ret >= 0 && ret <= 4096) { return null; }
168 org.ldk.structs.SendError ret_hu_conv = org.ldk.structs.SendError.constr_from_ptr(ret);
169 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
174 * Utility method to constructs a new BufferFull-variant SendError
176 public static SendError buffer_full() {
177 long ret = bindings.SendError_buffer_full();
178 if (ret >= 0 && ret <= 4096) { return null; }
179 org.ldk.structs.SendError ret_hu_conv = org.ldk.structs.SendError.constr_from_ptr(ret);
180 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
185 * Checks if two SendErrors contain equal inner contents.
186 * This ignores pointers and is_owned flags and looks at the values in fields.
188 public boolean eq(SendError b) {
189 boolean ret = bindings.SendError_eq(this.ptr, b == null ? 0 : b.ptr);
190 Reference.reachabilityFence(this);
191 Reference.reachabilityFence(b);
195 @Override public boolean equals(Object o) {
196 if (!(o instanceof SendError)) return false;
197 return this.eq((SendError)o);