be5614798effa6857f0204bbf7f74f7d6aef79bc
[ldk-java] / src / main / java / org / ldk / structs / ChannelDetails.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 of a channel, as returned by ChannelManager::list_channels and ChannelManager::list_usable_channels
13  */
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class ChannelDetails extends CommonBase {
16         ChannelDetails(Object _dummy, long ptr) { super(ptr); }
17         @Override @SuppressWarnings("deprecation")
18         protected void finalize() throws Throwable {
19                 super.finalize();
20                 if (ptr != 0) { bindings.ChannelDetails_free(ptr); }
21         }
22
23         /**
24          * The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
25          * thereafter this is the txid of the funding transaction xor the funding transaction output).
26          * Note that this means this value is *not* persistent - it can change once during the
27          * lifetime of the channel.
28          */
29         public byte[] get_channel_id() {
30                 byte[] ret = bindings.ChannelDetails_get_channel_id(this.ptr);
31                 Reference.reachabilityFence(this);
32                 return ret;
33         }
34
35         /**
36          * The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
37          * thereafter this is the txid of the funding transaction xor the funding transaction output).
38          * Note that this means this value is *not* persistent - it can change once during the
39          * lifetime of the channel.
40          */
41         public void set_channel_id(byte[] val) {
42                 bindings.ChannelDetails_set_channel_id(this.ptr, InternalUtils.check_arr_len(val, 32));
43                 Reference.reachabilityFence(this);
44                 Reference.reachabilityFence(val);
45         }
46
47         /**
48          * Parameters which apply to our counterparty. See individual fields for more information.
49          */
50         public ChannelCounterparty get_counterparty() {
51                 long ret = bindings.ChannelDetails_get_counterparty(this.ptr);
52                 Reference.reachabilityFence(this);
53                 if (ret >= 0 && ret <= 4096) { return null; }
54                 ChannelCounterparty ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ChannelCounterparty(null, ret); }
55                 ret_hu_conv.ptrs_to.add(this);
56                 return ret_hu_conv;
57         }
58
59         /**
60          * Parameters which apply to our counterparty. See individual fields for more information.
61          */
62         public void set_counterparty(ChannelCounterparty val) {
63                 bindings.ChannelDetails_set_counterparty(this.ptr, val == null ? 0 : val.ptr & ~1);
64                 Reference.reachabilityFence(this);
65                 Reference.reachabilityFence(val);
66         }
67
68         /**
69          * The Channel's funding transaction output, if we've negotiated the funding transaction with
70          * our counterparty already.
71          * 
72          * Note that, if this has been set, `channel_id` will be equivalent to
73          * `funding_txo.unwrap().to_channel_id()`.
74          * 
75          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
76          */
77         @Nullable
78         public OutPoint get_funding_txo() {
79                 long ret = bindings.ChannelDetails_get_funding_txo(this.ptr);
80                 Reference.reachabilityFence(this);
81                 if (ret >= 0 && ret <= 4096) { return null; }
82                 OutPoint ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new OutPoint(null, ret); }
83                 ret_hu_conv.ptrs_to.add(this);
84                 return ret_hu_conv;
85         }
86
87         /**
88          * The Channel's funding transaction output, if we've negotiated the funding transaction with
89          * our counterparty already.
90          * 
91          * Note that, if this has been set, `channel_id` will be equivalent to
92          * `funding_txo.unwrap().to_channel_id()`.
93          * 
94          * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
95          */
96         public void set_funding_txo(@Nullable OutPoint val) {
97                 bindings.ChannelDetails_set_funding_txo(this.ptr, val == null ? 0 : val.ptr & ~1);
98                 Reference.reachabilityFence(this);
99                 Reference.reachabilityFence(val);
100         }
101
102         /**
103          * The position of the funding transaction in the chain. None if the funding transaction has
104          * not yet been confirmed and the channel fully opened.
105          */
106         public Option_u64Z get_short_channel_id() {
107                 long ret = bindings.ChannelDetails_get_short_channel_id(this.ptr);
108                 Reference.reachabilityFence(this);
109                 if (ret >= 0 && ret <= 4096) { return null; }
110                 Option_u64Z ret_hu_conv = Option_u64Z.constr_from_ptr(ret);
111                 ret_hu_conv.ptrs_to.add(this);
112                 return ret_hu_conv;
113         }
114
115         /**
116          * The position of the funding transaction in the chain. None if the funding transaction has
117          * not yet been confirmed and the channel fully opened.
118          */
119         public void set_short_channel_id(Option_u64Z val) {
120                 bindings.ChannelDetails_set_short_channel_id(this.ptr, val.ptr);
121                 Reference.reachabilityFence(this);
122                 Reference.reachabilityFence(val);
123         }
124
125         /**
126          * The value, in satoshis, of this channel as appears in the funding output
127          */
128         public long get_channel_value_satoshis() {
129                 long ret = bindings.ChannelDetails_get_channel_value_satoshis(this.ptr);
130                 Reference.reachabilityFence(this);
131                 return ret;
132         }
133
134         /**
135          * The value, in satoshis, of this channel as appears in the funding output
136          */
137         public void set_channel_value_satoshis(long val) {
138                 bindings.ChannelDetails_set_channel_value_satoshis(this.ptr, val);
139                 Reference.reachabilityFence(this);
140                 Reference.reachabilityFence(val);
141         }
142
143         /**
144          * The value, in satoshis, that must always be held in the channel for us. This value ensures
145          * that if we broadcast a revoked state, our counterparty can punish us by claiming at least
146          * this value on chain.
147          * 
148          * This value is not included in [`outbound_capacity_msat`] as it can never be spent.
149          * 
150          * This value will be `None` for outbound channels until the counterparty accepts the channel.
151          * 
152          * [`outbound_capacity_msat`]: ChannelDetails::outbound_capacity_msat
153          */
154         public Option_u64Z get_unspendable_punishment_reserve() {
155                 long ret = bindings.ChannelDetails_get_unspendable_punishment_reserve(this.ptr);
156                 Reference.reachabilityFence(this);
157                 if (ret >= 0 && ret <= 4096) { return null; }
158                 Option_u64Z ret_hu_conv = Option_u64Z.constr_from_ptr(ret);
159                 ret_hu_conv.ptrs_to.add(this);
160                 return ret_hu_conv;
161         }
162
163         /**
164          * The value, in satoshis, that must always be held in the channel for us. This value ensures
165          * that if we broadcast a revoked state, our counterparty can punish us by claiming at least
166          * this value on chain.
167          * 
168          * This value is not included in [`outbound_capacity_msat`] as it can never be spent.
169          * 
170          * This value will be `None` for outbound channels until the counterparty accepts the channel.
171          * 
172          * [`outbound_capacity_msat`]: ChannelDetails::outbound_capacity_msat
173          */
174         public void set_unspendable_punishment_reserve(Option_u64Z val) {
175                 bindings.ChannelDetails_set_unspendable_punishment_reserve(this.ptr, val.ptr);
176                 Reference.reachabilityFence(this);
177                 Reference.reachabilityFence(val);
178         }
179
180         /**
181          * The `user_channel_id` passed in to create_channel, or 0 if the channel was inbound.
182          */
183         public long get_user_channel_id() {
184                 long ret = bindings.ChannelDetails_get_user_channel_id(this.ptr);
185                 Reference.reachabilityFence(this);
186                 return ret;
187         }
188
189         /**
190          * The `user_channel_id` passed in to create_channel, or 0 if the channel was inbound.
191          */
192         public void set_user_channel_id(long val) {
193                 bindings.ChannelDetails_set_user_channel_id(this.ptr, val);
194                 Reference.reachabilityFence(this);
195                 Reference.reachabilityFence(val);
196         }
197
198         /**
199          * Our total balance.  This is the amount we would get if we close the channel.
200          * This value is not exact. Due to various in-flight changes and feerate changes, exactly this
201          * amount is not likely to be recoverable on close.
202          * 
203          * This does not include any pending HTLCs which are not yet fully resolved (and, thus, whose
204          * balance is not available for inclusion in new outbound HTLCs). This further does not include
205          * any pending outgoing HTLCs which are awaiting some other resolution to be sent.
206          * This does not consider any on-chain fees.
207          * 
208          * See also [`ChannelDetails::outbound_capacity_msat`]
209          */
210         public long get_balance_msat() {
211                 long ret = bindings.ChannelDetails_get_balance_msat(this.ptr);
212                 Reference.reachabilityFence(this);
213                 return ret;
214         }
215
216         /**
217          * Our total balance.  This is the amount we would get if we close the channel.
218          * This value is not exact. Due to various in-flight changes and feerate changes, exactly this
219          * amount is not likely to be recoverable on close.
220          * 
221          * This does not include any pending HTLCs which are not yet fully resolved (and, thus, whose
222          * balance is not available for inclusion in new outbound HTLCs). This further does not include
223          * any pending outgoing HTLCs which are awaiting some other resolution to be sent.
224          * This does not consider any on-chain fees.
225          * 
226          * See also [`ChannelDetails::outbound_capacity_msat`]
227          */
228         public void set_balance_msat(long val) {
229                 bindings.ChannelDetails_set_balance_msat(this.ptr, val);
230                 Reference.reachabilityFence(this);
231                 Reference.reachabilityFence(val);
232         }
233
234         /**
235          * The available outbound capacity for sending HTLCs to the remote peer. This does not include
236          * any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
237          * available for inclusion in new outbound HTLCs). This further does not include any pending
238          * outgoing HTLCs which are awaiting some other resolution to be sent.
239          * 
240          * See also [`ChannelDetails::balance_msat`]
241          * 
242          * This value is not exact. Due to various in-flight changes, feerate changes, and our
243          * conflict-avoidance policy, exactly this amount is not likely to be spendable. However, we
244          * should be able to spend nearly this amount.
245          */
246         public long get_outbound_capacity_msat() {
247                 long ret = bindings.ChannelDetails_get_outbound_capacity_msat(this.ptr);
248                 Reference.reachabilityFence(this);
249                 return ret;
250         }
251
252         /**
253          * The available outbound capacity for sending HTLCs to the remote peer. This does not include
254          * any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
255          * available for inclusion in new outbound HTLCs). This further does not include any pending
256          * outgoing HTLCs which are awaiting some other resolution to be sent.
257          * 
258          * See also [`ChannelDetails::balance_msat`]
259          * 
260          * This value is not exact. Due to various in-flight changes, feerate changes, and our
261          * conflict-avoidance policy, exactly this amount is not likely to be spendable. However, we
262          * should be able to spend nearly this amount.
263          */
264         public void set_outbound_capacity_msat(long val) {
265                 bindings.ChannelDetails_set_outbound_capacity_msat(this.ptr, val);
266                 Reference.reachabilityFence(this);
267                 Reference.reachabilityFence(val);
268         }
269
270         /**
271          * The available inbound capacity for the remote peer to send HTLCs to us. This does not
272          * include any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
273          * available for inclusion in new inbound HTLCs).
274          * Note that there are some corner cases not fully handled here, so the actual available
275          * inbound capacity may be slightly higher than this.
276          * 
277          * This value is not exact. Due to various in-flight changes, feerate changes, and our
278          * counterparty's conflict-avoidance policy, exactly this amount is not likely to be spendable.
279          * However, our counterparty should be able to spend nearly this amount.
280          */
281         public long get_inbound_capacity_msat() {
282                 long ret = bindings.ChannelDetails_get_inbound_capacity_msat(this.ptr);
283                 Reference.reachabilityFence(this);
284                 return ret;
285         }
286
287         /**
288          * The available inbound capacity for the remote peer to send HTLCs to us. This does not
289          * include any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
290          * available for inclusion in new inbound HTLCs).
291          * Note that there are some corner cases not fully handled here, so the actual available
292          * inbound capacity may be slightly higher than this.
293          * 
294          * This value is not exact. Due to various in-flight changes, feerate changes, and our
295          * counterparty's conflict-avoidance policy, exactly this amount is not likely to be spendable.
296          * However, our counterparty should be able to spend nearly this amount.
297          */
298         public void set_inbound_capacity_msat(long val) {
299                 bindings.ChannelDetails_set_inbound_capacity_msat(this.ptr, val);
300                 Reference.reachabilityFence(this);
301                 Reference.reachabilityFence(val);
302         }
303
304         /**
305          * The number of required confirmations on the funding transaction before the funding will be
306          * considered \"locked\". This number is selected by the channel fundee (i.e. us if
307          * [`is_outbound`] is *not* set), and can be selected for inbound channels with
308          * [`ChannelHandshakeConfig::minimum_depth`] or limited for outbound channels with
309          * [`ChannelHandshakeLimits::max_minimum_depth`].
310          * 
311          * This value will be `None` for outbound channels until the counterparty accepts the channel.
312          * 
313          * [`is_outbound`]: ChannelDetails::is_outbound
314          * [`ChannelHandshakeConfig::minimum_depth`]: crate::util::config::ChannelHandshakeConfig::minimum_depth
315          * [`ChannelHandshakeLimits::max_minimum_depth`]: crate::util::config::ChannelHandshakeLimits::max_minimum_depth
316          */
317         public Option_u32Z get_confirmations_required() {
318                 long ret = bindings.ChannelDetails_get_confirmations_required(this.ptr);
319                 Reference.reachabilityFence(this);
320                 if (ret >= 0 && ret <= 4096) { return null; }
321                 Option_u32Z ret_hu_conv = Option_u32Z.constr_from_ptr(ret);
322                 ret_hu_conv.ptrs_to.add(this);
323                 return ret_hu_conv;
324         }
325
326         /**
327          * The number of required confirmations on the funding transaction before the funding will be
328          * considered \"locked\". This number is selected by the channel fundee (i.e. us if
329          * [`is_outbound`] is *not* set), and can be selected for inbound channels with
330          * [`ChannelHandshakeConfig::minimum_depth`] or limited for outbound channels with
331          * [`ChannelHandshakeLimits::max_minimum_depth`].
332          * 
333          * This value will be `None` for outbound channels until the counterparty accepts the channel.
334          * 
335          * [`is_outbound`]: ChannelDetails::is_outbound
336          * [`ChannelHandshakeConfig::minimum_depth`]: crate::util::config::ChannelHandshakeConfig::minimum_depth
337          * [`ChannelHandshakeLimits::max_minimum_depth`]: crate::util::config::ChannelHandshakeLimits::max_minimum_depth
338          */
339         public void set_confirmations_required(Option_u32Z val) {
340                 bindings.ChannelDetails_set_confirmations_required(this.ptr, val.ptr);
341                 Reference.reachabilityFence(this);
342                 Reference.reachabilityFence(val);
343         }
344
345         /**
346          * The number of blocks (after our commitment transaction confirms) that we will need to wait
347          * until we can claim our funds after we force-close the channel. During this time our
348          * counterparty is allowed to punish us if we broadcasted a stale state. If our counterparty
349          * force-closes the channel and broadcasts a commitment transaction we do not have to wait any
350          * time to claim our non-HTLC-encumbered funds.
351          * 
352          * This value will be `None` for outbound channels until the counterparty accepts the channel.
353          */
354         public Option_u16Z get_force_close_spend_delay() {
355                 long ret = bindings.ChannelDetails_get_force_close_spend_delay(this.ptr);
356                 Reference.reachabilityFence(this);
357                 if (ret >= 0 && ret <= 4096) { return null; }
358                 Option_u16Z ret_hu_conv = Option_u16Z.constr_from_ptr(ret);
359                 ret_hu_conv.ptrs_to.add(this);
360                 return ret_hu_conv;
361         }
362
363         /**
364          * The number of blocks (after our commitment transaction confirms) that we will need to wait
365          * until we can claim our funds after we force-close the channel. During this time our
366          * counterparty is allowed to punish us if we broadcasted a stale state. If our counterparty
367          * force-closes the channel and broadcasts a commitment transaction we do not have to wait any
368          * time to claim our non-HTLC-encumbered funds.
369          * 
370          * This value will be `None` for outbound channels until the counterparty accepts the channel.
371          */
372         public void set_force_close_spend_delay(Option_u16Z val) {
373                 bindings.ChannelDetails_set_force_close_spend_delay(this.ptr, val.ptr);
374                 Reference.reachabilityFence(this);
375                 Reference.reachabilityFence(val);
376         }
377
378         /**
379          * True if the channel was initiated (and thus funded) by us.
380          */
381         public boolean get_is_outbound() {
382                 boolean ret = bindings.ChannelDetails_get_is_outbound(this.ptr);
383                 Reference.reachabilityFence(this);
384                 return ret;
385         }
386
387         /**
388          * True if the channel was initiated (and thus funded) by us.
389          */
390         public void set_is_outbound(boolean val) {
391                 bindings.ChannelDetails_set_is_outbound(this.ptr, val);
392                 Reference.reachabilityFence(this);
393                 Reference.reachabilityFence(val);
394         }
395
396         /**
397          * True if the channel is confirmed, funding_locked messages have been exchanged, and the
398          * channel is not currently being shut down. `funding_locked` message exchange implies the
399          * required confirmation count has been reached (and we were connected to the peer at some
400          * point after the funding transaction received enough confirmations). The required
401          * confirmation count is provided in [`confirmations_required`].
402          * 
403          * [`confirmations_required`]: ChannelDetails::confirmations_required
404          */
405         public boolean get_is_funding_locked() {
406                 boolean ret = bindings.ChannelDetails_get_is_funding_locked(this.ptr);
407                 Reference.reachabilityFence(this);
408                 return ret;
409         }
410
411         /**
412          * True if the channel is confirmed, funding_locked messages have been exchanged, and the
413          * channel is not currently being shut down. `funding_locked` message exchange implies the
414          * required confirmation count has been reached (and we were connected to the peer at some
415          * point after the funding transaction received enough confirmations). The required
416          * confirmation count is provided in [`confirmations_required`].
417          * 
418          * [`confirmations_required`]: ChannelDetails::confirmations_required
419          */
420         public void set_is_funding_locked(boolean val) {
421                 bindings.ChannelDetails_set_is_funding_locked(this.ptr, val);
422                 Reference.reachabilityFence(this);
423                 Reference.reachabilityFence(val);
424         }
425
426         /**
427          * True if the channel is (a) confirmed and funding_locked messages have been exchanged, (b)
428          * the peer is connected, and (c) the channel is not currently negotiating a shutdown.
429          * 
430          * This is a strict superset of `is_funding_locked`.
431          */
432         public boolean get_is_usable() {
433                 boolean ret = bindings.ChannelDetails_get_is_usable(this.ptr);
434                 Reference.reachabilityFence(this);
435                 return ret;
436         }
437
438         /**
439          * True if the channel is (a) confirmed and funding_locked messages have been exchanged, (b)
440          * the peer is connected, and (c) the channel is not currently negotiating a shutdown.
441          * 
442          * This is a strict superset of `is_funding_locked`.
443          */
444         public void set_is_usable(boolean val) {
445                 bindings.ChannelDetails_set_is_usable(this.ptr, val);
446                 Reference.reachabilityFence(this);
447                 Reference.reachabilityFence(val);
448         }
449
450         /**
451          * True if this channel is (or will be) publicly-announced.
452          */
453         public boolean get_is_public() {
454                 boolean ret = bindings.ChannelDetails_get_is_public(this.ptr);
455                 Reference.reachabilityFence(this);
456                 return ret;
457         }
458
459         /**
460          * True if this channel is (or will be) publicly-announced.
461          */
462         public void set_is_public(boolean val) {
463                 bindings.ChannelDetails_set_is_public(this.ptr, val);
464                 Reference.reachabilityFence(this);
465                 Reference.reachabilityFence(val);
466         }
467
468         /**
469          * Constructs a new ChannelDetails given each field
470          */
471         public static ChannelDetails of(byte[] channel_id_arg, ChannelCounterparty counterparty_arg, OutPoint funding_txo_arg, Option_u64Z short_channel_id_arg, long channel_value_satoshis_arg, Option_u64Z unspendable_punishment_reserve_arg, long user_channel_id_arg, long balance_msat_arg, long outbound_capacity_msat_arg, long inbound_capacity_msat_arg, Option_u32Z confirmations_required_arg, Option_u16Z force_close_spend_delay_arg, boolean is_outbound_arg, boolean is_funding_locked_arg, boolean is_usable_arg, boolean is_public_arg) {
472                 long ret = bindings.ChannelDetails_new(InternalUtils.check_arr_len(channel_id_arg, 32), counterparty_arg == null ? 0 : counterparty_arg.ptr & ~1, funding_txo_arg == null ? 0 : funding_txo_arg.ptr & ~1, short_channel_id_arg.ptr, channel_value_satoshis_arg, unspendable_punishment_reserve_arg.ptr, user_channel_id_arg, balance_msat_arg, outbound_capacity_msat_arg, inbound_capacity_msat_arg, confirmations_required_arg.ptr, force_close_spend_delay_arg.ptr, is_outbound_arg, is_funding_locked_arg, is_usable_arg, is_public_arg);
473                 Reference.reachabilityFence(channel_id_arg);
474                 Reference.reachabilityFence(counterparty_arg);
475                 Reference.reachabilityFence(funding_txo_arg);
476                 Reference.reachabilityFence(short_channel_id_arg);
477                 Reference.reachabilityFence(channel_value_satoshis_arg);
478                 Reference.reachabilityFence(unspendable_punishment_reserve_arg);
479                 Reference.reachabilityFence(user_channel_id_arg);
480                 Reference.reachabilityFence(balance_msat_arg);
481                 Reference.reachabilityFence(outbound_capacity_msat_arg);
482                 Reference.reachabilityFence(inbound_capacity_msat_arg);
483                 Reference.reachabilityFence(confirmations_required_arg);
484                 Reference.reachabilityFence(force_close_spend_delay_arg);
485                 Reference.reachabilityFence(is_outbound_arg);
486                 Reference.reachabilityFence(is_funding_locked_arg);
487                 Reference.reachabilityFence(is_usable_arg);
488                 Reference.reachabilityFence(is_public_arg);
489                 if (ret >= 0 && ret <= 4096) { return null; }
490                 ChannelDetails ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ChannelDetails(null, ret); }
491                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
492                 return ret_hu_conv;
493         }
494
495         long clone_ptr() {
496                 long ret = bindings.ChannelDetails_clone_ptr(this.ptr);
497                 Reference.reachabilityFence(this);
498                 return ret;
499         }
500
501         /**
502          * Creates a copy of the ChannelDetails
503          */
504         public ChannelDetails clone() {
505                 long ret = bindings.ChannelDetails_clone(this.ptr);
506                 Reference.reachabilityFence(this);
507                 if (ret >= 0 && ret <= 4096) { return null; }
508                 ChannelDetails ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ChannelDetails(null, ret); }
509                 ret_hu_conv.ptrs_to.add(this);
510                 return ret_hu_conv;
511         }
512
513         /**
514          * Serialize the ChannelDetails object into a byte array which can be read by ChannelDetails_read
515          */
516         public byte[] write() {
517                 byte[] ret = bindings.ChannelDetails_write(this.ptr);
518                 Reference.reachabilityFence(this);
519                 return ret;
520         }
521
522         /**
523          * Read a ChannelDetails from a byte array, created by ChannelDetails_write
524          */
525         public static Result_ChannelDetailsDecodeErrorZ read(byte[] ser) {
526                 long ret = bindings.ChannelDetails_read(ser);
527                 Reference.reachabilityFence(ser);
528                 if (ret >= 0 && ret <= 4096) { return null; }
529                 Result_ChannelDetailsDecodeErrorZ ret_hu_conv = Result_ChannelDetailsDecodeErrorZ.constr_from_ptr(ret);
530                 return ret_hu_conv;
531         }
532
533 }