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 * An [`open_channel`] message to be sent to or received from a peer.
14 * Used in V1 channel establishment
16 * [`open_channel`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-open_channel-message
18 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
19 public class OpenChannel extends CommonBase {
20 OpenChannel(Object _dummy, long ptr) { super(ptr); }
21 @Override @SuppressWarnings("deprecation")
22 protected void finalize() throws Throwable {
24 if (ptr != 0) { bindings.OpenChannel_free(ptr); }
28 * The genesis hash of the blockchain where the channel is to be opened
30 public byte[] get_chain_hash() {
31 byte[] ret = bindings.OpenChannel_get_chain_hash(this.ptr);
32 Reference.reachabilityFence(this);
37 * The genesis hash of the blockchain where the channel is to be opened
39 public void set_chain_hash(byte[] val) {
40 bindings.OpenChannel_set_chain_hash(this.ptr, InternalUtils.check_arr_len(val, 32));
41 Reference.reachabilityFence(this);
42 Reference.reachabilityFence(val);
46 * A temporary channel ID, until the funding outpoint is announced
48 public byte[] get_temporary_channel_id() {
49 byte[] ret = bindings.OpenChannel_get_temporary_channel_id(this.ptr);
50 Reference.reachabilityFence(this);
55 * A temporary channel ID, until the funding outpoint is announced
57 public void set_temporary_channel_id(byte[] val) {
58 bindings.OpenChannel_set_temporary_channel_id(this.ptr, InternalUtils.check_arr_len(val, 32));
59 Reference.reachabilityFence(this);
60 Reference.reachabilityFence(val);
66 public long get_funding_satoshis() {
67 long ret = bindings.OpenChannel_get_funding_satoshis(this.ptr);
68 Reference.reachabilityFence(this);
75 public void set_funding_satoshis(long val) {
76 bindings.OpenChannel_set_funding_satoshis(this.ptr, val);
77 Reference.reachabilityFence(this);
78 Reference.reachabilityFence(val);
82 * The amount to push to the counterparty as part of the open, in milli-satoshi
84 public long get_push_msat() {
85 long ret = bindings.OpenChannel_get_push_msat(this.ptr);
86 Reference.reachabilityFence(this);
91 * The amount to push to the counterparty as part of the open, in milli-satoshi
93 public void set_push_msat(long val) {
94 bindings.OpenChannel_set_push_msat(this.ptr, val);
95 Reference.reachabilityFence(this);
96 Reference.reachabilityFence(val);
100 * The threshold below which outputs on transactions broadcast by sender will be omitted
102 public long get_dust_limit_satoshis() {
103 long ret = bindings.OpenChannel_get_dust_limit_satoshis(this.ptr);
104 Reference.reachabilityFence(this);
109 * The threshold below which outputs on transactions broadcast by sender will be omitted
111 public void set_dust_limit_satoshis(long val) {
112 bindings.OpenChannel_set_dust_limit_satoshis(this.ptr, val);
113 Reference.reachabilityFence(this);
114 Reference.reachabilityFence(val);
118 * The maximum inbound HTLC value in flight towards sender, in milli-satoshi
120 public long get_max_htlc_value_in_flight_msat() {
121 long ret = bindings.OpenChannel_get_max_htlc_value_in_flight_msat(this.ptr);
122 Reference.reachabilityFence(this);
127 * The maximum inbound HTLC value in flight towards sender, in milli-satoshi
129 public void set_max_htlc_value_in_flight_msat(long val) {
130 bindings.OpenChannel_set_max_htlc_value_in_flight_msat(this.ptr, val);
131 Reference.reachabilityFence(this);
132 Reference.reachabilityFence(val);
136 * The minimum value unencumbered by HTLCs for the counterparty to keep in the channel
138 public long get_channel_reserve_satoshis() {
139 long ret = bindings.OpenChannel_get_channel_reserve_satoshis(this.ptr);
140 Reference.reachabilityFence(this);
145 * The minimum value unencumbered by HTLCs for the counterparty to keep in the channel
147 public void set_channel_reserve_satoshis(long val) {
148 bindings.OpenChannel_set_channel_reserve_satoshis(this.ptr, val);
149 Reference.reachabilityFence(this);
150 Reference.reachabilityFence(val);
154 * The minimum HTLC size incoming to sender, in milli-satoshi
156 public long get_htlc_minimum_msat() {
157 long ret = bindings.OpenChannel_get_htlc_minimum_msat(this.ptr);
158 Reference.reachabilityFence(this);
163 * The minimum HTLC size incoming to sender, in milli-satoshi
165 public void set_htlc_minimum_msat(long val) {
166 bindings.OpenChannel_set_htlc_minimum_msat(this.ptr, val);
167 Reference.reachabilityFence(this);
168 Reference.reachabilityFence(val);
172 * The feerate per 1000-weight of sender generated transactions, until updated by
175 public int get_feerate_per_kw() {
176 int ret = bindings.OpenChannel_get_feerate_per_kw(this.ptr);
177 Reference.reachabilityFence(this);
182 * The feerate per 1000-weight of sender generated transactions, until updated by
185 public void set_feerate_per_kw(int val) {
186 bindings.OpenChannel_set_feerate_per_kw(this.ptr, val);
187 Reference.reachabilityFence(this);
188 Reference.reachabilityFence(val);
192 * The number of blocks which the counterparty will have to wait to claim on-chain funds if
193 * they broadcast a commitment transaction
195 public short get_to_self_delay() {
196 short ret = bindings.OpenChannel_get_to_self_delay(this.ptr);
197 Reference.reachabilityFence(this);
202 * The number of blocks which the counterparty will have to wait to claim on-chain funds if
203 * they broadcast a commitment transaction
205 public void set_to_self_delay(short val) {
206 bindings.OpenChannel_set_to_self_delay(this.ptr, val);
207 Reference.reachabilityFence(this);
208 Reference.reachabilityFence(val);
212 * The maximum number of inbound HTLCs towards sender
214 public short get_max_accepted_htlcs() {
215 short ret = bindings.OpenChannel_get_max_accepted_htlcs(this.ptr);
216 Reference.reachabilityFence(this);
221 * The maximum number of inbound HTLCs towards sender
223 public void set_max_accepted_htlcs(short val) {
224 bindings.OpenChannel_set_max_accepted_htlcs(this.ptr, val);
225 Reference.reachabilityFence(this);
226 Reference.reachabilityFence(val);
230 * The sender's key controlling the funding transaction
232 public byte[] get_funding_pubkey() {
233 byte[] ret = bindings.OpenChannel_get_funding_pubkey(this.ptr);
234 Reference.reachabilityFence(this);
239 * The sender's key controlling the funding transaction
241 public void set_funding_pubkey(byte[] val) {
242 bindings.OpenChannel_set_funding_pubkey(this.ptr, InternalUtils.check_arr_len(val, 33));
243 Reference.reachabilityFence(this);
244 Reference.reachabilityFence(val);
248 * Used to derive a revocation key for transactions broadcast by counterparty
250 public byte[] get_revocation_basepoint() {
251 byte[] ret = bindings.OpenChannel_get_revocation_basepoint(this.ptr);
252 Reference.reachabilityFence(this);
257 * Used to derive a revocation key for transactions broadcast by counterparty
259 public void set_revocation_basepoint(byte[] val) {
260 bindings.OpenChannel_set_revocation_basepoint(this.ptr, InternalUtils.check_arr_len(val, 33));
261 Reference.reachabilityFence(this);
262 Reference.reachabilityFence(val);
266 * A payment key to sender for transactions broadcast by counterparty
268 public byte[] get_payment_point() {
269 byte[] ret = bindings.OpenChannel_get_payment_point(this.ptr);
270 Reference.reachabilityFence(this);
275 * A payment key to sender for transactions broadcast by counterparty
277 public void set_payment_point(byte[] val) {
278 bindings.OpenChannel_set_payment_point(this.ptr, InternalUtils.check_arr_len(val, 33));
279 Reference.reachabilityFence(this);
280 Reference.reachabilityFence(val);
284 * Used to derive a payment key to sender for transactions broadcast by sender
286 public byte[] get_delayed_payment_basepoint() {
287 byte[] ret = bindings.OpenChannel_get_delayed_payment_basepoint(this.ptr);
288 Reference.reachabilityFence(this);
293 * Used to derive a payment key to sender for transactions broadcast by sender
295 public void set_delayed_payment_basepoint(byte[] val) {
296 bindings.OpenChannel_set_delayed_payment_basepoint(this.ptr, InternalUtils.check_arr_len(val, 33));
297 Reference.reachabilityFence(this);
298 Reference.reachabilityFence(val);
302 * Used to derive an HTLC payment key to sender
304 public byte[] get_htlc_basepoint() {
305 byte[] ret = bindings.OpenChannel_get_htlc_basepoint(this.ptr);
306 Reference.reachabilityFence(this);
311 * Used to derive an HTLC payment key to sender
313 public void set_htlc_basepoint(byte[] val) {
314 bindings.OpenChannel_set_htlc_basepoint(this.ptr, InternalUtils.check_arr_len(val, 33));
315 Reference.reachabilityFence(this);
316 Reference.reachabilityFence(val);
320 * The first to-be-broadcast-by-sender transaction's per commitment point
322 public byte[] get_first_per_commitment_point() {
323 byte[] ret = bindings.OpenChannel_get_first_per_commitment_point(this.ptr);
324 Reference.reachabilityFence(this);
329 * The first to-be-broadcast-by-sender transaction's per commitment point
331 public void set_first_per_commitment_point(byte[] val) {
332 bindings.OpenChannel_set_first_per_commitment_point(this.ptr, InternalUtils.check_arr_len(val, 33));
333 Reference.reachabilityFence(this);
334 Reference.reachabilityFence(val);
338 * The channel flags to be used
340 public byte get_channel_flags() {
341 byte ret = bindings.OpenChannel_get_channel_flags(this.ptr);
342 Reference.reachabilityFence(this);
347 * The channel flags to be used
349 public void set_channel_flags(byte val) {
350 bindings.OpenChannel_set_channel_flags(this.ptr, val);
351 Reference.reachabilityFence(this);
352 Reference.reachabilityFence(val);
356 * A request to pre-set the to-sender output's `scriptPubkey` for when we collaboratively close
358 public Option_CVec_u8ZZ get_shutdown_scriptpubkey() {
359 long ret = bindings.OpenChannel_get_shutdown_scriptpubkey(this.ptr);
360 Reference.reachabilityFence(this);
361 if (ret >= 0 && ret <= 4096) { return null; }
362 org.ldk.structs.Option_CVec_u8ZZ ret_hu_conv = org.ldk.structs.Option_CVec_u8ZZ.constr_from_ptr(ret);
363 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
368 * A request to pre-set the to-sender output's `scriptPubkey` for when we collaboratively close
370 public void set_shutdown_scriptpubkey(org.ldk.structs.Option_CVec_u8ZZ val) {
371 bindings.OpenChannel_set_shutdown_scriptpubkey(this.ptr, val.ptr);
372 Reference.reachabilityFence(this);
373 Reference.reachabilityFence(val);
374 if (this != null) { this.ptrs_to.add(val); };
378 * The channel type that this channel will represent
380 * If this is `None`, we derive the channel type from the intersection of our
381 * feature bits with our counterparty's feature bits from the [`Init`] message.
383 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
386 public ChannelTypeFeatures get_channel_type() {
387 long ret = bindings.OpenChannel_get_channel_type(this.ptr);
388 Reference.reachabilityFence(this);
389 if (ret >= 0 && ret <= 4096) { return null; }
390 org.ldk.structs.ChannelTypeFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelTypeFeatures(null, ret); }
391 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
396 * The channel type that this channel will represent
398 * If this is `None`, we derive the channel type from the intersection of our
399 * feature bits with our counterparty's feature bits from the [`Init`] message.
401 * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
403 public void set_channel_type(@Nullable org.ldk.structs.ChannelTypeFeatures val) {
404 bindings.OpenChannel_set_channel_type(this.ptr, val == null ? 0 : val.ptr);
405 Reference.reachabilityFence(this);
406 Reference.reachabilityFence(val);
407 if (this != null) { this.ptrs_to.add(val); };
411 * Constructs a new OpenChannel given each field
413 * Note that channel_type_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
415 public static OpenChannel of(byte[] chain_hash_arg, byte[] temporary_channel_id_arg, long funding_satoshis_arg, long push_msat_arg, long dust_limit_satoshis_arg, long max_htlc_value_in_flight_msat_arg, long channel_reserve_satoshis_arg, long htlc_minimum_msat_arg, int feerate_per_kw_arg, short to_self_delay_arg, short max_accepted_htlcs_arg, byte[] funding_pubkey_arg, byte[] revocation_basepoint_arg, byte[] payment_point_arg, byte[] delayed_payment_basepoint_arg, byte[] htlc_basepoint_arg, byte[] first_per_commitment_point_arg, byte channel_flags_arg, org.ldk.structs.Option_CVec_u8ZZ shutdown_scriptpubkey_arg, @Nullable org.ldk.structs.ChannelTypeFeatures channel_type_arg) {
416 long ret = bindings.OpenChannel_new(InternalUtils.check_arr_len(chain_hash_arg, 32), InternalUtils.check_arr_len(temporary_channel_id_arg, 32), funding_satoshis_arg, push_msat_arg, dust_limit_satoshis_arg, max_htlc_value_in_flight_msat_arg, channel_reserve_satoshis_arg, htlc_minimum_msat_arg, feerate_per_kw_arg, to_self_delay_arg, max_accepted_htlcs_arg, InternalUtils.check_arr_len(funding_pubkey_arg, 33), InternalUtils.check_arr_len(revocation_basepoint_arg, 33), InternalUtils.check_arr_len(payment_point_arg, 33), InternalUtils.check_arr_len(delayed_payment_basepoint_arg, 33), InternalUtils.check_arr_len(htlc_basepoint_arg, 33), InternalUtils.check_arr_len(first_per_commitment_point_arg, 33), channel_flags_arg, shutdown_scriptpubkey_arg.ptr, channel_type_arg == null ? 0 : channel_type_arg.ptr);
417 Reference.reachabilityFence(chain_hash_arg);
418 Reference.reachabilityFence(temporary_channel_id_arg);
419 Reference.reachabilityFence(funding_satoshis_arg);
420 Reference.reachabilityFence(push_msat_arg);
421 Reference.reachabilityFence(dust_limit_satoshis_arg);
422 Reference.reachabilityFence(max_htlc_value_in_flight_msat_arg);
423 Reference.reachabilityFence(channel_reserve_satoshis_arg);
424 Reference.reachabilityFence(htlc_minimum_msat_arg);
425 Reference.reachabilityFence(feerate_per_kw_arg);
426 Reference.reachabilityFence(to_self_delay_arg);
427 Reference.reachabilityFence(max_accepted_htlcs_arg);
428 Reference.reachabilityFence(funding_pubkey_arg);
429 Reference.reachabilityFence(revocation_basepoint_arg);
430 Reference.reachabilityFence(payment_point_arg);
431 Reference.reachabilityFence(delayed_payment_basepoint_arg);
432 Reference.reachabilityFence(htlc_basepoint_arg);
433 Reference.reachabilityFence(first_per_commitment_point_arg);
434 Reference.reachabilityFence(channel_flags_arg);
435 Reference.reachabilityFence(shutdown_scriptpubkey_arg);
436 Reference.reachabilityFence(channel_type_arg);
437 if (ret >= 0 && ret <= 4096) { return null; }
438 org.ldk.structs.OpenChannel ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OpenChannel(null, ret); }
439 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
440 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(shutdown_scriptpubkey_arg); };
441 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channel_type_arg); };
446 long ret = bindings.OpenChannel_clone_ptr(this.ptr);
447 Reference.reachabilityFence(this);
452 * Creates a copy of the OpenChannel
454 public OpenChannel clone() {
455 long ret = bindings.OpenChannel_clone(this.ptr);
456 Reference.reachabilityFence(this);
457 if (ret >= 0 && ret <= 4096) { return null; }
458 org.ldk.structs.OpenChannel ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OpenChannel(null, ret); }
459 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
464 * Checks if two OpenChannels contain equal inner contents.
465 * This ignores pointers and is_owned flags and looks at the values in fields.
466 * Two objects with NULL inner values will be considered "equal" here.
468 public boolean eq(org.ldk.structs.OpenChannel b) {
469 boolean ret = bindings.OpenChannel_eq(this.ptr, b == null ? 0 : b.ptr);
470 Reference.reachabilityFence(this);
471 Reference.reachabilityFence(b);
472 if (this != null) { this.ptrs_to.add(b); };
476 @Override public boolean equals(Object o) {
477 if (!(o instanceof OpenChannel)) return false;
478 return this.eq((OpenChannel)o);
481 * Serialize the OpenChannel object into a byte array which can be read by OpenChannel_read
483 public byte[] write() {
484 byte[] ret = bindings.OpenChannel_write(this.ptr);
485 Reference.reachabilityFence(this);
490 * Read a OpenChannel from a byte array, created by OpenChannel_write
492 public static Result_OpenChannelDecodeErrorZ read(byte[] ser) {
493 long ret = bindings.OpenChannel_read(ser);
494 Reference.reachabilityFence(ser);
495 if (ret >= 0 && ret <= 4096) { return null; }
496 Result_OpenChannelDecodeErrorZ ret_hu_conv = Result_OpenChannelDecodeErrorZ.constr_from_ptr(ret);