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 * Common fields of `open_channel(2)`-like messages
30 public CommonOpenChannelFields get_common_fields() {
31 long ret = bindings.OpenChannel_get_common_fields(this.ptr);
32 Reference.reachabilityFence(this);
33 if (ret >= 0 && ret <= 4096) { return null; }
34 org.ldk.structs.CommonOpenChannelFields ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.CommonOpenChannelFields(null, ret); }
35 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
40 * Common fields of `open_channel(2)`-like messages
42 public void set_common_fields(org.ldk.structs.CommonOpenChannelFields val) {
43 bindings.OpenChannel_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 amount to push to the counterparty as part of the open, in milli-satoshi
52 public long get_push_msat() {
53 long ret = bindings.OpenChannel_get_push_msat(this.ptr);
54 Reference.reachabilityFence(this);
59 * The amount to push to the counterparty as part of the open, in milli-satoshi
61 public void set_push_msat(long val) {
62 bindings.OpenChannel_set_push_msat(this.ptr, val);
63 Reference.reachabilityFence(this);
64 Reference.reachabilityFence(val);
68 * The minimum value unencumbered by HTLCs for the counterparty to keep in the channel
70 public long get_channel_reserve_satoshis() {
71 long ret = bindings.OpenChannel_get_channel_reserve_satoshis(this.ptr);
72 Reference.reachabilityFence(this);
77 * The minimum value unencumbered by HTLCs for the counterparty to keep in the channel
79 public void set_channel_reserve_satoshis(long val) {
80 bindings.OpenChannel_set_channel_reserve_satoshis(this.ptr, val);
81 Reference.reachabilityFence(this);
82 Reference.reachabilityFence(val);
86 * Constructs a new OpenChannel given each field
88 public static OpenChannel of(org.ldk.structs.CommonOpenChannelFields common_fields_arg, long push_msat_arg, long channel_reserve_satoshis_arg) {
89 long ret = bindings.OpenChannel_new(common_fields_arg.ptr, push_msat_arg, channel_reserve_satoshis_arg);
90 Reference.reachabilityFence(common_fields_arg);
91 Reference.reachabilityFence(push_msat_arg);
92 Reference.reachabilityFence(channel_reserve_satoshis_arg);
93 if (ret >= 0 && ret <= 4096) { return null; }
94 org.ldk.structs.OpenChannel ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OpenChannel(null, ret); }
95 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
96 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(common_fields_arg); };
101 long ret = bindings.OpenChannel_clone_ptr(this.ptr);
102 Reference.reachabilityFence(this);
107 * Creates a copy of the OpenChannel
109 public OpenChannel clone() {
110 long ret = bindings.OpenChannel_clone(this.ptr);
111 Reference.reachabilityFence(this);
112 if (ret >= 0 && ret <= 4096) { return null; }
113 org.ldk.structs.OpenChannel ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OpenChannel(null, ret); }
114 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
119 * Generates a non-cryptographic 64-bit hash of the OpenChannel.
122 long ret = bindings.OpenChannel_hash(this.ptr);
123 Reference.reachabilityFence(this);
127 @Override public int hashCode() {
128 return (int)this.hash();
131 * Checks if two OpenChannels contain equal inner contents.
132 * This ignores pointers and is_owned flags and looks at the values in fields.
133 * Two objects with NULL inner values will be considered "equal" here.
135 public boolean eq(org.ldk.structs.OpenChannel b) {
136 boolean ret = bindings.OpenChannel_eq(this.ptr, b.ptr);
137 Reference.reachabilityFence(this);
138 Reference.reachabilityFence(b);
139 if (this != null) { this.ptrs_to.add(b); };
143 @Override public boolean equals(Object o) {
144 if (!(o instanceof OpenChannel)) return false;
145 return this.eq((OpenChannel)o);
148 * Serialize the OpenChannel object into a byte array which can be read by OpenChannel_read
150 public byte[] write() {
151 byte[] ret = bindings.OpenChannel_write(this.ptr);
152 Reference.reachabilityFence(this);
157 * Read a OpenChannel from a byte array, created by OpenChannel_write
159 public static Result_OpenChannelDecodeErrorZ read(byte[] ser) {
160 long ret = bindings.OpenChannel_read(ser);
161 Reference.reachabilityFence(ser);
162 if (ret >= 0 && ret <= 4096) { return null; }
163 Result_OpenChannelDecodeErrorZ ret_hu_conv = Result_OpenChannelDecodeErrorZ.constr_from_ptr(ret);