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 * An [`error`] message to be sent to or received from a peer.
14 * [`error`]: https://github.com/lightning/bolts/blob/master/01-messaging.md#the-error-and-warning-messages
16 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
17 public class ErrorMessage extends CommonBase {
18 ErrorMessage(Object _dummy, long ptr) { super(ptr); }
19 @Override @SuppressWarnings("deprecation")
20 protected void finalize() throws Throwable {
22 if (ptr != 0) { bindings.ErrorMessage_free(ptr); }
26 * The channel ID involved in the error.
28 * All-0s indicates a general error unrelated to a specific channel, after which all channels
29 * with the sending peer should be closed.
31 public byte[] get_channel_id() {
32 byte[] ret = bindings.ErrorMessage_get_channel_id(this.ptr);
33 Reference.reachabilityFence(this);
38 * The channel ID involved in the error.
40 * All-0s indicates a general error unrelated to a specific channel, after which all channels
41 * with the sending peer should be closed.
43 public void set_channel_id(byte[] val) {
44 bindings.ErrorMessage_set_channel_id(this.ptr, InternalUtils.check_arr_len(val, 32));
45 Reference.reachabilityFence(this);
46 Reference.reachabilityFence(val);
50 * A possibly human-readable error description.
52 * The string should be sanitized before it is used (e.g., emitted to logs or printed to
53 * `stdout`). Otherwise, a well crafted error message may trigger a security vulnerability in
54 * the terminal emulator or the logging subsystem.
56 public String get_data() {
57 String ret = bindings.ErrorMessage_get_data(this.ptr);
58 Reference.reachabilityFence(this);
63 * A possibly human-readable error description.
65 * The string should be sanitized before it is used (e.g., emitted to logs or printed to
66 * `stdout`). Otherwise, a well crafted error message may trigger a security vulnerability in
67 * the terminal emulator or the logging subsystem.
69 public void set_data(java.lang.String val) {
70 bindings.ErrorMessage_set_data(this.ptr, val);
71 Reference.reachabilityFence(this);
72 Reference.reachabilityFence(val);
76 * Constructs a new ErrorMessage given each field
78 public static ErrorMessage of(byte[] channel_id_arg, java.lang.String data_arg) {
79 long ret = bindings.ErrorMessage_new(InternalUtils.check_arr_len(channel_id_arg, 32), data_arg);
80 Reference.reachabilityFence(channel_id_arg);
81 Reference.reachabilityFence(data_arg);
82 if (ret >= 0 && ret <= 4096) { return null; }
83 org.ldk.structs.ErrorMessage ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ErrorMessage(null, ret); }
84 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
89 long ret = bindings.ErrorMessage_clone_ptr(this.ptr);
90 Reference.reachabilityFence(this);
95 * Creates a copy of the ErrorMessage
97 public ErrorMessage clone() {
98 long ret = bindings.ErrorMessage_clone(this.ptr);
99 Reference.reachabilityFence(this);
100 if (ret >= 0 && ret <= 4096) { return null; }
101 org.ldk.structs.ErrorMessage ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ErrorMessage(null, ret); }
102 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
107 * Generates a non-cryptographic 64-bit hash of the ErrorMessage.
110 long ret = bindings.ErrorMessage_hash(this.ptr);
111 Reference.reachabilityFence(this);
115 @Override public int hashCode() {
116 return (int)this.hash();
119 * Checks if two ErrorMessages contain equal inner contents.
120 * This ignores pointers and is_owned flags and looks at the values in fields.
121 * Two objects with NULL inner values will be considered "equal" here.
123 public boolean eq(org.ldk.structs.ErrorMessage b) {
124 boolean ret = bindings.ErrorMessage_eq(this.ptr, b == null ? 0 : b.ptr);
125 Reference.reachabilityFence(this);
126 Reference.reachabilityFence(b);
127 if (this != null) { this.ptrs_to.add(b); };
131 @Override public boolean equals(Object o) {
132 if (!(o instanceof ErrorMessage)) return false;
133 return this.eq((ErrorMessage)o);
136 * Serialize the ErrorMessage object into a byte array which can be read by ErrorMessage_read
138 public byte[] write() {
139 byte[] ret = bindings.ErrorMessage_write(this.ptr);
140 Reference.reachabilityFence(this);
145 * Read a ErrorMessage from a byte array, created by ErrorMessage_write
147 public static Result_ErrorMessageDecodeErrorZ read(byte[] ser) {
148 long ret = bindings.ErrorMessage_read(ser);
149 Reference.reachabilityFence(ser);
150 if (ret >= 0 && ret <= 4096) { return null; }
151 Result_ErrorMessageDecodeErrorZ ret_hu_conv = Result_ErrorMessageDecodeErrorZ.constr_from_ptr(ret);