[Java] Update auto-generated bindings to LDK 0.0.123
[ldk-java] / src / main / java / org / ldk / structs / ChannelId.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10
11 /**
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.
20  */
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 {
26                 super.finalize();
27                 if (ptr != 0) { bindings.ChannelId_free(ptr); }
28         }
29
30         public byte[] get_a() {
31                 byte[] ret = bindings.ChannelId_get_a(this.ptr);
32                 Reference.reachabilityFence(this);
33                 return ret;
34         }
35
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);
40         }
41
42         /**
43          * Constructs a new ChannelId given each field
44          */
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); };
51                 return ret_hu_conv;
52         }
53
54         long clone_ptr() {
55                 long ret = bindings.ChannelId_clone_ptr(this.ptr);
56                 Reference.reachabilityFence(this);
57                 return ret;
58         }
59
60         /**
61          * Creates a copy of the ChannelId
62          */
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); };
69                 return ret_hu_conv;
70         }
71
72         /**
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.
76          */
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); };
82                 return ret;
83         }
84
85         @Override public boolean equals(Object o) {
86                 if (!(o instanceof ChannelId)) return false;
87                 return this.eq((ChannelId)o);
88         }
89         /**
90          * Generates a non-cryptographic 64-bit hash of the ChannelId.
91          */
92         public long hash() {
93                 long ret = bindings.ChannelId_hash(this.ptr);
94                 Reference.reachabilityFence(this);
95                 return ret;
96         }
97
98         @Override public int hashCode() {
99                 return (int)this.hash();
100         }
101         /**
102          * Create _v1_ channel ID based on a funding TX ID and output index
103          */
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); };
111                 return ret_hu_conv;
112         }
113
114         /**
115          * Create _v1_ channel ID from a funding tx outpoint
116          */
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); };
124                 return ret_hu_conv;
125         }
126
127         /**
128          * Create a _temporary_ channel ID randomly, based on an entropy source.
129          */
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); };
137                 return ret_hu_conv;
138         }
139
140         /**
141          * Generic constructor; create a new channel ID from the provided data.
142          * Use a more specific `*_from_*` constructor when possible.
143          */
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); };
150                 return ret_hu_conv;
151         }
152
153         /**
154          * Create a channel ID consisting of all-zeros data (e.g. when uninitialized or a placeholder).
155          */
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); };
161                 return ret_hu_conv;
162         }
163
164         /**
165          * Check whether ID is consisting of all zeros (uninitialized)
166          */
167         public boolean is_zero() {
168                 boolean ret = bindings.ChannelId_is_zero(this.ptr);
169                 Reference.reachabilityFence(this);
170                 return ret;
171         }
172
173         /**
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
176          * sorted order.
177          */
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); };
187                 return ret_hu_conv;
188         }
189
190         /**
191          * Create temporary _v2_ channel ID by concatenating a zeroed out basepoint with the holder
192          * revocation basepoint and hashing the result.
193          */
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); };
201                 return ret_hu_conv;
202         }
203
204         /**
205          * Serialize the ChannelId object into a byte array which can be read by ChannelId_read
206          */
207         public byte[] write() {
208                 byte[] ret = bindings.ChannelId_write(this.ptr);
209                 Reference.reachabilityFence(this);
210                 return ret;
211         }
212
213         /**
214          * Read a ChannelId from a byte array, created by ChannelId_write
215          */
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);
221                 return ret_hu_conv;
222         }
223
224 }