3a92408fedd249c529bb8a0ff747fff673a1ac26
[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                 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(ChannelFeatures val) {
40                 bindings.ChannelInfo_set_features(this.ptr, val == null ? 0 : val.ptr);
41                 Reference.reachabilityFence(this);
42                 Reference.reachabilityFence(val);
43                 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                 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(NodeId val) {
62                 bindings.ChannelInfo_set_node_one(this.ptr, val == null ? 0 : val.ptr);
63                 Reference.reachabilityFence(this);
64                 Reference.reachabilityFence(val);
65                 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                 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 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                 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                 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(NodeId val) {
111                 bindings.ChannelInfo_set_node_two(this.ptr, val == null ? 0 : val.ptr);
112                 Reference.reachabilityFence(this);
113                 Reference.reachabilityFence(val);
114                 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                 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 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                 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                 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(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                 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 ChannelAnnouncement val) {
192                 bindings.ChannelInfo_set_announcement_message(this.ptr, val == null ? 0 : val.ptr);
193                 Reference.reachabilityFence(this);
194                 Reference.reachabilityFence(val);
195                 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                 ret_hu_conv.ptrs_to.add(this);
213                 return ret_hu_conv;
214         }
215
216         /**
217          * Returns a [`ChannelUpdateInfo`] based on the direction implied by the channel_flag.
218          * 
219          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
220          */
221         @Nullable
222         public ChannelUpdateInfo get_directional_info(byte channel_flags) {
223                 long ret = bindings.ChannelInfo_get_directional_info(this.ptr, channel_flags);
224                 Reference.reachabilityFence(this);
225                 Reference.reachabilityFence(channel_flags);
226                 if (ret >= 0 && ret <= 4096) { return null; }
227                 org.ldk.structs.ChannelUpdateInfo ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelUpdateInfo(null, ret); }
228                 ret_hu_conv.ptrs_to.add(this);
229                 return ret_hu_conv;
230         }
231
232         /**
233          * Serialize the ChannelInfo object into a byte array which can be read by ChannelInfo_read
234          */
235         public byte[] write() {
236                 byte[] ret = bindings.ChannelInfo_write(this.ptr);
237                 Reference.reachabilityFence(this);
238                 return ret;
239         }
240
241         /**
242          * Read a ChannelInfo from a byte array, created by ChannelInfo_write
243          */
244         public static Result_ChannelInfoDecodeErrorZ read(byte[] ser) {
245                 long ret = bindings.ChannelInfo_read(ser);
246                 Reference.reachabilityFence(ser);
247                 if (ret >= 0 && ret <= 4096) { return null; }
248                 Result_ChannelInfoDecodeErrorZ ret_hu_conv = Result_ChannelInfoDecodeErrorZ.constr_from_ptr(ret);
249                 return ret_hu_conv;
250         }
251
252 }