[Java] Update auto-generated Java bindings to LDK 0.0.121
[ldk-java] / src / main / java / org / ldk / structs / ErrorAction.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  * Used to put an error message in a [`LightningError`].
13  */
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class ErrorAction extends CommonBase {
16         private ErrorAction(Object _dummy, long ptr) { super(ptr); }
17         @Override @SuppressWarnings("deprecation")
18         protected void finalize() throws Throwable {
19                 super.finalize();
20                 if (ptr != 0) { bindings.ErrorAction_free(ptr); }
21         }
22         static ErrorAction constr_from_ptr(long ptr) {
23                 bindings.LDKErrorAction raw_val = bindings.LDKErrorAction_ref_from_ptr(ptr);
24                 if (raw_val.getClass() == bindings.LDKErrorAction.DisconnectPeer.class) {
25                         return new DisconnectPeer(ptr, (bindings.LDKErrorAction.DisconnectPeer)raw_val);
26                 }
27                 if (raw_val.getClass() == bindings.LDKErrorAction.DisconnectPeerWithWarning.class) {
28                         return new DisconnectPeerWithWarning(ptr, (bindings.LDKErrorAction.DisconnectPeerWithWarning)raw_val);
29                 }
30                 if (raw_val.getClass() == bindings.LDKErrorAction.IgnoreError.class) {
31                         return new IgnoreError(ptr, (bindings.LDKErrorAction.IgnoreError)raw_val);
32                 }
33                 if (raw_val.getClass() == bindings.LDKErrorAction.IgnoreAndLog.class) {
34                         return new IgnoreAndLog(ptr, (bindings.LDKErrorAction.IgnoreAndLog)raw_val);
35                 }
36                 if (raw_val.getClass() == bindings.LDKErrorAction.IgnoreDuplicateGossip.class) {
37                         return new IgnoreDuplicateGossip(ptr, (bindings.LDKErrorAction.IgnoreDuplicateGossip)raw_val);
38                 }
39                 if (raw_val.getClass() == bindings.LDKErrorAction.SendErrorMessage.class) {
40                         return new SendErrorMessage(ptr, (bindings.LDKErrorAction.SendErrorMessage)raw_val);
41                 }
42                 if (raw_val.getClass() == bindings.LDKErrorAction.SendWarningMessage.class) {
43                         return new SendWarningMessage(ptr, (bindings.LDKErrorAction.SendWarningMessage)raw_val);
44                 }
45                 assert false; return null; // Unreachable without extending the (internal) bindings interface
46         }
47
48         /**
49          * The peer took some action which made us think they were useless. Disconnect them.
50          */
51         public final static class DisconnectPeer extends ErrorAction {
52                 /**
53                  * An error message which we should make an effort to send before we disconnect.
54                  * 
55                  * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
56                 */
57                 @Nullable public final org.ldk.structs.ErrorMessage msg;
58                 private DisconnectPeer(long ptr, bindings.LDKErrorAction.DisconnectPeer obj) {
59                         super(null, ptr);
60                         long msg = obj.msg;
61                         org.ldk.structs.ErrorMessage msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.ErrorMessage(null, msg); }
62                         if (msg_hu_conv != null) { msg_hu_conv.ptrs_to.add(this); };
63                         this.msg = msg_hu_conv;
64                 }
65         }
66         /**
67          * The peer did something incorrect. Tell them without closing any channels and disconnect them.
68          */
69         public final static class DisconnectPeerWithWarning extends ErrorAction {
70                 /**
71                  * A warning message which we should make an effort to send before we disconnect.
72                 */
73                 public final org.ldk.structs.WarningMessage msg;
74                 private DisconnectPeerWithWarning(long ptr, bindings.LDKErrorAction.DisconnectPeerWithWarning obj) {
75                         super(null, ptr);
76                         long msg = obj.msg;
77                         org.ldk.structs.WarningMessage msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.WarningMessage(null, msg); }
78                         if (msg_hu_conv != null) { msg_hu_conv.ptrs_to.add(this); };
79                         this.msg = msg_hu_conv;
80                 }
81         }
82         /**
83          * The peer did something harmless that we weren't able to process, just log and ignore
84          */
85         public final static class IgnoreError extends ErrorAction {
86                 private IgnoreError(long ptr, bindings.LDKErrorAction.IgnoreError obj) {
87                         super(null, ptr);
88                 }
89         }
90         /**
91          * The peer did something harmless that we weren't able to meaningfully process.
92          * If the error is logged, log it at the given level.
93          */
94         public final static class IgnoreAndLog extends ErrorAction {
95                 public final org.ldk.enums.Level ignore_and_log;
96                 private IgnoreAndLog(long ptr, bindings.LDKErrorAction.IgnoreAndLog obj) {
97                         super(null, ptr);
98                         this.ignore_and_log = obj.ignore_and_log;
99                 }
100         }
101         /**
102          * The peer provided us with a gossip message which we'd already seen. In most cases this
103          * should be ignored, but it may result in the message being forwarded if it is a duplicate of
104          * our own channel announcements.
105          */
106         public final static class IgnoreDuplicateGossip extends ErrorAction {
107                 private IgnoreDuplicateGossip(long ptr, bindings.LDKErrorAction.IgnoreDuplicateGossip obj) {
108                         super(null, ptr);
109                 }
110         }
111         /**
112          * The peer did something incorrect. Tell them.
113          */
114         public final static class SendErrorMessage extends ErrorAction {
115                 /**
116                  * The message to send.
117                 */
118                 public final org.ldk.structs.ErrorMessage msg;
119                 private SendErrorMessage(long ptr, bindings.LDKErrorAction.SendErrorMessage obj) {
120                         super(null, ptr);
121                         long msg = obj.msg;
122                         org.ldk.structs.ErrorMessage msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.ErrorMessage(null, msg); }
123                         if (msg_hu_conv != null) { msg_hu_conv.ptrs_to.add(this); };
124                         this.msg = msg_hu_conv;
125                 }
126         }
127         /**
128          * The peer did something incorrect. Tell them without closing any channels.
129          */
130         public final static class SendWarningMessage extends ErrorAction {
131                 /**
132                  * The message to send.
133                 */
134                 public final org.ldk.structs.WarningMessage msg;
135                 /**
136                  * The peer may have done something harmless that we weren't able to meaningfully process,
137                  * though we should still tell them about it.
138                  * If this event is logged, log it at the given level.
139                 */
140                 public final org.ldk.enums.Level log_level;
141                 private SendWarningMessage(long ptr, bindings.LDKErrorAction.SendWarningMessage obj) {
142                         super(null, ptr);
143                         long msg = obj.msg;
144                         org.ldk.structs.WarningMessage msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.WarningMessage(null, msg); }
145                         if (msg_hu_conv != null) { msg_hu_conv.ptrs_to.add(this); };
146                         this.msg = msg_hu_conv;
147                         this.log_level = obj.log_level;
148                 }
149         }
150         long clone_ptr() {
151                 long ret = bindings.ErrorAction_clone_ptr(this.ptr);
152                 Reference.reachabilityFence(this);
153                 return ret;
154         }
155
156         /**
157          * Creates a copy of the ErrorAction
158          */
159         public ErrorAction clone() {
160                 long ret = bindings.ErrorAction_clone(this.ptr);
161                 Reference.reachabilityFence(this);
162                 if (ret >= 0 && ret <= 4096) { return null; }
163                 org.ldk.structs.ErrorAction ret_hu_conv = org.ldk.structs.ErrorAction.constr_from_ptr(ret);
164                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
165                 return ret_hu_conv;
166         }
167
168         /**
169          * Utility method to constructs a new DisconnectPeer-variant ErrorAction
170          */
171         public static ErrorAction disconnect_peer(org.ldk.structs.ErrorMessage msg) {
172                 long ret = bindings.ErrorAction_disconnect_peer(msg == null ? 0 : msg.ptr);
173                 Reference.reachabilityFence(msg);
174                 if (ret >= 0 && ret <= 4096) { return null; }
175                 org.ldk.structs.ErrorAction ret_hu_conv = org.ldk.structs.ErrorAction.constr_from_ptr(ret);
176                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
177                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(msg); };
178                 return ret_hu_conv;
179         }
180
181         /**
182          * Utility method to constructs a new DisconnectPeerWithWarning-variant ErrorAction
183          */
184         public static ErrorAction disconnect_peer_with_warning(org.ldk.structs.WarningMessage msg) {
185                 long ret = bindings.ErrorAction_disconnect_peer_with_warning(msg == null ? 0 : msg.ptr);
186                 Reference.reachabilityFence(msg);
187                 if (ret >= 0 && ret <= 4096) { return null; }
188                 org.ldk.structs.ErrorAction ret_hu_conv = org.ldk.structs.ErrorAction.constr_from_ptr(ret);
189                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
190                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(msg); };
191                 return ret_hu_conv;
192         }
193
194         /**
195          * Utility method to constructs a new IgnoreError-variant ErrorAction
196          */
197         public static ErrorAction ignore_error() {
198                 long ret = bindings.ErrorAction_ignore_error();
199                 if (ret >= 0 && ret <= 4096) { return null; }
200                 org.ldk.structs.ErrorAction ret_hu_conv = org.ldk.structs.ErrorAction.constr_from_ptr(ret);
201                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
202                 return ret_hu_conv;
203         }
204
205         /**
206          * Utility method to constructs a new IgnoreAndLog-variant ErrorAction
207          */
208         public static ErrorAction ignore_and_log(org.ldk.enums.Level a) {
209                 long ret = bindings.ErrorAction_ignore_and_log(a);
210                 Reference.reachabilityFence(a);
211                 if (ret >= 0 && ret <= 4096) { return null; }
212                 org.ldk.structs.ErrorAction ret_hu_conv = org.ldk.structs.ErrorAction.constr_from_ptr(ret);
213                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
214                 return ret_hu_conv;
215         }
216
217         /**
218          * Utility method to constructs a new IgnoreDuplicateGossip-variant ErrorAction
219          */
220         public static ErrorAction ignore_duplicate_gossip() {
221                 long ret = bindings.ErrorAction_ignore_duplicate_gossip();
222                 if (ret >= 0 && ret <= 4096) { return null; }
223                 org.ldk.structs.ErrorAction ret_hu_conv = org.ldk.structs.ErrorAction.constr_from_ptr(ret);
224                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
225                 return ret_hu_conv;
226         }
227
228         /**
229          * Utility method to constructs a new SendErrorMessage-variant ErrorAction
230          */
231         public static ErrorAction send_error_message(org.ldk.structs.ErrorMessage msg) {
232                 long ret = bindings.ErrorAction_send_error_message(msg == null ? 0 : msg.ptr);
233                 Reference.reachabilityFence(msg);
234                 if (ret >= 0 && ret <= 4096) { return null; }
235                 org.ldk.structs.ErrorAction ret_hu_conv = org.ldk.structs.ErrorAction.constr_from_ptr(ret);
236                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
237                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(msg); };
238                 return ret_hu_conv;
239         }
240
241         /**
242          * Utility method to constructs a new SendWarningMessage-variant ErrorAction
243          */
244         public static ErrorAction send_warning_message(org.ldk.structs.WarningMessage msg, org.ldk.enums.Level log_level) {
245                 long ret = bindings.ErrorAction_send_warning_message(msg == null ? 0 : msg.ptr, log_level);
246                 Reference.reachabilityFence(msg);
247                 Reference.reachabilityFence(log_level);
248                 if (ret >= 0 && ret <= 4096) { return null; }
249                 org.ldk.structs.ErrorAction ret_hu_conv = org.ldk.structs.ErrorAction.constr_from_ptr(ret);
250                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
251                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(msg); };
252                 return ret_hu_conv;
253         }
254
255         /**
256          * Generates a non-cryptographic 64-bit hash of the ErrorAction.
257          */
258         public long hash() {
259                 long ret = bindings.ErrorAction_hash(this.ptr);
260                 Reference.reachabilityFence(this);
261                 return ret;
262         }
263
264         @Override public int hashCode() {
265                 return (int)this.hash();
266         }
267 }