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 * A unique 32-byte identifier for a channel.
13 * Depending on how the ID is generated, several varieties are distinguished
14 * (but all are stored as 32 bytes):
15 * _v1_ and _temporary_.
16 * A _v1_ channel ID is generated based on funding tx outpoint (txid & index).
17 * A _temporary_ ID is generated randomly.
18 * (Later revocation-point-based _v2_ is a possibility.)
19 * The variety (context) is not stored, it is relevant only at creation.
21 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
22 public class ChannelId extends CommonBase {
23 ChannelId(Object _dummy, long ptr) { super(ptr); }
24 @Override @SuppressWarnings("deprecation")
25 protected void finalize() throws Throwable {
27 if (ptr != 0) { bindings.ChannelId_free(ptr); }
30 public byte[] get_a() {
31 byte[] ret = bindings.ChannelId_get_a(this.ptr);
32 Reference.reachabilityFence(this);
36 public void set_a(byte[] val) {
37 bindings.ChannelId_set_a(this.ptr, InternalUtils.check_arr_len(val, 32));
38 Reference.reachabilityFence(this);
39 Reference.reachabilityFence(val);
43 * Constructs a new ChannelId given each field
45 public static ChannelId of(byte[] a_arg) {
46 long ret = bindings.ChannelId_new(InternalUtils.check_arr_len(a_arg, 32));
47 Reference.reachabilityFence(a_arg);
48 if (ret >= 0 && ret <= 4096) { return null; }
49 org.ldk.structs.ChannelId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelId(null, ret); }
50 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
55 long ret = bindings.ChannelId_clone_ptr(this.ptr);
56 Reference.reachabilityFence(this);
61 * Creates a copy of the ChannelId
63 public ChannelId clone() {
64 long ret = bindings.ChannelId_clone(this.ptr);
65 Reference.reachabilityFence(this);
66 if (ret >= 0 && ret <= 4096) { return null; }
67 org.ldk.structs.ChannelId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelId(null, ret); }
68 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
73 * Checks if two ChannelIds contain equal inner contents.
74 * This ignores pointers and is_owned flags and looks at the values in fields.
75 * Two objects with NULL inner values will be considered "equal" here.
77 public boolean eq(org.ldk.structs.ChannelId b) {
78 boolean ret = bindings.ChannelId_eq(this.ptr, b.ptr);
79 Reference.reachabilityFence(this);
80 Reference.reachabilityFence(b);
81 if (this != null) { this.ptrs_to.add(b); };
85 @Override public boolean equals(Object o) {
86 if (!(o instanceof ChannelId)) return false;
87 return this.eq((ChannelId)o);
90 * Generates a non-cryptographic 64-bit hash of the ChannelId.
93 long ret = bindings.ChannelId_hash(this.ptr);
94 Reference.reachabilityFence(this);
98 @Override public int hashCode() {
99 return (int)this.hash();
102 * Create _v1_ channel ID based on a funding TX ID and output index
104 public static ChannelId v1_from_funding_txid(byte[] txid, short output_index) {
105 long ret = bindings.ChannelId_v1_from_funding_txid(InternalUtils.check_arr_len(txid, 32), output_index);
106 Reference.reachabilityFence(txid);
107 Reference.reachabilityFence(output_index);
108 if (ret >= 0 && ret <= 4096) { return null; }
109 org.ldk.structs.ChannelId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelId(null, ret); }
110 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
115 * Create _v1_ channel ID from a funding tx outpoint
117 public static ChannelId v1_from_funding_outpoint(org.ldk.structs.OutPoint outpoint) {
118 long ret = bindings.ChannelId_v1_from_funding_outpoint(outpoint.ptr);
119 Reference.reachabilityFence(outpoint);
120 if (ret >= 0 && ret <= 4096) { return null; }
121 org.ldk.structs.ChannelId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelId(null, ret); }
122 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
123 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(outpoint); };
128 * Create a _temporary_ channel ID randomly, based on an entropy source.
130 public static ChannelId temporary_from_entropy_source(org.ldk.structs.EntropySource entropy_source) {
131 long ret = bindings.ChannelId_temporary_from_entropy_source(entropy_source.ptr);
132 Reference.reachabilityFence(entropy_source);
133 if (ret >= 0 && ret <= 4096) { return null; }
134 org.ldk.structs.ChannelId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelId(null, ret); }
135 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
136 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(entropy_source); };
141 * Generic constructor; create a new channel ID from the provided data.
142 * Use a more specific `*_from_*` constructor when possible.
144 public static ChannelId from_bytes(byte[] data) {
145 long ret = bindings.ChannelId_from_bytes(InternalUtils.check_arr_len(data, 32));
146 Reference.reachabilityFence(data);
147 if (ret >= 0 && ret <= 4096) { return null; }
148 org.ldk.structs.ChannelId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelId(null, ret); }
149 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
154 * Create a channel ID consisting of all-zeros data (e.g. when uninitialized or a placeholder).
156 public static ChannelId new_zero() {
157 long ret = bindings.ChannelId_new_zero();
158 if (ret >= 0 && ret <= 4096) { return null; }
159 org.ldk.structs.ChannelId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelId(null, ret); }
160 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
165 * Check whether ID is consisting of all zeros (uninitialized)
167 public boolean is_zero() {
168 boolean ret = bindings.ChannelId_is_zero(this.ptr);
169 Reference.reachabilityFence(this);
174 * Create _v2_ channel ID by concatenating the holder revocation basepoint with the counterparty
175 * revocation basepoint and hashing the result. The basepoints will be concatenated in increasing
178 public static ChannelId v2_from_revocation_basepoints(org.ldk.structs.RevocationBasepoint ours, org.ldk.structs.RevocationBasepoint theirs) {
179 long ret = bindings.ChannelId_v2_from_revocation_basepoints(ours.ptr, theirs.ptr);
180 Reference.reachabilityFence(ours);
181 Reference.reachabilityFence(theirs);
182 if (ret >= 0 && ret <= 4096) { return null; }
183 org.ldk.structs.ChannelId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelId(null, ret); }
184 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
185 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ours); };
186 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(theirs); };
191 * Create temporary _v2_ channel ID by concatenating a zeroed out basepoint with the holder
192 * revocation basepoint and hashing the result.
194 public static ChannelId temporary_v2_from_revocation_basepoint(org.ldk.structs.RevocationBasepoint our_revocation_basepoint) {
195 long ret = bindings.ChannelId_temporary_v2_from_revocation_basepoint(our_revocation_basepoint.ptr);
196 Reference.reachabilityFence(our_revocation_basepoint);
197 if (ret >= 0 && ret <= 4096) { return null; }
198 org.ldk.structs.ChannelId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelId(null, ret); }
199 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
200 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(our_revocation_basepoint); };
205 * Serialize the ChannelId object into a byte array which can be read by ChannelId_read
207 public byte[] write() {
208 byte[] ret = bindings.ChannelId_write(this.ptr);
209 Reference.reachabilityFence(this);
214 * Read a ChannelId from a byte array, created by ChannelId_write
216 public static Result_ChannelIdDecodeErrorZ read(byte[] ser) {
217 long ret = bindings.ChannelId_read(ser);
218 Reference.reachabilityFence(ser);
219 if (ret >= 0 && ret <= 4096) { return null; }
220 Result_ChannelIdDecodeErrorZ ret_hu_conv = Result_ChannelIdDecodeErrorZ.constr_from_ptr(ret);