864f64e2fa76f4a9944b504fe6c5f2d00abf1881
[ldk-java] / src / main / java / org / ldk / structs / ChannelInfo.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  * Details about a channel (both directions).
13  * Received within a channel announcement.
14  */
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class ChannelInfo extends CommonBase {
17         ChannelInfo(Object _dummy, long ptr) { super(ptr); }
18         @Override @SuppressWarnings("deprecation")
19         protected void finalize() throws Throwable {
20                 super.finalize();
21                 if (ptr != 0) { bindings.ChannelInfo_free(ptr); }
22         }
23
24         /**
25          * Protocol features of a channel communicated during its announcement
26          */
27         public ChannelFeatures get_features() {
28                 long ret = bindings.ChannelInfo_get_features(this.ptr);
29                 Reference.reachabilityFence(this);
30                 if (ret >= 0 && ret <= 4096) { return null; }
31                 org.ldk.structs.ChannelFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelFeatures(null, ret); }
32                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
33                 return ret_hu_conv;
34         }
35
36         /**
37          * Protocol features of a channel communicated during its announcement
38          */
39         public void set_features(org.ldk.structs.ChannelFeatures val) {
40                 bindings.ChannelInfo_set_features(this.ptr, val == null ? 0 : val.ptr);
41                 Reference.reachabilityFence(this);
42                 Reference.reachabilityFence(val);
43                 if (this != null) { this.ptrs_to.add(val); };
44         }
45
46         /**
47          * Source node of the first direction of a channel
48          */
49         public NodeId get_node_one() {
50                 long ret = bindings.ChannelInfo_get_node_one(this.ptr);
51                 Reference.reachabilityFence(this);
52                 if (ret >= 0 && ret <= 4096) { return null; }
53                 org.ldk.structs.NodeId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeId(null, ret); }
54                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
55                 return ret_hu_conv;
56         }
57
58         /**
59          * Source node of the first direction of a channel
60          */
61         public void set_node_one(org.ldk.structs.NodeId val) {
62                 bindings.ChannelInfo_set_node_one(this.ptr, val == null ? 0 : val.ptr);
63                 Reference.reachabilityFence(this);
64                 Reference.reachabilityFence(val);
65                 if (this != null) { this.ptrs_to.add(val); };
66         }
67
68         /**
69          * Details about the first direction of a channel
70          * 
71          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
72          */
73         @Nullable
74         public ChannelUpdateInfo get_one_to_two() {
75                 long ret = bindings.ChannelInfo_get_one_to_two(this.ptr);
76                 Reference.reachabilityFence(this);
77                 if (ret >= 0 && ret <= 4096) { return null; }
78                 org.ldk.structs.ChannelUpdateInfo ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelUpdateInfo(null, ret); }
79                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
80                 return ret_hu_conv;
81         }
82
83         /**
84          * Details about the first direction of a channel
85          * 
86          * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
87          */
88         public void set_one_to_two(@Nullable org.ldk.structs.ChannelUpdateInfo val) {
89                 bindings.ChannelInfo_set_one_to_two(this.ptr, val == null ? 0 : val.ptr);
90                 Reference.reachabilityFence(this);
91                 Reference.reachabilityFence(val);
92                 if (this != null) { this.ptrs_to.add(val); };
93         }
94
95         /**
96          * Source node of the second direction of a channel
97          */
98         public NodeId get_node_two() {
99                 long ret = bindings.ChannelInfo_get_node_two(this.ptr);
100                 Reference.reachabilityFence(this);
101                 if (ret >= 0 && ret <= 4096) { return null; }
102                 org.ldk.structs.NodeId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeId(null, ret); }
103                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
104                 return ret_hu_conv;
105         }
106
107         /**
108          * Source node of the second direction of a channel
109          */
110         public void set_node_two(org.ldk.structs.NodeId val) {
111                 bindings.ChannelInfo_set_node_two(this.ptr, val == null ? 0 : val.ptr);
112                 Reference.reachabilityFence(this);
113                 Reference.reachabilityFence(val);
114                 if (this != null) { this.ptrs_to.add(val); };
115         }
116
117         /**
118          * Details about the second direction of a channel
119          * 
120          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
121          */
122         @Nullable
123         public ChannelUpdateInfo get_two_to_one() {
124                 long ret = bindings.ChannelInfo_get_two_to_one(this.ptr);
125                 Reference.reachabilityFence(this);
126                 if (ret >= 0 && ret <= 4096) { return null; }
127                 org.ldk.structs.ChannelUpdateInfo ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelUpdateInfo(null, ret); }
128                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
129                 return ret_hu_conv;
130         }
131
132         /**
133          * Details about the second direction of a channel
134          * 
135          * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
136          */
137         public void set_two_to_one(@Nullable org.ldk.structs.ChannelUpdateInfo val) {
138                 bindings.ChannelInfo_set_two_to_one(this.ptr, val == null ? 0 : val.ptr);
139                 Reference.reachabilityFence(this);
140                 Reference.reachabilityFence(val);
141                 if (this != null) { this.ptrs_to.add(val); };
142         }
143
144         /**
145          * The channel capacity as seen on-chain, if chain lookup is available.
146          */
147         public Option_u64Z get_capacity_sats() {
148                 long ret = bindings.ChannelInfo_get_capacity_sats(this.ptr);
149                 Reference.reachabilityFence(this);
150                 if (ret >= 0 && ret <= 4096) { return null; }
151                 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
152                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
153                 return ret_hu_conv;
154         }
155
156         /**
157          * The channel capacity as seen on-chain, if chain lookup is available.
158          */
159         public void set_capacity_sats(org.ldk.structs.Option_u64Z val) {
160                 bindings.ChannelInfo_set_capacity_sats(this.ptr, val.ptr);
161                 Reference.reachabilityFence(this);
162                 Reference.reachabilityFence(val);
163         }
164
165         /**
166          * An initial announcement of the channel
167          * Mostly redundant with the data we store in fields explicitly.
168          * Everything else is useful only for sending out for initial routing sync.
169          * Not stored if contains excess data to prevent DoS.
170          * 
171          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
172          */
173         @Nullable
174         public ChannelAnnouncement get_announcement_message() {
175                 long ret = bindings.ChannelInfo_get_announcement_message(this.ptr);
176                 Reference.reachabilityFence(this);
177                 if (ret >= 0 && ret <= 4096) { return null; }
178                 org.ldk.structs.ChannelAnnouncement ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelAnnouncement(null, ret); }
179                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
180                 return ret_hu_conv;
181         }
182
183         /**
184          * An initial announcement of the channel
185          * Mostly redundant with the data we store in fields explicitly.
186          * Everything else is useful only for sending out for initial routing sync.
187          * Not stored if contains excess data to prevent DoS.
188          * 
189          * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
190          */
191         public void set_announcement_message(@Nullable org.ldk.structs.ChannelAnnouncement val) {
192                 bindings.ChannelInfo_set_announcement_message(this.ptr, val == null ? 0 : val.ptr);
193                 Reference.reachabilityFence(this);
194                 Reference.reachabilityFence(val);
195                 if (this != null) { this.ptrs_to.add(val); };
196         }
197
198         long clone_ptr() {
199                 long ret = bindings.ChannelInfo_clone_ptr(this.ptr);
200                 Reference.reachabilityFence(this);
201                 return ret;
202         }
203
204         /**
205          * Creates a copy of the ChannelInfo
206          */
207         public ChannelInfo clone() {
208                 long ret = bindings.ChannelInfo_clone(this.ptr);
209                 Reference.reachabilityFence(this);
210                 if (ret >= 0 && ret <= 4096) { return null; }
211                 org.ldk.structs.ChannelInfo ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelInfo(null, ret); }
212                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
213                 return ret_hu_conv;
214         }
215
216         /**
217          * Checks if two ChannelInfos contain equal inner contents.
218          * This ignores pointers and is_owned flags and looks at the values in fields.
219          * Two objects with NULL inner values will be considered "equal" here.
220          */
221         public boolean eq(org.ldk.structs.ChannelInfo b) {
222                 boolean ret = bindings.ChannelInfo_eq(this.ptr, b == null ? 0 : b.ptr);
223                 Reference.reachabilityFence(this);
224                 Reference.reachabilityFence(b);
225                 if (this != null) { this.ptrs_to.add(b); };
226                 return ret;
227         }
228
229         @Override public boolean equals(Object o) {
230                 if (!(o instanceof ChannelInfo)) return false;
231                 return this.eq((ChannelInfo)o);
232         }
233         /**
234          * Returns a [`ChannelUpdateInfo`] based on the direction implied by the channel_flag.
235          * 
236          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
237          */
238         @Nullable
239         public ChannelUpdateInfo get_directional_info(byte channel_flags) {
240                 long ret = bindings.ChannelInfo_get_directional_info(this.ptr, channel_flags);
241                 Reference.reachabilityFence(this);
242                 Reference.reachabilityFence(channel_flags);
243                 if (ret >= 0 && ret <= 4096) { return null; }
244                 org.ldk.structs.ChannelUpdateInfo ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelUpdateInfo(null, ret); }
245                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
246                 return ret_hu_conv;
247         }
248
249         /**
250          * Serialize the ChannelInfo object into a byte array which can be read by ChannelInfo_read
251          */
252         public byte[] write() {
253                 byte[] ret = bindings.ChannelInfo_write(this.ptr);
254                 Reference.reachabilityFence(this);
255                 return ret;
256         }
257
258         /**
259          * Read a ChannelInfo from a byte array, created by ChannelInfo_write
260          */
261         public static Result_ChannelInfoDecodeErrorZ read(byte[] ser) {
262                 long ret = bindings.ChannelInfo_read(ser);
263                 Reference.reachabilityFence(ser);
264                 if (ret >= 0 && ret <= 4096) { return null; }
265                 Result_ChannelInfoDecodeErrorZ ret_hu_conv = Result_ChannelInfoDecodeErrorZ.constr_from_ptr(ret);
266                 return ret_hu_conv;
267         }
268
269 }