d355cbf1cb55642668c8a92bb4bff2e53a1a574a
[ldk-java] / src / main / java / org / ldk / structs / ChannelCounterparty.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  * Channel parameters which apply to our counterparty. These are split out from [`ChannelDetails`]
13  * to better separate parameters.
14  */
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class ChannelCounterparty extends CommonBase {
17         ChannelCounterparty(Object _dummy, long ptr) { super(ptr); }
18         @Override @SuppressWarnings("deprecation")
19         protected void finalize() throws Throwable {
20                 super.finalize();
21                 if (ptr != 0) { bindings.ChannelCounterparty_free(ptr); }
22         }
23
24         /**
25          * The node_id of our counterparty
26          */
27         public byte[] get_node_id() {
28                 byte[] ret = bindings.ChannelCounterparty_get_node_id(this.ptr);
29                 Reference.reachabilityFence(this);
30                 return ret;
31         }
32
33         /**
34          * The node_id of our counterparty
35          */
36         public void set_node_id(byte[] val) {
37                 bindings.ChannelCounterparty_set_node_id(this.ptr, InternalUtils.check_arr_len(val, 33));
38                 Reference.reachabilityFence(this);
39                 Reference.reachabilityFence(val);
40         }
41
42         /**
43          * The Features the channel counterparty provided upon last connection.
44          * Useful for routing as it is the most up-to-date copy of the counterparty's features and
45          * many routing-relevant features are present in the init context.
46          */
47         public InitFeatures get_features() {
48                 long ret = bindings.ChannelCounterparty_get_features(this.ptr);
49                 Reference.reachabilityFence(this);
50                 if (ret >= 0 && ret <= 4096) { return null; }
51                 InitFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new InitFeatures(null, ret); }
52                 ret_hu_conv.ptrs_to.add(this);
53                 return ret_hu_conv;
54         }
55
56         /**
57          * The Features the channel counterparty provided upon last connection.
58          * Useful for routing as it is the most up-to-date copy of the counterparty's features and
59          * many routing-relevant features are present in the init context.
60          */
61         public void set_features(InitFeatures val) {
62                 bindings.ChannelCounterparty_set_features(this.ptr, val == null ? 0 : val.ptr & ~1);
63                 Reference.reachabilityFence(this);
64                 Reference.reachabilityFence(val);
65         }
66
67         /**
68          * The value, in satoshis, that must always be held in the channel for our counterparty. This
69          * value ensures that if our counterparty broadcasts a revoked state, we can punish them by
70          * claiming at least this value on chain.
71          * 
72          * This value is not included in [`inbound_capacity_msat`] as it can never be spent.
73          * 
74          * [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
75          */
76         public long get_unspendable_punishment_reserve() {
77                 long ret = bindings.ChannelCounterparty_get_unspendable_punishment_reserve(this.ptr);
78                 Reference.reachabilityFence(this);
79                 return ret;
80         }
81
82         /**
83          * The value, in satoshis, that must always be held in the channel for our counterparty. This
84          * value ensures that if our counterparty broadcasts a revoked state, we can punish them by
85          * claiming at least this value on chain.
86          * 
87          * This value is not included in [`inbound_capacity_msat`] as it can never be spent.
88          * 
89          * [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
90          */
91         public void set_unspendable_punishment_reserve(long val) {
92                 bindings.ChannelCounterparty_set_unspendable_punishment_reserve(this.ptr, val);
93                 Reference.reachabilityFence(this);
94                 Reference.reachabilityFence(val);
95         }
96
97         /**
98          * Information on the fees and requirements that the counterparty requires when forwarding
99          * payments to us through this channel.
100          * 
101          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
102          */
103         @Nullable
104         public CounterpartyForwardingInfo get_forwarding_info() {
105                 long ret = bindings.ChannelCounterparty_get_forwarding_info(this.ptr);
106                 Reference.reachabilityFence(this);
107                 if (ret >= 0 && ret <= 4096) { return null; }
108                 CounterpartyForwardingInfo ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new CounterpartyForwardingInfo(null, ret); }
109                 ret_hu_conv.ptrs_to.add(this);
110                 return ret_hu_conv;
111         }
112
113         /**
114          * Information on the fees and requirements that the counterparty requires when forwarding
115          * payments to us through this 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_forwarding_info(@Nullable CounterpartyForwardingInfo val) {
120                 bindings.ChannelCounterparty_set_forwarding_info(this.ptr, val == null ? 0 : val.ptr & ~1);
121                 Reference.reachabilityFence(this);
122                 Reference.reachabilityFence(val);
123         }
124
125         /**
126          * Constructs a new ChannelCounterparty given each field
127          */
128         public static ChannelCounterparty of(byte[] node_id_arg, InitFeatures features_arg, long unspendable_punishment_reserve_arg, CounterpartyForwardingInfo forwarding_info_arg) {
129                 long ret = bindings.ChannelCounterparty_new(InternalUtils.check_arr_len(node_id_arg, 33), features_arg == null ? 0 : features_arg.ptr & ~1, unspendable_punishment_reserve_arg, forwarding_info_arg == null ? 0 : forwarding_info_arg.ptr & ~1);
130                 Reference.reachabilityFence(node_id_arg);
131                 Reference.reachabilityFence(features_arg);
132                 Reference.reachabilityFence(unspendable_punishment_reserve_arg);
133                 Reference.reachabilityFence(forwarding_info_arg);
134                 if (ret >= 0 && ret <= 4096) { return null; }
135                 ChannelCounterparty ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ChannelCounterparty(null, ret); }
136                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
137                 return ret_hu_conv;
138         }
139
140         long clone_ptr() {
141                 long ret = bindings.ChannelCounterparty_clone_ptr(this.ptr);
142                 Reference.reachabilityFence(this);
143                 return ret;
144         }
145
146         /**
147          * Creates a copy of the ChannelCounterparty
148          */
149         public ChannelCounterparty clone() {
150                 long ret = bindings.ChannelCounterparty_clone(this.ptr);
151                 Reference.reachabilityFence(this);
152                 if (ret >= 0 && ret <= 4096) { return null; }
153                 ChannelCounterparty ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ChannelCounterparty(null, ret); }
154                 ret_hu_conv.ptrs_to.add(this);
155                 return ret_hu_conv;
156         }
157
158 }