6 namespace org { namespace ldk { namespace structs {
10 * A unique 32-byte identifier for a channel.
11 * Depending on how the ID is generated, several varieties are distinguished
12 * (but all are stored as 32 bytes):
13 * _v1_ and _temporary_.
14 * A _v1_ channel ID is generated based on funding tx outpoint (txid & index).
15 * A _temporary_ ID is generated randomly.
16 * (Later revocation-point-based _v2_ is a possibility.)
17 * The variety (context) is not stored, it is relevant only at creation.
19 public class ChannelId : CommonBase {
20 internal ChannelId(object _dummy, long ptr) : base(ptr) { }
22 if (ptr != 0) { bindings.ChannelId_free(ptr); }
25 public byte[] get_a() {
26 long ret = bindings.ChannelId_get_a(this.ptr);
28 if (ret >= 0 && ret <= 4096) { return null; }
29 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
33 public void set_a(byte[] val) {
34 bindings.ChannelId_set_a(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(val, 32)));
40 * Constructs a new ChannelId given each field
42 public static ChannelId of(byte[] a_arg) {
43 long ret = bindings.ChannelId_new(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(a_arg, 32)));
45 if (ret >= 0 && ret <= 4096) { return null; }
46 org.ldk.structs.ChannelId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelId(null, ret); }
47 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
51 internal long clone_ptr() {
52 long ret = bindings.ChannelId_clone_ptr(this.ptr);
58 * Creates a copy of the ChannelId
60 public ChannelId clone() {
61 long ret = bindings.ChannelId_clone(this.ptr);
63 if (ret >= 0 && ret <= 4096) { return null; }
64 org.ldk.structs.ChannelId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelId(null, ret); }
65 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
70 * Checks if two ChannelIds contain equal inner contents.
71 * This ignores pointers and is_owned flags and looks at the values in fields.
72 * Two objects with NULL inner values will be considered "equal" here.
74 public bool eq(org.ldk.structs.ChannelId b) {
75 bool ret = bindings.ChannelId_eq(this.ptr, b.ptr);
78 if (this != null) { this.ptrs_to.AddLast(b); };
82 public override bool Equals(object o) {
83 if (!(o is ChannelId)) return false;
84 return this.eq((ChannelId)o);
87 * Generates a non-cryptographic 64-bit hash of the ChannelId.
90 long ret = bindings.ChannelId_hash(this.ptr);
95 public override int GetHashCode() {
96 return (int)this.hash();
99 * Create _v1_ channel ID based on a funding TX ID and output index
101 public static ChannelId v1_from_funding_txid(byte[] txid, short output_index) {
102 long ret = bindings.ChannelId_v1_from_funding_txid(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(txid, 32)), output_index);
104 GC.KeepAlive(output_index);
105 if (ret >= 0 && ret <= 4096) { return null; }
106 org.ldk.structs.ChannelId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelId(null, ret); }
107 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
112 * Create _v1_ channel ID from a funding tx outpoint
114 public static ChannelId v1_from_funding_outpoint(org.ldk.structs.OutPoint outpoint) {
115 long ret = bindings.ChannelId_v1_from_funding_outpoint(outpoint.ptr);
116 GC.KeepAlive(outpoint);
117 if (ret >= 0 && ret <= 4096) { return null; }
118 org.ldk.structs.ChannelId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelId(null, ret); }
119 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
120 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(outpoint); };
125 * Create a _temporary_ channel ID randomly, based on an entropy source.
127 public static ChannelId temporary_from_entropy_source(org.ldk.structs.EntropySource entropy_source) {
128 long ret = bindings.ChannelId_temporary_from_entropy_source(entropy_source.ptr);
129 GC.KeepAlive(entropy_source);
130 if (ret >= 0 && ret <= 4096) { return null; }
131 org.ldk.structs.ChannelId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelId(null, ret); }
132 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
133 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(entropy_source); };
138 * Generic constructor; create a new channel ID from the provided data.
139 * Use a more specific `*_from_*` constructor when possible.
141 public static ChannelId from_bytes(byte[] data) {
142 long ret = bindings.ChannelId_from_bytes(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(data, 32)));
144 if (ret >= 0 && ret <= 4096) { return null; }
145 org.ldk.structs.ChannelId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelId(null, ret); }
146 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
151 * Create a channel ID consisting of all-zeros data (e.g. when uninitialized or a placeholder).
153 public static ChannelId new_zero() {
154 long ret = bindings.ChannelId_new_zero();
155 if (ret >= 0 && ret <= 4096) { return null; }
156 org.ldk.structs.ChannelId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelId(null, ret); }
157 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
162 * Check whether ID is consisting of all zeros (uninitialized)
164 public bool is_zero() {
165 bool ret = bindings.ChannelId_is_zero(this.ptr);
171 * Create _v2_ channel ID by concatenating the holder revocation basepoint with the counterparty
172 * revocation basepoint and hashing the result. The basepoints will be concatenated in increasing
175 public static ChannelId v2_from_revocation_basepoints(org.ldk.structs.RevocationBasepoint ours, org.ldk.structs.RevocationBasepoint theirs) {
176 long ret = bindings.ChannelId_v2_from_revocation_basepoints(ours.ptr, theirs.ptr);
178 GC.KeepAlive(theirs);
179 if (ret >= 0 && ret <= 4096) { return null; }
180 org.ldk.structs.ChannelId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelId(null, ret); }
181 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
182 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ours); };
183 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(theirs); };
188 * Create temporary _v2_ channel ID by concatenating a zeroed out basepoint with the holder
189 * revocation basepoint and hashing the result.
191 public static ChannelId temporary_v2_from_revocation_basepoint(org.ldk.structs.RevocationBasepoint our_revocation_basepoint) {
192 long ret = bindings.ChannelId_temporary_v2_from_revocation_basepoint(our_revocation_basepoint.ptr);
193 GC.KeepAlive(our_revocation_basepoint);
194 if (ret >= 0 && ret <= 4096) { return null; }
195 org.ldk.structs.ChannelId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelId(null, ret); }
196 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
197 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(our_revocation_basepoint); };
202 * Serialize the ChannelId object into a byte array which can be read by ChannelId_read
204 public byte[] write() {
205 long ret = bindings.ChannelId_write(this.ptr);
207 if (ret >= 0 && ret <= 4096) { return null; }
208 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
213 * Read a ChannelId from a byte array, created by ChannelId_write
215 public static Result_ChannelIdDecodeErrorZ read(byte[] ser) {
216 long ret = bindings.ChannelId_read(InternalUtils.encodeUint8Array(ser));
218 if (ret >= 0 && ret <= 4096) { return null; }
219 Result_ChannelIdDecodeErrorZ ret_hu_conv = Result_ChannelIdDecodeErrorZ.constr_from_ptr(ret);