Merge pull request #54 from TheBlueMatt/main
[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 javax.annotation.Nullable;
8
9
10 /**
11  * Details about a channel (both directions).
12  * Received within a channel announcement.
13  */
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class ChannelInfo extends CommonBase {
16         ChannelInfo(Object _dummy, long ptr) { super(ptr); }
17         @Override @SuppressWarnings("deprecation")
18         protected void finalize() throws Throwable {
19                 super.finalize();
20                 if (ptr != 0) { bindings.ChannelInfo_free(ptr); }
21         }
22
23         /**
24          * Protocol features of a channel communicated during its announcement
25          */
26         public ChannelFeatures get_features() {
27                 long ret = bindings.ChannelInfo_get_features(this.ptr);
28                 if (ret >= 0 && ret <= 4096) { return null; }
29                 ChannelFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ChannelFeatures(null, ret); }
30                 ret_hu_conv.ptrs_to.add(this);
31                 return ret_hu_conv;
32         }
33
34         /**
35          * Protocol features of a channel communicated during its announcement
36          */
37         public void set_features(ChannelFeatures val) {
38                 bindings.ChannelInfo_set_features(this.ptr, val == null ? 0 : val.ptr & ~1);
39         }
40
41         /**
42          * Source node of the first direction of a channel
43          */
44         public NodeId get_node_one() {
45                 long ret = bindings.ChannelInfo_get_node_one(this.ptr);
46                 if (ret >= 0 && ret <= 4096) { return null; }
47                 NodeId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new NodeId(null, ret); }
48                 ret_hu_conv.ptrs_to.add(this);
49                 return ret_hu_conv;
50         }
51
52         /**
53          * Source node of the first direction of a channel
54          */
55         public void set_node_one(NodeId val) {
56                 bindings.ChannelInfo_set_node_one(this.ptr, val == null ? 0 : val.ptr & ~1);
57         }
58
59         /**
60          * Details about the first direction of a channel
61          * 
62          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
63          */
64         @Nullable
65         public DirectionalChannelInfo get_one_to_two() {
66                 long ret = bindings.ChannelInfo_get_one_to_two(this.ptr);
67                 if (ret >= 0 && ret <= 4096) { return null; }
68                 DirectionalChannelInfo ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new DirectionalChannelInfo(null, ret); }
69                 ret_hu_conv.ptrs_to.add(this);
70                 return ret_hu_conv;
71         }
72
73         /**
74          * Details about the first direction of a channel
75          * 
76          * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
77          */
78         public void set_one_to_two(@Nullable DirectionalChannelInfo val) {
79                 bindings.ChannelInfo_set_one_to_two(this.ptr, val == null ? 0 : val.ptr & ~1);
80         }
81
82         /**
83          * Source node of the second direction of a channel
84          */
85         public NodeId get_node_two() {
86                 long ret = bindings.ChannelInfo_get_node_two(this.ptr);
87                 if (ret >= 0 && ret <= 4096) { return null; }
88                 NodeId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new NodeId(null, ret); }
89                 ret_hu_conv.ptrs_to.add(this);
90                 return ret_hu_conv;
91         }
92
93         /**
94          * Source node of the second direction of a channel
95          */
96         public void set_node_two(NodeId val) {
97                 bindings.ChannelInfo_set_node_two(this.ptr, val == null ? 0 : val.ptr & ~1);
98         }
99
100         /**
101          * Details about the second direction of a channel
102          * 
103          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
104          */
105         @Nullable
106         public DirectionalChannelInfo get_two_to_one() {
107                 long ret = bindings.ChannelInfo_get_two_to_one(this.ptr);
108                 if (ret >= 0 && ret <= 4096) { return null; }
109                 DirectionalChannelInfo ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new DirectionalChannelInfo(null, ret); }
110                 ret_hu_conv.ptrs_to.add(this);
111                 return ret_hu_conv;
112         }
113
114         /**
115          * Details about the second direction of a channel
116          * 
117          * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
118          */
119         public void set_two_to_one(@Nullable DirectionalChannelInfo val) {
120                 bindings.ChannelInfo_set_two_to_one(this.ptr, val == null ? 0 : val.ptr & ~1);
121         }
122
123         /**
124          * The channel capacity as seen on-chain, if chain lookup is available.
125          */
126         public Option_u64Z get_capacity_sats() {
127                 long ret = bindings.ChannelInfo_get_capacity_sats(this.ptr);
128                 if (ret >= 0 && ret <= 4096) { return null; }
129                 Option_u64Z ret_hu_conv = Option_u64Z.constr_from_ptr(ret);
130                 ret_hu_conv.ptrs_to.add(this);
131                 return ret_hu_conv;
132         }
133
134         /**
135          * The channel capacity as seen on-chain, if chain lookup is available.
136          */
137         public void set_capacity_sats(Option_u64Z val) {
138                 bindings.ChannelInfo_set_capacity_sats(this.ptr, val.ptr);
139         }
140
141         /**
142          * An initial announcement of the channel
143          * Mostly redundant with the data we store in fields explicitly.
144          * Everything else is useful only for sending out for initial routing sync.
145          * Not stored if contains excess data to prevent DoS.
146          * 
147          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
148          */
149         @Nullable
150         public ChannelAnnouncement get_announcement_message() {
151                 long ret = bindings.ChannelInfo_get_announcement_message(this.ptr);
152                 if (ret >= 0 && ret <= 4096) { return null; }
153                 ChannelAnnouncement ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ChannelAnnouncement(null, ret); }
154                 ret_hu_conv.ptrs_to.add(this);
155                 return ret_hu_conv;
156         }
157
158         /**
159          * An initial announcement of the channel
160          * Mostly redundant with the data we store in fields explicitly.
161          * Everything else is useful only for sending out for initial routing sync.
162          * Not stored if contains excess data to prevent DoS.
163          * 
164          * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
165          */
166         public void set_announcement_message(@Nullable ChannelAnnouncement val) {
167                 bindings.ChannelInfo_set_announcement_message(this.ptr, val == null ? 0 : val.ptr & ~1);
168         }
169
170         /**
171          * Constructs a new ChannelInfo given each field
172          */
173         public static ChannelInfo of(ChannelFeatures features_arg, NodeId node_one_arg, DirectionalChannelInfo one_to_two_arg, NodeId node_two_arg, DirectionalChannelInfo two_to_one_arg, Option_u64Z capacity_sats_arg, ChannelAnnouncement announcement_message_arg) {
174                 long ret = bindings.ChannelInfo_new(features_arg == null ? 0 : features_arg.ptr & ~1, node_one_arg == null ? 0 : node_one_arg.ptr & ~1, one_to_two_arg == null ? 0 : one_to_two_arg.ptr & ~1, node_two_arg == null ? 0 : node_two_arg.ptr & ~1, two_to_one_arg == null ? 0 : two_to_one_arg.ptr & ~1, capacity_sats_arg.ptr, announcement_message_arg == null ? 0 : announcement_message_arg.ptr & ~1);
175                 if (ret >= 0 && ret <= 4096) { return null; }
176                 ChannelInfo ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ChannelInfo(null, ret); }
177                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
178                 return ret_hu_conv;
179         }
180
181         /**
182          * Creates a copy of the ChannelInfo
183          */
184         public ChannelInfo clone() {
185                 long ret = bindings.ChannelInfo_clone(this.ptr);
186                 if (ret >= 0 && ret <= 4096) { return null; }
187                 ChannelInfo ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ChannelInfo(null, ret); }
188                 ret_hu_conv.ptrs_to.add(this);
189                 return ret_hu_conv;
190         }
191
192         /**
193          * Serialize the ChannelInfo object into a byte array which can be read by ChannelInfo_read
194          */
195         public byte[] write() {
196                 byte[] ret = bindings.ChannelInfo_write(this.ptr);
197                 return ret;
198         }
199
200         /**
201          * Read a ChannelInfo from a byte array, created by ChannelInfo_write
202          */
203         public static Result_ChannelInfoDecodeErrorZ read(byte[] ser) {
204                 long ret = bindings.ChannelInfo_read(ser);
205                 if (ret >= 0 && ret <= 4096) { return null; }
206                 Result_ChannelInfoDecodeErrorZ ret_hu_conv = Result_ChannelInfoDecodeErrorZ.constr_from_ptr(ret);
207                 return ret_hu_conv;
208         }
209
210 }