03093d27e12303c3e6da83bddd6009f91cfa47c5
[ldk-java] / src / main / java / org / ldk / structs / DirectionalChannelInfo.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 one direction of a channel. Received
13  * within a channel update.
14  */
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class DirectionalChannelInfo extends CommonBase {
17         DirectionalChannelInfo(Object _dummy, long ptr) { super(ptr); }
18         @Override @SuppressWarnings("deprecation")
19         protected void finalize() throws Throwable {
20                 super.finalize();
21                 if (ptr != 0) { bindings.DirectionalChannelInfo_free(ptr); }
22         }
23
24         /**
25          * When the last update to the channel direction was issued.
26          * Value is opaque, as set in the announcement.
27          */
28         public int get_last_update() {
29                 int ret = bindings.DirectionalChannelInfo_get_last_update(this.ptr);
30                 Reference.reachabilityFence(this);
31                 return ret;
32         }
33
34         /**
35          * When the last update to the channel direction was issued.
36          * Value is opaque, as set in the announcement.
37          */
38         public void set_last_update(int val) {
39                 bindings.DirectionalChannelInfo_set_last_update(this.ptr, val);
40                 Reference.reachabilityFence(this);
41                 Reference.reachabilityFence(val);
42         }
43
44         /**
45          * Whether the channel can be currently used for payments (in this one direction).
46          */
47         public boolean get_enabled() {
48                 boolean ret = bindings.DirectionalChannelInfo_get_enabled(this.ptr);
49                 Reference.reachabilityFence(this);
50                 return ret;
51         }
52
53         /**
54          * Whether the channel can be currently used for payments (in this one direction).
55          */
56         public void set_enabled(boolean val) {
57                 bindings.DirectionalChannelInfo_set_enabled(this.ptr, val);
58                 Reference.reachabilityFence(this);
59                 Reference.reachabilityFence(val);
60         }
61
62         /**
63          * The difference in CLTV values that you must have when routing through this channel.
64          */
65         public short get_cltv_expiry_delta() {
66                 short ret = bindings.DirectionalChannelInfo_get_cltv_expiry_delta(this.ptr);
67                 Reference.reachabilityFence(this);
68                 return ret;
69         }
70
71         /**
72          * The difference in CLTV values that you must have when routing through this channel.
73          */
74         public void set_cltv_expiry_delta(short val) {
75                 bindings.DirectionalChannelInfo_set_cltv_expiry_delta(this.ptr, val);
76                 Reference.reachabilityFence(this);
77                 Reference.reachabilityFence(val);
78         }
79
80         /**
81          * The minimum value, which must be relayed to the next hop via the channel
82          */
83         public long get_htlc_minimum_msat() {
84                 long ret = bindings.DirectionalChannelInfo_get_htlc_minimum_msat(this.ptr);
85                 Reference.reachabilityFence(this);
86                 return ret;
87         }
88
89         /**
90          * The minimum value, which must be relayed to the next hop via the channel
91          */
92         public void set_htlc_minimum_msat(long val) {
93                 bindings.DirectionalChannelInfo_set_htlc_minimum_msat(this.ptr, val);
94                 Reference.reachabilityFence(this);
95                 Reference.reachabilityFence(val);
96         }
97
98         /**
99          * The maximum value which may be relayed to the next hop via the channel.
100          */
101         public Option_u64Z get_htlc_maximum_msat() {
102                 long ret = bindings.DirectionalChannelInfo_get_htlc_maximum_msat(this.ptr);
103                 Reference.reachabilityFence(this);
104                 if (ret >= 0 && ret <= 4096) { return null; }
105                 Option_u64Z ret_hu_conv = Option_u64Z.constr_from_ptr(ret);
106                 ret_hu_conv.ptrs_to.add(this);
107                 return ret_hu_conv;
108         }
109
110         /**
111          * The maximum value which may be relayed to the next hop via the channel.
112          */
113         public void set_htlc_maximum_msat(Option_u64Z val) {
114                 bindings.DirectionalChannelInfo_set_htlc_maximum_msat(this.ptr, val.ptr);
115                 Reference.reachabilityFence(this);
116                 Reference.reachabilityFence(val);
117         }
118
119         /**
120          * Fees charged when the channel is used for routing
121          */
122         public RoutingFees get_fees() {
123                 long ret = bindings.DirectionalChannelInfo_get_fees(this.ptr);
124                 Reference.reachabilityFence(this);
125                 if (ret >= 0 && ret <= 4096) { return null; }
126                 RoutingFees ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new RoutingFees(null, ret); }
127                 ret_hu_conv.ptrs_to.add(this);
128                 return ret_hu_conv;
129         }
130
131         /**
132          * Fees charged when the channel is used for routing
133          */
134         public void set_fees(RoutingFees val) {
135                 bindings.DirectionalChannelInfo_set_fees(this.ptr, val == null ? 0 : val.ptr & ~1);
136                 Reference.reachabilityFence(this);
137                 Reference.reachabilityFence(val);
138         }
139
140         /**
141          * Most recent update for the channel received from the network
142          * Mostly redundant with the data we store in fields explicitly.
143          * Everything else is useful only for sending out for initial routing sync.
144          * Not stored if contains excess data to prevent DoS.
145          * 
146          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
147          */
148         @Nullable
149         public ChannelUpdate get_last_update_message() {
150                 long ret = bindings.DirectionalChannelInfo_get_last_update_message(this.ptr);
151                 Reference.reachabilityFence(this);
152                 if (ret >= 0 && ret <= 4096) { return null; }
153                 ChannelUpdate ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ChannelUpdate(null, ret); }
154                 ret_hu_conv.ptrs_to.add(this);
155                 return ret_hu_conv;
156         }
157
158         /**
159          * Most recent update for the channel received from the network
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_last_update_message(@Nullable ChannelUpdate val) {
167                 bindings.DirectionalChannelInfo_set_last_update_message(this.ptr, val == null ? 0 : val.ptr & ~1);
168                 Reference.reachabilityFence(this);
169                 Reference.reachabilityFence(val);
170         }
171
172         /**
173          * Constructs a new DirectionalChannelInfo given each field
174          */
175         public static DirectionalChannelInfo of(int last_update_arg, boolean enabled_arg, short cltv_expiry_delta_arg, long htlc_minimum_msat_arg, Option_u64Z htlc_maximum_msat_arg, RoutingFees fees_arg, ChannelUpdate last_update_message_arg) {
176                 long ret = bindings.DirectionalChannelInfo_new(last_update_arg, enabled_arg, cltv_expiry_delta_arg, htlc_minimum_msat_arg, htlc_maximum_msat_arg.ptr, fees_arg == null ? 0 : fees_arg.ptr & ~1, last_update_message_arg == null ? 0 : last_update_message_arg.ptr & ~1);
177                 Reference.reachabilityFence(last_update_arg);
178                 Reference.reachabilityFence(enabled_arg);
179                 Reference.reachabilityFence(cltv_expiry_delta_arg);
180                 Reference.reachabilityFence(htlc_minimum_msat_arg);
181                 Reference.reachabilityFence(htlc_maximum_msat_arg);
182                 Reference.reachabilityFence(fees_arg);
183                 Reference.reachabilityFence(last_update_message_arg);
184                 if (ret >= 0 && ret <= 4096) { return null; }
185                 DirectionalChannelInfo ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new DirectionalChannelInfo(null, ret); }
186                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
187                 return ret_hu_conv;
188         }
189
190         long clone_ptr() {
191                 long ret = bindings.DirectionalChannelInfo_clone_ptr(this.ptr);
192                 Reference.reachabilityFence(this);
193                 return ret;
194         }
195
196         /**
197          * Creates a copy of the DirectionalChannelInfo
198          */
199         public DirectionalChannelInfo clone() {
200                 long ret = bindings.DirectionalChannelInfo_clone(this.ptr);
201                 Reference.reachabilityFence(this);
202                 if (ret >= 0 && ret <= 4096) { return null; }
203                 DirectionalChannelInfo ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new DirectionalChannelInfo(null, ret); }
204                 ret_hu_conv.ptrs_to.add(this);
205                 return ret_hu_conv;
206         }
207
208         /**
209          * Serialize the DirectionalChannelInfo object into a byte array which can be read by DirectionalChannelInfo_read
210          */
211         public byte[] write() {
212                 byte[] ret = bindings.DirectionalChannelInfo_write(this.ptr);
213                 Reference.reachabilityFence(this);
214                 return ret;
215         }
216
217         /**
218          * Read a DirectionalChannelInfo from a byte array, created by DirectionalChannelInfo_write
219          */
220         public static Result_DirectionalChannelInfoDecodeErrorZ read(byte[] ser) {
221                 long ret = bindings.DirectionalChannelInfo_read(ser);
222                 Reference.reachabilityFence(ser);
223                 if (ret >= 0 && ret <= 4096) { return null; }
224                 Result_DirectionalChannelInfoDecodeErrorZ ret_hu_conv = Result_DirectionalChannelInfoDecodeErrorZ.constr_from_ptr(ret);
225                 return ret_hu_conv;
226         }
227
228 }