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 [`init`] message to be sent to or received from a peer.
14 * [`init`]: https://github.com/lightning/bolts/blob/master/01-messaging.md#the-init-message
16 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
17 public class Init extends CommonBase {
18 Init(Object _dummy, long ptr) { super(ptr); }
19 @Override @SuppressWarnings("deprecation")
20 protected void finalize() throws Throwable {
22 if (ptr != 0) { bindings.Init_free(ptr); }
26 * The relevant features which the sender supports.
28 public InitFeatures get_features() {
29 long ret = bindings.Init_get_features(this.ptr);
30 Reference.reachabilityFence(this);
31 if (ret >= 0 && ret <= 4096) { return null; }
32 org.ldk.structs.InitFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InitFeatures(null, ret); }
33 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
38 * The relevant features which the sender supports.
40 public void set_features(org.ldk.structs.InitFeatures val) {
41 bindings.Init_set_features(this.ptr, val == null ? 0 : val.ptr);
42 Reference.reachabilityFence(this);
43 Reference.reachabilityFence(val);
44 if (this != null) { this.ptrs_to.add(val); };
48 * The receipient's network address.
50 * This adds the option to report a remote IP address back to a connecting peer using the init
51 * message. A node can decide to use that information to discover a potential update to its
52 * public IPv4 address (NAT) and use that for a [`NodeAnnouncement`] update message containing
55 public Option_NetAddressZ get_remote_network_address() {
56 long ret = bindings.Init_get_remote_network_address(this.ptr);
57 Reference.reachabilityFence(this);
58 if (ret >= 0 && ret <= 4096) { return null; }
59 org.ldk.structs.Option_NetAddressZ ret_hu_conv = org.ldk.structs.Option_NetAddressZ.constr_from_ptr(ret);
60 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
65 * The receipient's network address.
67 * This adds the option to report a remote IP address back to a connecting peer using the init
68 * message. A node can decide to use that information to discover a potential update to its
69 * public IPv4 address (NAT) and use that for a [`NodeAnnouncement`] update message containing
72 public void set_remote_network_address(org.ldk.structs.Option_NetAddressZ val) {
73 bindings.Init_set_remote_network_address(this.ptr, val.ptr);
74 Reference.reachabilityFence(this);
75 Reference.reachabilityFence(val);
76 if (this != null) { this.ptrs_to.add(val); };
80 * Constructs a new Init given each field
82 public static Init of(org.ldk.structs.InitFeatures features_arg, org.ldk.structs.Option_NetAddressZ remote_network_address_arg) {
83 long ret = bindings.Init_new(features_arg == null ? 0 : features_arg.ptr, remote_network_address_arg.ptr);
84 Reference.reachabilityFence(features_arg);
85 Reference.reachabilityFence(remote_network_address_arg);
86 if (ret >= 0 && ret <= 4096) { return null; }
87 org.ldk.structs.Init ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Init(null, ret); }
88 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
89 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(features_arg); };
90 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(remote_network_address_arg); };
95 long ret = bindings.Init_clone_ptr(this.ptr);
96 Reference.reachabilityFence(this);
101 * Creates a copy of the Init
103 public Init clone() {
104 long ret = bindings.Init_clone(this.ptr);
105 Reference.reachabilityFence(this);
106 if (ret >= 0 && ret <= 4096) { return null; }
107 org.ldk.structs.Init ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Init(null, ret); }
108 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
113 * Checks if two Inits contain equal inner contents.
114 * This ignores pointers and is_owned flags and looks at the values in fields.
115 * Two objects with NULL inner values will be considered "equal" here.
117 public boolean eq(org.ldk.structs.Init b) {
118 boolean ret = bindings.Init_eq(this.ptr, b == null ? 0 : b.ptr);
119 Reference.reachabilityFence(this);
120 Reference.reachabilityFence(b);
121 if (this != null) { this.ptrs_to.add(b); };
125 @Override public boolean equals(Object o) {
126 if (!(o instanceof Init)) return false;
127 return this.eq((Init)o);
130 * Serialize the Init object into a byte array which can be read by Init_read
132 public byte[] write() {
133 byte[] ret = bindings.Init_write(this.ptr);
134 Reference.reachabilityFence(this);
139 * Read a Init from a byte array, created by Init_write
141 public static Result_InitDecodeErrorZ read(byte[] ser) {
142 long ret = bindings.Init_read(ser);
143 Reference.reachabilityFence(ser);
144 if (ret >= 0 && ret <= 4096) { return null; }
145 Result_InitDecodeErrorZ ret_hu_conv = Result_InitDecodeErrorZ.constr_from_ptr(ret);