1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * Channel parameters which apply to our counterparty. These are split out from [`ChannelDetails`]
13 * to better separate parameters.
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 {
21 if (ptr != 0) { bindings.ChannelCounterparty_free(ptr); }
25 * The node_id of our counterparty
27 public byte[] get_node_id() {
28 byte[] ret = bindings.ChannelCounterparty_get_node_id(this.ptr);
29 Reference.reachabilityFence(this);
34 * The node_id of our counterparty
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);
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.
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);
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.
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);
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.
72 * This value is not included in [`inbound_capacity_msat`] as it can never be spent.
74 * [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
76 public long get_unspendable_punishment_reserve() {
77 long ret = bindings.ChannelCounterparty_get_unspendable_punishment_reserve(this.ptr);
78 Reference.reachabilityFence(this);
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.
87 * This value is not included in [`inbound_capacity_msat`] as it can never be spent.
89 * [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
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);
98 * Information on the fees and requirements that the counterparty requires when forwarding
99 * payments to us through this channel.
101 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
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);
114 * Information on the fees and requirements that the counterparty requires when forwarding
115 * payments to us through this channel.
117 * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
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);
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.
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);
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.
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);
151 * The largest value HTLC (in msat) the remote peer currently will accept, for this channel.
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);
163 * The largest value HTLC (in msat) the remote peer currently will accept, for this channel.
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);
172 * Constructs a new ChannelCounterparty given each field
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);
189 long ret = bindings.ChannelCounterparty_clone_ptr(this.ptr);
190 Reference.reachabilityFence(this);
195 * Creates a copy of the ChannelCounterparty
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);
207 * Serialize the ChannelCounterparty object into a byte array which can be read by ChannelCounterparty_read
209 public byte[] write() {
210 byte[] ret = bindings.ChannelCounterparty_write(this.ptr);
211 Reference.reachabilityFence(this);
216 * Read a ChannelCounterparty from a byte array, created by ChannelCounterparty_write
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);