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 [`accept_channel`] message to be sent to or received from a peer.
14 * Used in V1 channel establishment
16 * [`accept_channel`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-accept_channel-message
18 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
19 public class AcceptChannel extends CommonBase {
20 AcceptChannel(Object _dummy, long ptr) { super(ptr); }
21 @Override @SuppressWarnings("deprecation")
22 protected void finalize() throws Throwable {
24 if (ptr != 0) { bindings.AcceptChannel_free(ptr); }
28 * Common fields of `accept_channel(2)`-like messages
30 public CommonAcceptChannelFields get_common_fields() {
31 long ret = bindings.AcceptChannel_get_common_fields(this.ptr);
32 Reference.reachabilityFence(this);
33 if (ret >= 0 && ret <= 4096) { return null; }
34 org.ldk.structs.CommonAcceptChannelFields ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.CommonAcceptChannelFields(null, ret); }
35 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
40 * Common fields of `accept_channel(2)`-like messages
42 public void set_common_fields(org.ldk.structs.CommonAcceptChannelFields val) {
43 bindings.AcceptChannel_set_common_fields(this.ptr, val.ptr);
44 Reference.reachabilityFence(this);
45 Reference.reachabilityFence(val);
46 if (this != null) { this.ptrs_to.add(val); };
50 * The minimum value unencumbered by HTLCs for the counterparty to keep in the channel
52 public long get_channel_reserve_satoshis() {
53 long ret = bindings.AcceptChannel_get_channel_reserve_satoshis(this.ptr);
54 Reference.reachabilityFence(this);
59 * The minimum value unencumbered by HTLCs for the counterparty to keep in the channel
61 public void set_channel_reserve_satoshis(long val) {
62 bindings.AcceptChannel_set_channel_reserve_satoshis(this.ptr, val);
63 Reference.reachabilityFence(this);
64 Reference.reachabilityFence(val);
68 * Constructs a new AcceptChannel given each field
70 public static AcceptChannel of(org.ldk.structs.CommonAcceptChannelFields common_fields_arg, long channel_reserve_satoshis_arg) {
71 long ret = bindings.AcceptChannel_new(common_fields_arg.ptr, channel_reserve_satoshis_arg);
72 Reference.reachabilityFence(common_fields_arg);
73 Reference.reachabilityFence(channel_reserve_satoshis_arg);
74 if (ret >= 0 && ret <= 4096) { return null; }
75 org.ldk.structs.AcceptChannel ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.AcceptChannel(null, ret); }
76 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
77 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(common_fields_arg); };
82 long ret = bindings.AcceptChannel_clone_ptr(this.ptr);
83 Reference.reachabilityFence(this);
88 * Creates a copy of the AcceptChannel
90 public AcceptChannel clone() {
91 long ret = bindings.AcceptChannel_clone(this.ptr);
92 Reference.reachabilityFence(this);
93 if (ret >= 0 && ret <= 4096) { return null; }
94 org.ldk.structs.AcceptChannel ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.AcceptChannel(null, ret); }
95 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
100 * Generates a non-cryptographic 64-bit hash of the AcceptChannel.
103 long ret = bindings.AcceptChannel_hash(this.ptr);
104 Reference.reachabilityFence(this);
108 @Override public int hashCode() {
109 return (int)this.hash();
112 * Checks if two AcceptChannels contain equal inner contents.
113 * This ignores pointers and is_owned flags and looks at the values in fields.
114 * Two objects with NULL inner values will be considered "equal" here.
116 public boolean eq(org.ldk.structs.AcceptChannel b) {
117 boolean ret = bindings.AcceptChannel_eq(this.ptr, b.ptr);
118 Reference.reachabilityFence(this);
119 Reference.reachabilityFence(b);
120 if (this != null) { this.ptrs_to.add(b); };
124 @Override public boolean equals(Object o) {
125 if (!(o instanceof AcceptChannel)) return false;
126 return this.eq((AcceptChannel)o);
129 * Serialize the AcceptChannel object into a byte array which can be read by AcceptChannel_read
131 public byte[] write() {
132 byte[] ret = bindings.AcceptChannel_write(this.ptr);
133 Reference.reachabilityFence(this);
138 * Read a AcceptChannel from a byte array, created by AcceptChannel_write
140 public static Result_AcceptChannelDecodeErrorZ read(byte[] ser) {
141 long ret = bindings.AcceptChannel_read(ser);
142 Reference.reachabilityFence(ser);
143 if (ret >= 0 && ret <= 4096) { return null; }
144 Result_AcceptChannelDecodeErrorZ ret_hu_conv = Result_AcceptChannelDecodeErrorZ.constr_from_ptr(ret);