6a32283415af188a720835deaca0b6a1a2a9d8c1
[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 revoke_and_ack 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                 UpdateAddHTLC[] ret_conv_15_arr = new UpdateAddHTLC[ret.length];
31                 for (int p = 0; p < ret.length; p++) {
32                         long ret_conv_15 = ret[p];
33                         UpdateAddHTLC ret_conv_15_hu_conv = null; if (ret_conv_15 < 0 || ret_conv_15 > 4096) { ret_conv_15_hu_conv = new UpdateAddHTLC(null, ret_conv_15); }
34                         ret_conv_15_hu_conv.ptrs_to.add(this);
35                         ret_conv_15_arr[p] = ret_conv_15_hu_conv;
36                 }
37                 return ret_conv_15_arr;
38         }
39
40         /**
41          * update_add_htlc messages which should be sent
42          */
43         public void set_update_add_htlcs(UpdateAddHTLC[] val) {
44                 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 & ~1).toArray() : null);
45                 Reference.reachabilityFence(this);
46                 Reference.reachabilityFence(val);
47         }
48
49         /**
50          * update_fulfill_htlc messages which should be sent
51          */
52         public UpdateFulfillHTLC[] get_update_fulfill_htlcs() {
53                 long[] ret = bindings.CommitmentUpdate_get_update_fulfill_htlcs(this.ptr);
54                 Reference.reachabilityFence(this);
55                 UpdateFulfillHTLC[] ret_conv_19_arr = new UpdateFulfillHTLC[ret.length];
56                 for (int t = 0; t < ret.length; t++) {
57                         long ret_conv_19 = ret[t];
58                         UpdateFulfillHTLC ret_conv_19_hu_conv = null; if (ret_conv_19 < 0 || ret_conv_19 > 4096) { ret_conv_19_hu_conv = new UpdateFulfillHTLC(null, ret_conv_19); }
59                         ret_conv_19_hu_conv.ptrs_to.add(this);
60                         ret_conv_19_arr[t] = ret_conv_19_hu_conv;
61                 }
62                 return ret_conv_19_arr;
63         }
64
65         /**
66          * update_fulfill_htlc messages which should be sent
67          */
68         public void set_update_fulfill_htlcs(UpdateFulfillHTLC[] val) {
69                 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 & ~1).toArray() : null);
70                 Reference.reachabilityFence(this);
71                 Reference.reachabilityFence(val);
72         }
73
74         /**
75          * update_fail_htlc messages which should be sent
76          */
77         public UpdateFailHTLC[] get_update_fail_htlcs() {
78                 long[] ret = bindings.CommitmentUpdate_get_update_fail_htlcs(this.ptr);
79                 Reference.reachabilityFence(this);
80                 UpdateFailHTLC[] ret_conv_16_arr = new UpdateFailHTLC[ret.length];
81                 for (int q = 0; q < ret.length; q++) {
82                         long ret_conv_16 = ret[q];
83                         UpdateFailHTLC ret_conv_16_hu_conv = null; if (ret_conv_16 < 0 || ret_conv_16 > 4096) { ret_conv_16_hu_conv = new UpdateFailHTLC(null, ret_conv_16); }
84                         ret_conv_16_hu_conv.ptrs_to.add(this);
85                         ret_conv_16_arr[q] = ret_conv_16_hu_conv;
86                 }
87                 return ret_conv_16_arr;
88         }
89
90         /**
91          * update_fail_htlc messages which should be sent
92          */
93         public void set_update_fail_htlcs(UpdateFailHTLC[] val) {
94                 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 & ~1).toArray() : null);
95                 Reference.reachabilityFence(this);
96                 Reference.reachabilityFence(val);
97         }
98
99         /**
100          * update_fail_malformed_htlc messages which should be sent
101          */
102         public UpdateFailMalformedHTLC[] get_update_fail_malformed_htlcs() {
103                 long[] ret = bindings.CommitmentUpdate_get_update_fail_malformed_htlcs(this.ptr);
104                 Reference.reachabilityFence(this);
105                 UpdateFailMalformedHTLC[] ret_conv_25_arr = new UpdateFailMalformedHTLC[ret.length];
106                 for (int z = 0; z < ret.length; z++) {
107                         long ret_conv_25 = ret[z];
108                         UpdateFailMalformedHTLC ret_conv_25_hu_conv = null; if (ret_conv_25 < 0 || ret_conv_25 > 4096) { ret_conv_25_hu_conv = new UpdateFailMalformedHTLC(null, ret_conv_25); }
109                         ret_conv_25_hu_conv.ptrs_to.add(this);
110                         ret_conv_25_arr[z] = ret_conv_25_hu_conv;
111                 }
112                 return ret_conv_25_arr;
113         }
114
115         /**
116          * update_fail_malformed_htlc messages which should be sent
117          */
118         public void set_update_fail_malformed_htlcs(UpdateFailMalformedHTLC[] val) {
119                 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 & ~1).toArray() : null);
120                 Reference.reachabilityFence(this);
121                 Reference.reachabilityFence(val);
122         }
123
124         /**
125          * An update_fee message which should be sent
126          * 
127          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
128          */
129         @Nullable
130         public UpdateFee get_update_fee() {
131                 long ret = bindings.CommitmentUpdate_get_update_fee(this.ptr);
132                 Reference.reachabilityFence(this);
133                 if (ret >= 0 && ret <= 4096) { return null; }
134                 UpdateFee ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new UpdateFee(null, ret); }
135                 ret_hu_conv.ptrs_to.add(this);
136                 return ret_hu_conv;
137         }
138
139         /**
140          * An update_fee message which should be sent
141          * 
142          * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
143          */
144         public void set_update_fee(@Nullable UpdateFee val) {
145                 bindings.CommitmentUpdate_set_update_fee(this.ptr, val == null ? 0 : val.ptr & ~1);
146                 Reference.reachabilityFence(this);
147                 Reference.reachabilityFence(val);
148         }
149
150         /**
151          * Finally, the commitment_signed message which should be sent
152          */
153         public CommitmentSigned get_commitment_signed() {
154                 long ret = bindings.CommitmentUpdate_get_commitment_signed(this.ptr);
155                 Reference.reachabilityFence(this);
156                 if (ret >= 0 && ret <= 4096) { return null; }
157                 CommitmentSigned ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new CommitmentSigned(null, ret); }
158                 ret_hu_conv.ptrs_to.add(this);
159                 return ret_hu_conv;
160         }
161
162         /**
163          * Finally, the commitment_signed message which should be sent
164          */
165         public void set_commitment_signed(CommitmentSigned val) {
166                 bindings.CommitmentUpdate_set_commitment_signed(this.ptr, val == null ? 0 : val.ptr & ~1);
167                 Reference.reachabilityFence(this);
168                 Reference.reachabilityFence(val);
169         }
170
171         /**
172          * Constructs a new CommitmentUpdate given each field
173          */
174         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, UpdateFee update_fee_arg, CommitmentSigned commitment_signed_arg) {
175                 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 & ~1).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 & ~1).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 & ~1).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 & ~1).toArray() : null, update_fee_arg == null ? 0 : update_fee_arg.ptr & ~1, commitment_signed_arg == null ? 0 : commitment_signed_arg.ptr & ~1);
176                 Reference.reachabilityFence(update_add_htlcs_arg);
177                 Reference.reachabilityFence(update_fulfill_htlcs_arg);
178                 Reference.reachabilityFence(update_fail_htlcs_arg);
179                 Reference.reachabilityFence(update_fail_malformed_htlcs_arg);
180                 Reference.reachabilityFence(update_fee_arg);
181                 Reference.reachabilityFence(commitment_signed_arg);
182                 if (ret >= 0 && ret <= 4096) { return null; }
183                 CommitmentUpdate ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new CommitmentUpdate(null, ret); }
184                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
185                 return ret_hu_conv;
186         }
187
188         long clone_ptr() {
189                 long ret = bindings.CommitmentUpdate_clone_ptr(this.ptr);
190                 Reference.reachabilityFence(this);
191                 return ret;
192         }
193
194         /**
195          * Creates a copy of the CommitmentUpdate
196          */
197         public CommitmentUpdate clone() {
198                 long ret = bindings.CommitmentUpdate_clone(this.ptr);
199                 Reference.reachabilityFence(this);
200                 if (ret >= 0 && ret <= 4096) { return null; }
201                 CommitmentUpdate ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new CommitmentUpdate(null, ret); }
202                 ret_hu_conv.ptrs_to.add(this);
203                 return ret_hu_conv;
204         }
205
206 }