44c877f09d326011c010c7837d0b40801092a820
[ldk-java] / src / main / java / org / ldk / structs / SendError.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 java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10
11 /**
12  * Errors that may occur when [sending an onion message].
13  * 
14  * [sending an onion message]: OnionMessenger::send_onion_message
15  */
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 {
21                 super.finalize();
22                 if (ptr != 0) { bindings.SendError_free(ptr); }
23         }
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);
28                 }
29                 if (raw_val.getClass() == bindings.LDKSendError.TooBigPacket.class) {
30                         return new TooBigPacket(ptr, (bindings.LDKSendError.TooBigPacket)raw_val);
31                 }
32                 if (raw_val.getClass() == bindings.LDKSendError.TooFewBlindedHops.class) {
33                         return new TooFewBlindedHops(ptr, (bindings.LDKSendError.TooFewBlindedHops)raw_val);
34                 }
35                 if (raw_val.getClass() == bindings.LDKSendError.InvalidFirstHop.class) {
36                         return new InvalidFirstHop(ptr, (bindings.LDKSendError.InvalidFirstHop)raw_val);
37                 }
38                 if (raw_val.getClass() == bindings.LDKSendError.InvalidMessage.class) {
39                         return new InvalidMessage(ptr, (bindings.LDKSendError.InvalidMessage)raw_val);
40                 }
41                 if (raw_val.getClass() == bindings.LDKSendError.BufferFull.class) {
42                         return new BufferFull(ptr, (bindings.LDKSendError.BufferFull)raw_val);
43                 }
44                 if (raw_val.getClass() == bindings.LDKSendError.GetNodeIdFailed.class) {
45                         return new GetNodeIdFailed(ptr, (bindings.LDKSendError.GetNodeIdFailed)raw_val);
46                 }
47                 if (raw_val.getClass() == bindings.LDKSendError.BlindedPathAdvanceFailed.class) {
48                         return new BlindedPathAdvanceFailed(ptr, (bindings.LDKSendError.BlindedPathAdvanceFailed)raw_val);
49                 }
50                 assert false; return null; // Unreachable without extending the (internal) bindings interface
51         }
52
53         /**
54          * Errored computing onion message packet keys.
55          */
56         public final static class Secp256k1 extends SendError {
57                 public final org.ldk.enums.Secp256k1Error secp256k1;
58                 private Secp256k1(long ptr, bindings.LDKSendError.Secp256k1 obj) {
59                         super(null, ptr);
60                         this.secp256k1 = obj.secp256k1;
61                 }
62         }
63         /**
64          * Because implementations such as Eclair will drop onion messages where the message packet
65          * exceeds 32834 bytes, we refuse to send messages where the packet exceeds this size.
66          */
67         public final static class TooBigPacket extends SendError {
68                 private TooBigPacket(long ptr, bindings.LDKSendError.TooBigPacket obj) {
69                         super(null, ptr);
70                 }
71         }
72         /**
73          * The provided [`Destination`] was an invalid [`BlindedPath`], due to having fewer than two
74          * blinded hops.
75          */
76         public final static class TooFewBlindedHops extends SendError {
77                 private TooFewBlindedHops(long ptr, bindings.LDKSendError.TooFewBlindedHops obj) {
78                         super(null, ptr);
79                 }
80         }
81         /**
82          * Our next-hop peer was offline or does not support onion message forwarding.
83          */
84         public final static class InvalidFirstHop extends SendError {
85                 private InvalidFirstHop(long ptr, bindings.LDKSendError.InvalidFirstHop obj) {
86                         super(null, ptr);
87                 }
88         }
89         /**
90          * Onion message contents must have a TLV type >= 64.
91          */
92         public final static class InvalidMessage extends SendError {
93                 private InvalidMessage(long ptr, bindings.LDKSendError.InvalidMessage obj) {
94                         super(null, ptr);
95                 }
96         }
97         /**
98          * Our next-hop peer's buffer was full or our total outbound buffer was full.
99          */
100         public final static class BufferFull extends SendError {
101                 private BufferFull(long ptr, bindings.LDKSendError.BufferFull obj) {
102                         super(null, ptr);
103                 }
104         }
105         /**
106          * Failed to retrieve our node id from the provided [`NodeSigner`].
107          * 
108          * [`NodeSigner`]: crate::sign::NodeSigner
109          */
110         public final static class GetNodeIdFailed extends SendError {
111                 private GetNodeIdFailed(long ptr, bindings.LDKSendError.GetNodeIdFailed obj) {
112                         super(null, ptr);
113                 }
114         }
115         /**
116          * We attempted to send to a blinded path where we are the introduction node, and failed to
117          * advance the blinded path to make the second hop the new introduction node. Either
118          * [`NodeSigner::ecdh`] failed, we failed to tweak the current blinding point to get the
119          * new blinding point, or we were attempting to send to ourselves.
120          */
121         public final static class BlindedPathAdvanceFailed extends SendError {
122                 private BlindedPathAdvanceFailed(long ptr, bindings.LDKSendError.BlindedPathAdvanceFailed obj) {
123                         super(null, ptr);
124                 }
125         }
126         long clone_ptr() {
127                 long ret = bindings.SendError_clone_ptr(this.ptr);
128                 Reference.reachabilityFence(this);
129                 return ret;
130         }
131
132         /**
133          * Creates a copy of the SendError
134          */
135         public SendError clone() {
136                 long ret = bindings.SendError_clone(this.ptr);
137                 Reference.reachabilityFence(this);
138                 if (ret >= 0 && ret <= 4096) { return null; }
139                 org.ldk.structs.SendError ret_hu_conv = org.ldk.structs.SendError.constr_from_ptr(ret);
140                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
141                 return ret_hu_conv;
142         }
143
144         /**
145          * Utility method to constructs a new Secp256k1-variant SendError
146          */
147         public static SendError secp256k1(org.ldk.enums.Secp256k1Error a) {
148                 long ret = bindings.SendError_secp256k1(a);
149                 Reference.reachabilityFence(a);
150                 if (ret >= 0 && ret <= 4096) { return null; }
151                 org.ldk.structs.SendError ret_hu_conv = org.ldk.structs.SendError.constr_from_ptr(ret);
152                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
153                 return ret_hu_conv;
154         }
155
156         /**
157          * Utility method to constructs a new TooBigPacket-variant SendError
158          */
159         public static SendError too_big_packet() {
160                 long ret = bindings.SendError_too_big_packet();
161                 if (ret >= 0 && ret <= 4096) { return null; }
162                 org.ldk.structs.SendError ret_hu_conv = org.ldk.structs.SendError.constr_from_ptr(ret);
163                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
164                 return ret_hu_conv;
165         }
166
167         /**
168          * Utility method to constructs a new TooFewBlindedHops-variant SendError
169          */
170         public static SendError too_few_blinded_hops() {
171                 long ret = bindings.SendError_too_few_blinded_hops();
172                 if (ret >= 0 && ret <= 4096) { return null; }
173                 org.ldk.structs.SendError ret_hu_conv = org.ldk.structs.SendError.constr_from_ptr(ret);
174                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
175                 return ret_hu_conv;
176         }
177
178         /**
179          * Utility method to constructs a new InvalidFirstHop-variant SendError
180          */
181         public static SendError invalid_first_hop() {
182                 long ret = bindings.SendError_invalid_first_hop();
183                 if (ret >= 0 && ret <= 4096) { return null; }
184                 org.ldk.structs.SendError ret_hu_conv = org.ldk.structs.SendError.constr_from_ptr(ret);
185                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
186                 return ret_hu_conv;
187         }
188
189         /**
190          * Utility method to constructs a new InvalidMessage-variant SendError
191          */
192         public static SendError invalid_message() {
193                 long ret = bindings.SendError_invalid_message();
194                 if (ret >= 0 && ret <= 4096) { return null; }
195                 org.ldk.structs.SendError ret_hu_conv = org.ldk.structs.SendError.constr_from_ptr(ret);
196                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
197                 return ret_hu_conv;
198         }
199
200         /**
201          * Utility method to constructs a new BufferFull-variant SendError
202          */
203         public static SendError buffer_full() {
204                 long ret = bindings.SendError_buffer_full();
205                 if (ret >= 0 && ret <= 4096) { return null; }
206                 org.ldk.structs.SendError ret_hu_conv = org.ldk.structs.SendError.constr_from_ptr(ret);
207                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
208                 return ret_hu_conv;
209         }
210
211         /**
212          * Utility method to constructs a new GetNodeIdFailed-variant SendError
213          */
214         public static SendError get_node_id_failed() {
215                 long ret = bindings.SendError_get_node_id_failed();
216                 if (ret >= 0 && ret <= 4096) { return null; }
217                 org.ldk.structs.SendError ret_hu_conv = org.ldk.structs.SendError.constr_from_ptr(ret);
218                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
219                 return ret_hu_conv;
220         }
221
222         /**
223          * Utility method to constructs a new BlindedPathAdvanceFailed-variant SendError
224          */
225         public static SendError blinded_path_advance_failed() {
226                 long ret = bindings.SendError_blinded_path_advance_failed();
227                 if (ret >= 0 && ret <= 4096) { return null; }
228                 org.ldk.structs.SendError ret_hu_conv = org.ldk.structs.SendError.constr_from_ptr(ret);
229                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
230                 return ret_hu_conv;
231         }
232
233         /**
234          * Checks if two SendErrors contain equal inner contents.
235          * This ignores pointers and is_owned flags and looks at the values in fields.
236          */
237         public boolean eq(org.ldk.structs.SendError b) {
238                 boolean ret = bindings.SendError_eq(this.ptr, b == null ? 0 : b.ptr);
239                 Reference.reachabilityFence(this);
240                 Reference.reachabilityFence(b);
241                 return ret;
242         }
243
244         @Override public boolean equals(Object o) {
245                 if (!(o instanceof SendError)) return false;
246                 return this.eq((SendError)o);
247         }
248 }