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 * The unsigned part of a [`node_announcement`] message.
14 * [`node_announcement`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-node_announcement-message
16 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
17 public class UnsignedNodeAnnouncement extends CommonBase {
18 UnsignedNodeAnnouncement(Object _dummy, long ptr) { super(ptr); }
19 @Override @SuppressWarnings("deprecation")
20 protected void finalize() throws Throwable {
22 if (ptr != 0) { bindings.UnsignedNodeAnnouncement_free(ptr); }
26 * The advertised features
28 public NodeFeatures get_features() {
29 long ret = bindings.UnsignedNodeAnnouncement_get_features(this.ptr);
30 Reference.reachabilityFence(this);
31 if (ret >= 0 && ret <= 4096) { return null; }
32 org.ldk.structs.NodeFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeFeatures(null, ret); }
33 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
38 * The advertised features
40 public void set_features(org.ldk.structs.NodeFeatures val) {
41 bindings.UnsignedNodeAnnouncement_set_features(this.ptr, val.ptr);
42 Reference.reachabilityFence(this);
43 Reference.reachabilityFence(val);
44 if (this != null) { this.ptrs_to.add(val); };
48 * A strictly monotonic announcement counter, with gaps allowed
50 public int get_timestamp() {
51 int ret = bindings.UnsignedNodeAnnouncement_get_timestamp(this.ptr);
52 Reference.reachabilityFence(this);
57 * A strictly monotonic announcement counter, with gaps allowed
59 public void set_timestamp(int val) {
60 bindings.UnsignedNodeAnnouncement_set_timestamp(this.ptr, val);
61 Reference.reachabilityFence(this);
62 Reference.reachabilityFence(val);
66 * The `node_id` this announcement originated from (don't rebroadcast the `node_announcement` back
69 public NodeId get_node_id() {
70 long ret = bindings.UnsignedNodeAnnouncement_get_node_id(this.ptr);
71 Reference.reachabilityFence(this);
72 if (ret >= 0 && ret <= 4096) { return null; }
73 org.ldk.structs.NodeId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeId(null, ret); }
74 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
79 * The `node_id` this announcement originated from (don't rebroadcast the `node_announcement` back
82 public void set_node_id(org.ldk.structs.NodeId val) {
83 bindings.UnsignedNodeAnnouncement_set_node_id(this.ptr, val.ptr);
84 Reference.reachabilityFence(this);
85 Reference.reachabilityFence(val);
86 if (this != null) { this.ptrs_to.add(val); };
90 * An RGB color for UI purposes
92 public byte[] get_rgb() {
93 byte[] ret = bindings.UnsignedNodeAnnouncement_get_rgb(this.ptr);
94 Reference.reachabilityFence(this);
99 * An RGB color for UI purposes
101 public void set_rgb(byte[] val) {
102 bindings.UnsignedNodeAnnouncement_set_rgb(this.ptr, InternalUtils.check_arr_len(val, 3));
103 Reference.reachabilityFence(this);
104 Reference.reachabilityFence(val);
108 * An alias, for UI purposes.
110 * This should be sanitized before use. There is no guarantee of uniqueness.
112 public NodeAlias get_alias() {
113 long ret = bindings.UnsignedNodeAnnouncement_get_alias(this.ptr);
114 Reference.reachabilityFence(this);
115 if (ret >= 0 && ret <= 4096) { return null; }
116 org.ldk.structs.NodeAlias ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeAlias(null, ret); }
117 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
122 * An alias, for UI purposes.
124 * This should be sanitized before use. There is no guarantee of uniqueness.
126 public void set_alias(org.ldk.structs.NodeAlias val) {
127 bindings.UnsignedNodeAnnouncement_set_alias(this.ptr, val.ptr);
128 Reference.reachabilityFence(this);
129 Reference.reachabilityFence(val);
130 if (this != null) { this.ptrs_to.add(val); };
134 * List of addresses on which this node is reachable
136 * Returns a copy of the field.
138 public SocketAddress[] get_addresses() {
139 long[] ret = bindings.UnsignedNodeAnnouncement_get_addresses(this.ptr);
140 Reference.reachabilityFence(this);
141 int ret_conv_15_len = ret.length;
142 SocketAddress[] ret_conv_15_arr = new SocketAddress[ret_conv_15_len];
143 for (int p = 0; p < ret_conv_15_len; p++) {
144 long ret_conv_15 = ret[p];
145 org.ldk.structs.SocketAddress ret_conv_15_hu_conv = org.ldk.structs.SocketAddress.constr_from_ptr(ret_conv_15);
146 if (ret_conv_15_hu_conv != null) { ret_conv_15_hu_conv.ptrs_to.add(this); };
147 ret_conv_15_arr[p] = ret_conv_15_hu_conv;
149 return ret_conv_15_arr;
153 * List of addresses on which this node is reachable
155 public void set_addresses(SocketAddress[] val) {
156 bindings.UnsignedNodeAnnouncement_set_addresses(this.ptr, val != null ? Arrays.stream(val).mapToLong(val_conv_15 -> val_conv_15.ptr).toArray() : null);
157 Reference.reachabilityFence(this);
158 Reference.reachabilityFence(val);
159 for (SocketAddress val_conv_15: val) { if (this != null) { this.ptrs_to.add(val_conv_15); }; };
163 * Excess address data which was signed as a part of the message which we do not (yet) understand how
166 * This is stored to ensure forward-compatibility as new address types are added to the lightning gossip protocol.
168 * Returns a copy of the field.
170 public byte[] get_excess_address_data() {
171 byte[] ret = bindings.UnsignedNodeAnnouncement_get_excess_address_data(this.ptr);
172 Reference.reachabilityFence(this);
177 * Excess address data which was signed as a part of the message which we do not (yet) understand how
180 * This is stored to ensure forward-compatibility as new address types are added to the lightning gossip protocol.
182 public void set_excess_address_data(byte[] val) {
183 bindings.UnsignedNodeAnnouncement_set_excess_address_data(this.ptr, val);
184 Reference.reachabilityFence(this);
185 Reference.reachabilityFence(val);
189 * Excess data which was signed as a part of the message which we do not (yet) understand how
192 * This is stored to ensure forward-compatibility as new fields are added to the lightning gossip protocol.
194 * Returns a copy of the field.
196 public byte[] get_excess_data() {
197 byte[] ret = bindings.UnsignedNodeAnnouncement_get_excess_data(this.ptr);
198 Reference.reachabilityFence(this);
203 * Excess data which was signed as a part of the message which we do not (yet) understand how
206 * This is stored to ensure forward-compatibility as new fields are added to the lightning gossip protocol.
208 public void set_excess_data(byte[] val) {
209 bindings.UnsignedNodeAnnouncement_set_excess_data(this.ptr, val);
210 Reference.reachabilityFence(this);
211 Reference.reachabilityFence(val);
215 * Constructs a new UnsignedNodeAnnouncement given each field
217 public static UnsignedNodeAnnouncement of(org.ldk.structs.NodeFeatures features_arg, int timestamp_arg, org.ldk.structs.NodeId node_id_arg, byte[] rgb_arg, org.ldk.structs.NodeAlias alias_arg, SocketAddress[] addresses_arg, byte[] excess_address_data_arg, byte[] excess_data_arg) {
218 long ret = bindings.UnsignedNodeAnnouncement_new(features_arg.ptr, timestamp_arg, node_id_arg.ptr, InternalUtils.check_arr_len(rgb_arg, 3), alias_arg.ptr, addresses_arg != null ? Arrays.stream(addresses_arg).mapToLong(addresses_arg_conv_15 -> addresses_arg_conv_15.ptr).toArray() : null, excess_address_data_arg, excess_data_arg);
219 Reference.reachabilityFence(features_arg);
220 Reference.reachabilityFence(timestamp_arg);
221 Reference.reachabilityFence(node_id_arg);
222 Reference.reachabilityFence(rgb_arg);
223 Reference.reachabilityFence(alias_arg);
224 Reference.reachabilityFence(addresses_arg);
225 Reference.reachabilityFence(excess_address_data_arg);
226 Reference.reachabilityFence(excess_data_arg);
227 if (ret >= 0 && ret <= 4096) { return null; }
228 org.ldk.structs.UnsignedNodeAnnouncement ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.UnsignedNodeAnnouncement(null, ret); }
229 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
230 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(features_arg); };
231 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(node_id_arg); };
232 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(alias_arg); };
233 for (SocketAddress addresses_arg_conv_15: addresses_arg) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(addresses_arg_conv_15); }; };
238 long ret = bindings.UnsignedNodeAnnouncement_clone_ptr(this.ptr);
239 Reference.reachabilityFence(this);
244 * Creates a copy of the UnsignedNodeAnnouncement
246 public UnsignedNodeAnnouncement clone() {
247 long ret = bindings.UnsignedNodeAnnouncement_clone(this.ptr);
248 Reference.reachabilityFence(this);
249 if (ret >= 0 && ret <= 4096) { return null; }
250 org.ldk.structs.UnsignedNodeAnnouncement ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.UnsignedNodeAnnouncement(null, ret); }
251 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
256 * Generates a non-cryptographic 64-bit hash of the UnsignedNodeAnnouncement.
259 long ret = bindings.UnsignedNodeAnnouncement_hash(this.ptr);
260 Reference.reachabilityFence(this);
264 @Override public int hashCode() {
265 return (int)this.hash();
268 * Checks if two UnsignedNodeAnnouncements contain equal inner contents.
269 * This ignores pointers and is_owned flags and looks at the values in fields.
270 * Two objects with NULL inner values will be considered "equal" here.
272 public boolean eq(org.ldk.structs.UnsignedNodeAnnouncement b) {
273 boolean ret = bindings.UnsignedNodeAnnouncement_eq(this.ptr, b.ptr);
274 Reference.reachabilityFence(this);
275 Reference.reachabilityFence(b);
276 if (this != null) { this.ptrs_to.add(b); };
280 @Override public boolean equals(Object o) {
281 if (!(o instanceof UnsignedNodeAnnouncement)) return false;
282 return this.eq((UnsignedNodeAnnouncement)o);
285 * Serialize the UnsignedNodeAnnouncement object into a byte array which can be read by UnsignedNodeAnnouncement_read
287 public byte[] write() {
288 byte[] ret = bindings.UnsignedNodeAnnouncement_write(this.ptr);
289 Reference.reachabilityFence(this);
294 * Read a UnsignedNodeAnnouncement from a byte array, created by UnsignedNodeAnnouncement_write
296 public static Result_UnsignedNodeAnnouncementDecodeErrorZ read(byte[] ser) {
297 long ret = bindings.UnsignedNodeAnnouncement_read(ser);
298 Reference.reachabilityFence(ser);
299 if (ret >= 0 && ret <= 4096) { return null; }
300 Result_UnsignedNodeAnnouncementDecodeErrorZ ret_hu_conv = Result_UnsignedNodeAnnouncementDecodeErrorZ.constr_from_ptr(ret);