[Java] Update auto-generated Java bindings to LDK 0.0.121
[ldk-java] / src / main / java / org / ldk / structs / CommitmentUpdate.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  * Struct used to return values from [`RevokeAndACK`] messages, containing a bunch of commitment
13  * transaction updates if they were pending.
14  */
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class CommitmentUpdate extends CommonBase {
17         CommitmentUpdate(Object _dummy, long ptr) { super(ptr); }
18         @Override @SuppressWarnings("deprecation")
19         protected void finalize() throws Throwable {
20                 super.finalize();
21                 if (ptr != 0) { bindings.CommitmentUpdate_free(ptr); }
22         }
23
24         /**
25          * `update_add_htlc` messages which should be sent
26          */
27         public UpdateAddHTLC[] get_update_add_htlcs() {
28                 long[] ret = bindings.CommitmentUpdate_get_update_add_htlcs(this.ptr);
29                 Reference.reachabilityFence(this);
30                 int ret_conv_15_len = ret.length;
31                 UpdateAddHTLC[] ret_conv_15_arr = new UpdateAddHTLC[ret_conv_15_len];
32                 for (int p = 0; p < ret_conv_15_len; p++) {
33                         long ret_conv_15 = ret[p];
34                         org.ldk.structs.UpdateAddHTLC ret_conv_15_hu_conv = null; if (ret_conv_15 < 0 || ret_conv_15 > 4096) { ret_conv_15_hu_conv = new org.ldk.structs.UpdateAddHTLC(null, ret_conv_15); }
35                         if (ret_conv_15_hu_conv != null) { ret_conv_15_hu_conv.ptrs_to.add(this); };
36                         ret_conv_15_arr[p] = ret_conv_15_hu_conv;
37                 }
38                 return ret_conv_15_arr;
39         }
40
41         /**
42          * `update_add_htlc` messages which should be sent
43          */
44         public void set_update_add_htlcs(UpdateAddHTLC[] val) {
45                 bindings.CommitmentUpdate_set_update_add_htlcs(this.ptr, val != null ? Arrays.stream(val).mapToLong(val_conv_15 -> val_conv_15 == null ? 0 : val_conv_15.ptr).toArray() : null);
46                 Reference.reachabilityFence(this);
47                 Reference.reachabilityFence(val);
48                 for (UpdateAddHTLC val_conv_15: val) { if (this != null) { this.ptrs_to.add(val_conv_15); }; };
49         }
50
51         /**
52          * `update_fulfill_htlc` messages which should be sent
53          */
54         public UpdateFulfillHTLC[] get_update_fulfill_htlcs() {
55                 long[] ret = bindings.CommitmentUpdate_get_update_fulfill_htlcs(this.ptr);
56                 Reference.reachabilityFence(this);
57                 int ret_conv_19_len = ret.length;
58                 UpdateFulfillHTLC[] ret_conv_19_arr = new UpdateFulfillHTLC[ret_conv_19_len];
59                 for (int t = 0; t < ret_conv_19_len; t++) {
60                         long ret_conv_19 = ret[t];
61                         org.ldk.structs.UpdateFulfillHTLC ret_conv_19_hu_conv = null; if (ret_conv_19 < 0 || ret_conv_19 > 4096) { ret_conv_19_hu_conv = new org.ldk.structs.UpdateFulfillHTLC(null, ret_conv_19); }
62                         if (ret_conv_19_hu_conv != null) { ret_conv_19_hu_conv.ptrs_to.add(this); };
63                         ret_conv_19_arr[t] = ret_conv_19_hu_conv;
64                 }
65                 return ret_conv_19_arr;
66         }
67
68         /**
69          * `update_fulfill_htlc` messages which should be sent
70          */
71         public void set_update_fulfill_htlcs(UpdateFulfillHTLC[] val) {
72                 bindings.CommitmentUpdate_set_update_fulfill_htlcs(this.ptr, val != null ? Arrays.stream(val).mapToLong(val_conv_19 -> val_conv_19 == null ? 0 : val_conv_19.ptr).toArray() : null);
73                 Reference.reachabilityFence(this);
74                 Reference.reachabilityFence(val);
75                 for (UpdateFulfillHTLC val_conv_19: val) { if (this != null) { this.ptrs_to.add(val_conv_19); }; };
76         }
77
78         /**
79          * `update_fail_htlc` messages which should be sent
80          */
81         public UpdateFailHTLC[] get_update_fail_htlcs() {
82                 long[] ret = bindings.CommitmentUpdate_get_update_fail_htlcs(this.ptr);
83                 Reference.reachabilityFence(this);
84                 int ret_conv_16_len = ret.length;
85                 UpdateFailHTLC[] ret_conv_16_arr = new UpdateFailHTLC[ret_conv_16_len];
86                 for (int q = 0; q < ret_conv_16_len; q++) {
87                         long ret_conv_16 = ret[q];
88                         org.ldk.structs.UpdateFailHTLC ret_conv_16_hu_conv = null; if (ret_conv_16 < 0 || ret_conv_16 > 4096) { ret_conv_16_hu_conv = new org.ldk.structs.UpdateFailHTLC(null, ret_conv_16); }
89                         if (ret_conv_16_hu_conv != null) { ret_conv_16_hu_conv.ptrs_to.add(this); };
90                         ret_conv_16_arr[q] = ret_conv_16_hu_conv;
91                 }
92                 return ret_conv_16_arr;
93         }
94
95         /**
96          * `update_fail_htlc` messages which should be sent
97          */
98         public void set_update_fail_htlcs(UpdateFailHTLC[] val) {
99                 bindings.CommitmentUpdate_set_update_fail_htlcs(this.ptr, val != null ? Arrays.stream(val).mapToLong(val_conv_16 -> val_conv_16 == null ? 0 : val_conv_16.ptr).toArray() : null);
100                 Reference.reachabilityFence(this);
101                 Reference.reachabilityFence(val);
102                 for (UpdateFailHTLC val_conv_16: val) { if (this != null) { this.ptrs_to.add(val_conv_16); }; };
103         }
104
105         /**
106          * `update_fail_malformed_htlc` messages which should be sent
107          */
108         public UpdateFailMalformedHTLC[] get_update_fail_malformed_htlcs() {
109                 long[] ret = bindings.CommitmentUpdate_get_update_fail_malformed_htlcs(this.ptr);
110                 Reference.reachabilityFence(this);
111                 int ret_conv_25_len = ret.length;
112                 UpdateFailMalformedHTLC[] ret_conv_25_arr = new UpdateFailMalformedHTLC[ret_conv_25_len];
113                 for (int z = 0; z < ret_conv_25_len; z++) {
114                         long ret_conv_25 = ret[z];
115                         org.ldk.structs.UpdateFailMalformedHTLC ret_conv_25_hu_conv = null; if (ret_conv_25 < 0 || ret_conv_25 > 4096) { ret_conv_25_hu_conv = new org.ldk.structs.UpdateFailMalformedHTLC(null, ret_conv_25); }
116                         if (ret_conv_25_hu_conv != null) { ret_conv_25_hu_conv.ptrs_to.add(this); };
117                         ret_conv_25_arr[z] = ret_conv_25_hu_conv;
118                 }
119                 return ret_conv_25_arr;
120         }
121
122         /**
123          * `update_fail_malformed_htlc` messages which should be sent
124          */
125         public void set_update_fail_malformed_htlcs(UpdateFailMalformedHTLC[] val) {
126                 bindings.CommitmentUpdate_set_update_fail_malformed_htlcs(this.ptr, val != null ? Arrays.stream(val).mapToLong(val_conv_25 -> val_conv_25 == null ? 0 : val_conv_25.ptr).toArray() : null);
127                 Reference.reachabilityFence(this);
128                 Reference.reachabilityFence(val);
129                 for (UpdateFailMalformedHTLC val_conv_25: val) { if (this != null) { this.ptrs_to.add(val_conv_25); }; };
130         }
131
132         /**
133          * An `update_fee` message which should be sent
134          * 
135          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
136          */
137         @Nullable
138         public UpdateFee get_update_fee() {
139                 long ret = bindings.CommitmentUpdate_get_update_fee(this.ptr);
140                 Reference.reachabilityFence(this);
141                 if (ret >= 0 && ret <= 4096) { return null; }
142                 org.ldk.structs.UpdateFee ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.UpdateFee(null, ret); }
143                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
144                 return ret_hu_conv;
145         }
146
147         /**
148          * An `update_fee` message which should be sent
149          * 
150          * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
151          */
152         public void set_update_fee(@Nullable org.ldk.structs.UpdateFee val) {
153                 bindings.CommitmentUpdate_set_update_fee(this.ptr, val == null ? 0 : val.ptr);
154                 Reference.reachabilityFence(this);
155                 Reference.reachabilityFence(val);
156                 if (this != null) { this.ptrs_to.add(val); };
157         }
158
159         /**
160          * A `commitment_signed` message which should be sent
161          */
162         public CommitmentSigned get_commitment_signed() {
163                 long ret = bindings.CommitmentUpdate_get_commitment_signed(this.ptr);
164                 Reference.reachabilityFence(this);
165                 if (ret >= 0 && ret <= 4096) { return null; }
166                 org.ldk.structs.CommitmentSigned ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.CommitmentSigned(null, ret); }
167                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
168                 return ret_hu_conv;
169         }
170
171         /**
172          * A `commitment_signed` message which should be sent
173          */
174         public void set_commitment_signed(org.ldk.structs.CommitmentSigned val) {
175                 bindings.CommitmentUpdate_set_commitment_signed(this.ptr, val == null ? 0 : val.ptr);
176                 Reference.reachabilityFence(this);
177                 Reference.reachabilityFence(val);
178                 if (this != null) { this.ptrs_to.add(val); };
179         }
180
181         /**
182          * Constructs a new CommitmentUpdate given each field
183          * 
184          * Note that update_fee_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
185          */
186         public static CommitmentUpdate of(UpdateAddHTLC[] update_add_htlcs_arg, UpdateFulfillHTLC[] update_fulfill_htlcs_arg, UpdateFailHTLC[] update_fail_htlcs_arg, UpdateFailMalformedHTLC[] update_fail_malformed_htlcs_arg, @Nullable org.ldk.structs.UpdateFee update_fee_arg, org.ldk.structs.CommitmentSigned commitment_signed_arg) {
187                 long ret = bindings.CommitmentUpdate_new(update_add_htlcs_arg != null ? Arrays.stream(update_add_htlcs_arg).mapToLong(update_add_htlcs_arg_conv_15 -> update_add_htlcs_arg_conv_15 == null ? 0 : update_add_htlcs_arg_conv_15.ptr).toArray() : null, update_fulfill_htlcs_arg != null ? Arrays.stream(update_fulfill_htlcs_arg).mapToLong(update_fulfill_htlcs_arg_conv_19 -> update_fulfill_htlcs_arg_conv_19 == null ? 0 : update_fulfill_htlcs_arg_conv_19.ptr).toArray() : null, update_fail_htlcs_arg != null ? Arrays.stream(update_fail_htlcs_arg).mapToLong(update_fail_htlcs_arg_conv_16 -> update_fail_htlcs_arg_conv_16 == null ? 0 : update_fail_htlcs_arg_conv_16.ptr).toArray() : null, update_fail_malformed_htlcs_arg != null ? Arrays.stream(update_fail_malformed_htlcs_arg).mapToLong(update_fail_malformed_htlcs_arg_conv_25 -> update_fail_malformed_htlcs_arg_conv_25 == null ? 0 : update_fail_malformed_htlcs_arg_conv_25.ptr).toArray() : null, update_fee_arg == null ? 0 : update_fee_arg.ptr, commitment_signed_arg == null ? 0 : commitment_signed_arg.ptr);
188                 Reference.reachabilityFence(update_add_htlcs_arg);
189                 Reference.reachabilityFence(update_fulfill_htlcs_arg);
190                 Reference.reachabilityFence(update_fail_htlcs_arg);
191                 Reference.reachabilityFence(update_fail_malformed_htlcs_arg);
192                 Reference.reachabilityFence(update_fee_arg);
193                 Reference.reachabilityFence(commitment_signed_arg);
194                 if (ret >= 0 && ret <= 4096) { return null; }
195                 org.ldk.structs.CommitmentUpdate ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.CommitmentUpdate(null, ret); }
196                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
197                 for (UpdateAddHTLC update_add_htlcs_arg_conv_15: update_add_htlcs_arg) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(update_add_htlcs_arg_conv_15); }; };
198                 for (UpdateFulfillHTLC update_fulfill_htlcs_arg_conv_19: update_fulfill_htlcs_arg) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(update_fulfill_htlcs_arg_conv_19); }; };
199                 for (UpdateFailHTLC update_fail_htlcs_arg_conv_16: update_fail_htlcs_arg) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(update_fail_htlcs_arg_conv_16); }; };
200                 for (UpdateFailMalformedHTLC update_fail_malformed_htlcs_arg_conv_25: update_fail_malformed_htlcs_arg) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(update_fail_malformed_htlcs_arg_conv_25); }; };
201                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(update_fee_arg); };
202                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(commitment_signed_arg); };
203                 return ret_hu_conv;
204         }
205
206         long clone_ptr() {
207                 long ret = bindings.CommitmentUpdate_clone_ptr(this.ptr);
208                 Reference.reachabilityFence(this);
209                 return ret;
210         }
211
212         /**
213          * Creates a copy of the CommitmentUpdate
214          */
215         public CommitmentUpdate clone() {
216                 long ret = bindings.CommitmentUpdate_clone(this.ptr);
217                 Reference.reachabilityFence(this);
218                 if (ret >= 0 && ret <= 4096) { return null; }
219                 org.ldk.structs.CommitmentUpdate ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.CommitmentUpdate(null, ret); }
220                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
221                 return ret_hu_conv;
222         }
223
224         /**
225          * Generates a non-cryptographic 64-bit hash of the CommitmentUpdate.
226          */
227         public long hash() {
228                 long ret = bindings.CommitmentUpdate_hash(this.ptr);
229                 Reference.reachabilityFence(this);
230                 return ret;
231         }
232
233         @Override public int hashCode() {
234                 return (int)this.hash();
235         }
236         /**
237          * Checks if two CommitmentUpdates contain equal inner contents.
238          * This ignores pointers and is_owned flags and looks at the values in fields.
239          * Two objects with NULL inner values will be considered "equal" here.
240          */
241         public boolean eq(org.ldk.structs.CommitmentUpdate b) {
242                 boolean ret = bindings.CommitmentUpdate_eq(this.ptr, b == null ? 0 : b.ptr);
243                 Reference.reachabilityFence(this);
244                 Reference.reachabilityFence(b);
245                 if (this != null) { this.ptrs_to.add(b); };
246                 return ret;
247         }
248
249         @Override public boolean equals(Object o) {
250                 if (!(o instanceof CommitmentUpdate)) return false;
251                 return this.eq((CommitmentUpdate)o);
252         }
253 }