93d0688f5c39d5da88fee929a413192bffcc5b67
[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                 org.ldk.structs.InitFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.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                 org.ldk.structs.CounterpartyForwardingInfo ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.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          * The smallest value HTLC (in msat) the remote peer will accept, for this channel. This field
127          * is only `None` before we have received either the `OpenChannel` or `AcceptChannel` message
128          * from the remote peer, or for `ChannelCounterparty` objects serialized prior to LDK 0.0.107.
129          */
130         public Option_u64Z get_outbound_htlc_minimum_msat() {
131                 long ret = bindings.ChannelCounterparty_get_outbound_htlc_minimum_msat(this.ptr);
132                 Reference.reachabilityFence(this);
133                 if (ret >= 0 && ret <= 4096) { return null; }
134                 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
135                 ret_hu_conv.ptrs_to.add(this);
136                 return ret_hu_conv;
137         }
138
139         /**
140          * The smallest value HTLC (in msat) the remote peer will accept, for this channel. This field
141          * is only `None` before we have received either the `OpenChannel` or `AcceptChannel` message
142          * from the remote peer, or for `ChannelCounterparty` objects serialized prior to LDK 0.0.107.
143          */
144         public void set_outbound_htlc_minimum_msat(Option_u64Z val) {
145                 bindings.ChannelCounterparty_set_outbound_htlc_minimum_msat(this.ptr, val.ptr);
146                 Reference.reachabilityFence(this);
147                 Reference.reachabilityFence(val);
148         }
149
150         /**
151          * The largest value HTLC (in msat) the remote peer currently will accept, for this channel.
152          */
153         public Option_u64Z get_outbound_htlc_maximum_msat() {
154                 long ret = bindings.ChannelCounterparty_get_outbound_htlc_maximum_msat(this.ptr);
155                 Reference.reachabilityFence(this);
156                 if (ret >= 0 && ret <= 4096) { return null; }
157                 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
158                 ret_hu_conv.ptrs_to.add(this);
159                 return ret_hu_conv;
160         }
161
162         /**
163          * The largest value HTLC (in msat) the remote peer currently will accept, for this channel.
164          */
165         public void set_outbound_htlc_maximum_msat(Option_u64Z val) {
166                 bindings.ChannelCounterparty_set_outbound_htlc_maximum_msat(this.ptr, val.ptr);
167                 Reference.reachabilityFence(this);
168                 Reference.reachabilityFence(val);
169         }
170
171         /**
172          * Constructs a new ChannelCounterparty given each field
173          */
174         public static ChannelCounterparty of(byte[] node_id_arg, InitFeatures features_arg, long unspendable_punishment_reserve_arg, CounterpartyForwardingInfo forwarding_info_arg, Option_u64Z outbound_htlc_minimum_msat_arg, Option_u64Z outbound_htlc_maximum_msat_arg) {
175                 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, outbound_htlc_minimum_msat_arg.ptr, outbound_htlc_maximum_msat_arg.ptr);
176                 Reference.reachabilityFence(node_id_arg);
177                 Reference.reachabilityFence(features_arg);
178                 Reference.reachabilityFence(unspendable_punishment_reserve_arg);
179                 Reference.reachabilityFence(forwarding_info_arg);
180                 Reference.reachabilityFence(outbound_htlc_minimum_msat_arg);
181                 Reference.reachabilityFence(outbound_htlc_maximum_msat_arg);
182                 if (ret >= 0 && ret <= 4096) { return null; }
183                 org.ldk.structs.ChannelCounterparty ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelCounterparty(null, ret); }
184                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
185                 return ret_hu_conv;
186         }
187
188         long clone_ptr() {
189                 long ret = bindings.ChannelCounterparty_clone_ptr(this.ptr);
190                 Reference.reachabilityFence(this);
191                 return ret;
192         }
193
194         /**
195          * Creates a copy of the ChannelCounterparty
196          */
197         public ChannelCounterparty clone() {
198                 long ret = bindings.ChannelCounterparty_clone(this.ptr);
199                 Reference.reachabilityFence(this);
200                 if (ret >= 0 && ret <= 4096) { return null; }
201                 org.ldk.structs.ChannelCounterparty ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelCounterparty(null, ret); }
202                 ret_hu_conv.ptrs_to.add(this);
203                 return ret_hu_conv;
204         }
205
206         /**
207          * Serialize the ChannelCounterparty object into a byte array which can be read by ChannelCounterparty_read
208          */
209         public byte[] write() {
210                 byte[] ret = bindings.ChannelCounterparty_write(this.ptr);
211                 Reference.reachabilityFence(this);
212                 return ret;
213         }
214
215         /**
216          * Read a ChannelCounterparty from a byte array, created by ChannelCounterparty_write
217          */
218         public static Result_ChannelCounterpartyDecodeErrorZ read(byte[] ser) {
219                 long ret = bindings.ChannelCounterparty_read(ser);
220                 Reference.reachabilityFence(ser);
221                 if (ret >= 0 && ret <= 4096) { return null; }
222                 Result_ChannelCounterpartyDecodeErrorZ ret_hu_conv = Result_ChannelCounterpartyDecodeErrorZ.constr_from_ptr(ret);
223                 return ret_hu_conv;
224         }
225
226 }