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 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);
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 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);
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 * Constructs a new ChannelCounterparty given each field
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);
141 long ret = bindings.ChannelCounterparty_clone_ptr(this.ptr);
142 Reference.reachabilityFence(this);
147 * Creates a copy of the ChannelCounterparty
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);
159 * Serialize the ChannelCounterparty object into a byte array which can be read by ChannelCounterparty_read
161 public byte[] write() {
162 byte[] ret = bindings.ChannelCounterparty_write(this.ptr);
163 Reference.reachabilityFence(this);
168 * Read a ChannelCounterparty from a byte array, created by ChannelCounterparty_write
170 public static Result_ChannelCounterpartyDecodeErrorZ read(byte[] ser) {
171 long ret = bindings.ChannelCounterparty_read(ser);
172 Reference.reachabilityFence(ser);
173 if (ret >= 0 && ret <= 4096) { return null; }
174 Result_ChannelCounterpartyDecodeErrorZ ret_hu_conv = Result_ChannelCounterpartyDecodeErrorZ.constr_from_ptr(ret);