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 * Indicates chains the sender is interested in.
50 * If there are no common chains, the connection will be closed.
52 * Returns a copy of the field.
54 public Option_CVec_ThirtyTwoBytesZZ get_networks() {
55 long ret = bindings.Init_get_networks(this.ptr);
56 Reference.reachabilityFence(this);
57 if (ret >= 0 && ret <= 4096) { return null; }
58 org.ldk.structs.Option_CVec_ThirtyTwoBytesZZ ret_hu_conv = org.ldk.structs.Option_CVec_ThirtyTwoBytesZZ.constr_from_ptr(ret);
59 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
64 * Indicates chains the sender is interested in.
66 * If there are no common chains, the connection will be closed.
68 public void set_networks(org.ldk.structs.Option_CVec_ThirtyTwoBytesZZ val) {
69 bindings.Init_set_networks(this.ptr, val.ptr);
70 Reference.reachabilityFence(this);
71 Reference.reachabilityFence(val);
72 if (this != null) { this.ptrs_to.add(val); };
76 * The receipient's network address.
78 * This adds the option to report a remote IP address back to a connecting peer using the init
79 * message. A node can decide to use that information to discover a potential update to its
80 * public IPv4 address (NAT) and use that for a [`NodeAnnouncement`] update message containing
83 public Option_SocketAddressZ get_remote_network_address() {
84 long ret = bindings.Init_get_remote_network_address(this.ptr);
85 Reference.reachabilityFence(this);
86 if (ret >= 0 && ret <= 4096) { return null; }
87 org.ldk.structs.Option_SocketAddressZ ret_hu_conv = org.ldk.structs.Option_SocketAddressZ.constr_from_ptr(ret);
88 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
93 * The receipient's network address.
95 * This adds the option to report a remote IP address back to a connecting peer using the init
96 * message. A node can decide to use that information to discover a potential update to its
97 * public IPv4 address (NAT) and use that for a [`NodeAnnouncement`] update message containing
100 public void set_remote_network_address(org.ldk.structs.Option_SocketAddressZ val) {
101 bindings.Init_set_remote_network_address(this.ptr, val.ptr);
102 Reference.reachabilityFence(this);
103 Reference.reachabilityFence(val);
104 if (this != null) { this.ptrs_to.add(val); };
108 * Constructs a new Init given each field
110 public static Init of(org.ldk.structs.InitFeatures features_arg, org.ldk.structs.Option_CVec_ThirtyTwoBytesZZ networks_arg, org.ldk.structs.Option_SocketAddressZ remote_network_address_arg) {
111 long ret = bindings.Init_new(features_arg == null ? 0 : features_arg.ptr, networks_arg.ptr, remote_network_address_arg.ptr);
112 Reference.reachabilityFence(features_arg);
113 Reference.reachabilityFence(networks_arg);
114 Reference.reachabilityFence(remote_network_address_arg);
115 if (ret >= 0 && ret <= 4096) { return null; }
116 org.ldk.structs.Init ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Init(null, ret); }
117 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
118 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(features_arg); };
119 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(networks_arg); };
120 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(remote_network_address_arg); };
125 long ret = bindings.Init_clone_ptr(this.ptr);
126 Reference.reachabilityFence(this);
131 * Creates a copy of the Init
133 public Init clone() {
134 long ret = bindings.Init_clone(this.ptr);
135 Reference.reachabilityFence(this);
136 if (ret >= 0 && ret <= 4096) { return null; }
137 org.ldk.structs.Init ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Init(null, ret); }
138 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
143 * Checks if two Inits contain equal inner contents.
144 * This ignores pointers and is_owned flags and looks at the values in fields.
145 * Two objects with NULL inner values will be considered "equal" here.
147 public boolean eq(org.ldk.structs.Init b) {
148 boolean ret = bindings.Init_eq(this.ptr, b == null ? 0 : b.ptr);
149 Reference.reachabilityFence(this);
150 Reference.reachabilityFence(b);
151 if (this != null) { this.ptrs_to.add(b); };
155 @Override public boolean equals(Object o) {
156 if (!(o instanceof Init)) return false;
157 return this.eq((Init)o);
160 * Serialize the Init object into a byte array which can be read by Init_read
162 public byte[] write() {
163 byte[] ret = bindings.Init_write(this.ptr);
164 Reference.reachabilityFence(this);
169 * Read a Init from a byte array, created by Init_write
171 public static Result_InitDecodeErrorZ read(byte[] ser) {
172 long ret = bindings.Init_read(ser);
173 Reference.reachabilityFence(ser);
174 if (ret >= 0 && ret <= 4096) { return null; }
175 Result_InitDecodeErrorZ ret_hu_conv = Result_InitDecodeErrorZ.constr_from_ptr(ret);