a79de30933c4be8ac0c66489ac40f22404bd769a
[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_custom_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                 assert false; return null; // Unreachable without extending the (internal) bindings interface
45         }
46
47         /**
48          * Errored computing onion message packet keys.
49          */
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) {
53                         super(null, ptr);
54                         this.secp256k1 = obj.secp256k1;
55                 }
56         }
57         /**
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.
60          */
61         public final static class TooBigPacket extends SendError {
62                 private TooBigPacket(long ptr, bindings.LDKSendError.TooBigPacket obj) {
63                         super(null, ptr);
64                 }
65         }
66         /**
67          * The provided [`Destination`] was an invalid [`BlindedRoute`], due to having fewer than two
68          * blinded hops.
69          */
70         public final static class TooFewBlindedHops extends SendError {
71                 private TooFewBlindedHops(long ptr, bindings.LDKSendError.TooFewBlindedHops obj) {
72                         super(null, ptr);
73                 }
74         }
75         /**
76          * Our next-hop peer was offline or does not support onion message forwarding.
77          */
78         public final static class InvalidFirstHop extends SendError {
79                 private InvalidFirstHop(long ptr, bindings.LDKSendError.InvalidFirstHop obj) {
80                         super(null, ptr);
81                 }
82         }
83         /**
84          * Onion message contents must have a TLV type >= 64.
85          */
86         public final static class InvalidMessage extends SendError {
87                 private InvalidMessage(long ptr, bindings.LDKSendError.InvalidMessage obj) {
88                         super(null, ptr);
89                 }
90         }
91         /**
92          * Our next-hop peer's buffer was full or our total outbound buffer was full.
93          */
94         public final static class BufferFull extends SendError {
95                 private BufferFull(long ptr, bindings.LDKSendError.BufferFull obj) {
96                         super(null, ptr);
97                 }
98         }
99         long clone_ptr() {
100                 long ret = bindings.SendError_clone_ptr(this.ptr);
101                 Reference.reachabilityFence(this);
102                 return ret;
103         }
104
105         /**
106          * Creates a copy of the SendError
107          */
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); };
114                 return ret_hu_conv;
115         }
116
117         /**
118          * Utility method to constructs a new Secp256k1-variant SendError
119          */
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); };
126                 return ret_hu_conv;
127         }
128
129         /**
130          * Utility method to constructs a new TooBigPacket-variant SendError
131          */
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); };
137                 return ret_hu_conv;
138         }
139
140         /**
141          * Utility method to constructs a new TooFewBlindedHops-variant SendError
142          */
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); };
148                 return ret_hu_conv;
149         }
150
151         /**
152          * Utility method to constructs a new InvalidFirstHop-variant SendError
153          */
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); };
159                 return ret_hu_conv;
160         }
161
162         /**
163          * Utility method to constructs a new InvalidMessage-variant SendError
164          */
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); };
170                 return ret_hu_conv;
171         }
172
173         /**
174          * Utility method to constructs a new BufferFull-variant SendError
175          */
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); };
181                 return ret_hu_conv;
182         }
183
184         /**
185          * Checks if two SendErrors contain equal inner contents.
186          * This ignores pointers and is_owned flags and looks at the values in fields.
187          */
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);
192                 return ret;
193         }
194
195         @Override public boolean equals(Object o) {
196                 if (!(o instanceof SendError)) return false;
197                 return this.eq((SendError)o);
198         }
199 }