8b0122395437448924633fe2a1f531d95eed8109
[ldk-java] / src / main / java / org / ldk / structs / Init.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  * An [`init`] message to be sent to or received from a peer.
13  * 
14  * [`init`]: https://github.com/lightning/bolts/blob/master/01-messaging.md#the-init-message
15  */
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 {
21                 super.finalize();
22                 if (ptr != 0) { bindings.Init_free(ptr); }
23         }
24
25         /**
26          * The relevant features which the sender supports.
27          */
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); };
34                 return ret_hu_conv;
35         }
36
37         /**
38          * The relevant features which the sender supports.
39          */
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); };
45         }
46
47         /**
48          * The receipient's network address.
49          * 
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
53          * the new address.
54          */
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); };
61                 return ret_hu_conv;
62         }
63
64         /**
65          * The receipient's network address.
66          * 
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
70          * the new address.
71          */
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); };
77         }
78
79         /**
80          * Constructs a new Init given each field
81          */
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); };
91                 return ret_hu_conv;
92         }
93
94         long clone_ptr() {
95                 long ret = bindings.Init_clone_ptr(this.ptr);
96                 Reference.reachabilityFence(this);
97                 return ret;
98         }
99
100         /**
101          * Creates a copy of the Init
102          */
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); };
109                 return ret_hu_conv;
110         }
111
112         /**
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.
116          */
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); };
122                 return ret;
123         }
124
125         @Override public boolean equals(Object o) {
126                 if (!(o instanceof Init)) return false;
127                 return this.eq((Init)o);
128         }
129         /**
130          * Serialize the Init object into a byte array which can be read by Init_read
131          */
132         public byte[] write() {
133                 byte[] ret = bindings.Init_write(this.ptr);
134                 Reference.reachabilityFence(this);
135                 return ret;
136         }
137
138         /**
139          * Read a Init from a byte array, created by Init_write
140          */
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);
146                 return ret_hu_conv;
147         }
148
149 }