Merge pull request #45 from TheBlueMatt/main
[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 javax.annotation.Nullable;
8
9
10 /**
11  * Struct used to return values from revoke_and_ack messages, containing a bunch of commitment
12  * transaction updates if they were pending.
13  */
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class CommitmentUpdate extends CommonBase {
16         CommitmentUpdate(Object _dummy, long ptr) { super(ptr); }
17         @Override @SuppressWarnings("deprecation")
18         protected void finalize() throws Throwable {
19                 super.finalize();
20                 if (ptr != 0) { bindings.CommitmentUpdate_free(ptr); }
21         }
22
23         /**
24          * update_add_htlc messages which should be sent
25          */
26         public UpdateAddHTLC[] get_update_add_htlcs() {
27                 long[] ret = bindings.CommitmentUpdate_get_update_add_htlcs(this.ptr);
28                 UpdateAddHTLC[] ret_conv_15_arr = new UpdateAddHTLC[ret.length];
29                 for (int p = 0; p < ret.length; p++) {
30                         long ret_conv_15 = ret[p];
31                         UpdateAddHTLC ret_conv_15_hu_conv = new UpdateAddHTLC(null, ret_conv_15);
32                         ret_conv_15_hu_conv.ptrs_to.add(this);
33                         ret_conv_15_arr[p] = ret_conv_15_hu_conv;
34                 }
35                 return ret_conv_15_arr;
36         }
37
38         /**
39          * update_add_htlc messages which should be sent
40          */
41         public void set_update_add_htlcs(UpdateAddHTLC[] val) {
42                 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);
43                 for (UpdateAddHTLC val_conv_15: val) { this.ptrs_to.add(val_conv_15); };
44         }
45
46         /**
47          * update_fulfill_htlc messages which should be sent
48          */
49         public UpdateFulfillHTLC[] get_update_fulfill_htlcs() {
50                 long[] ret = bindings.CommitmentUpdate_get_update_fulfill_htlcs(this.ptr);
51                 UpdateFulfillHTLC[] ret_conv_19_arr = new UpdateFulfillHTLC[ret.length];
52                 for (int t = 0; t < ret.length; t++) {
53                         long ret_conv_19 = ret[t];
54                         UpdateFulfillHTLC ret_conv_19_hu_conv = new UpdateFulfillHTLC(null, ret_conv_19);
55                         ret_conv_19_hu_conv.ptrs_to.add(this);
56                         ret_conv_19_arr[t] = ret_conv_19_hu_conv;
57                 }
58                 return ret_conv_19_arr;
59         }
60
61         /**
62          * update_fulfill_htlc messages which should be sent
63          */
64         public void set_update_fulfill_htlcs(UpdateFulfillHTLC[] val) {
65                 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);
66                 for (UpdateFulfillHTLC val_conv_19: val) { this.ptrs_to.add(val_conv_19); };
67         }
68
69         /**
70          * update_fail_htlc messages which should be sent
71          */
72         public UpdateFailHTLC[] get_update_fail_htlcs() {
73                 long[] ret = bindings.CommitmentUpdate_get_update_fail_htlcs(this.ptr);
74                 UpdateFailHTLC[] ret_conv_16_arr = new UpdateFailHTLC[ret.length];
75                 for (int q = 0; q < ret.length; q++) {
76                         long ret_conv_16 = ret[q];
77                         UpdateFailHTLC ret_conv_16_hu_conv = new UpdateFailHTLC(null, ret_conv_16);
78                         ret_conv_16_hu_conv.ptrs_to.add(this);
79                         ret_conv_16_arr[q] = ret_conv_16_hu_conv;
80                 }
81                 return ret_conv_16_arr;
82         }
83
84         /**
85          * update_fail_htlc messages which should be sent
86          */
87         public void set_update_fail_htlcs(UpdateFailHTLC[] val) {
88                 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);
89                 for (UpdateFailHTLC val_conv_16: val) { this.ptrs_to.add(val_conv_16); };
90         }
91
92         /**
93          * update_fail_malformed_htlc messages which should be sent
94          */
95         public UpdateFailMalformedHTLC[] get_update_fail_malformed_htlcs() {
96                 long[] ret = bindings.CommitmentUpdate_get_update_fail_malformed_htlcs(this.ptr);
97                 UpdateFailMalformedHTLC[] ret_conv_25_arr = new UpdateFailMalformedHTLC[ret.length];
98                 for (int z = 0; z < ret.length; z++) {
99                         long ret_conv_25 = ret[z];
100                         UpdateFailMalformedHTLC ret_conv_25_hu_conv = new UpdateFailMalformedHTLC(null, ret_conv_25);
101                         ret_conv_25_hu_conv.ptrs_to.add(this);
102                         ret_conv_25_arr[z] = ret_conv_25_hu_conv;
103                 }
104                 return ret_conv_25_arr;
105         }
106
107         /**
108          * update_fail_malformed_htlc messages which should be sent
109          */
110         public void set_update_fail_malformed_htlcs(UpdateFailMalformedHTLC[] val) {
111                 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);
112                 for (UpdateFailMalformedHTLC val_conv_25: val) { this.ptrs_to.add(val_conv_25); };
113         }
114
115         /**
116          * An update_fee message which should be sent
117          * 
118          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
119          */
120         @Nullable
121         public UpdateFee get_update_fee() {
122                 long ret = bindings.CommitmentUpdate_get_update_fee(this.ptr);
123                 if (ret < 1024) { return null; }
124                 UpdateFee ret_hu_conv = new UpdateFee(null, ret);
125                 ret_hu_conv.ptrs_to.add(this);
126                 return ret_hu_conv;
127         }
128
129         /**
130          * An update_fee message which should be sent
131          * 
132          * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
133          */
134         public void set_update_fee(@Nullable UpdateFee val) {
135                 bindings.CommitmentUpdate_set_update_fee(this.ptr, val == null ? 0 : val.ptr & ~1);
136                 this.ptrs_to.add(val);
137         }
138
139         /**
140          * Finally, the commitment_signed message which should be sent
141          */
142         public CommitmentSigned get_commitment_signed() {
143                 long ret = bindings.CommitmentUpdate_get_commitment_signed(this.ptr);
144                 if (ret < 1024) { return null; }
145                 CommitmentSigned ret_hu_conv = new CommitmentSigned(null, ret);
146                 ret_hu_conv.ptrs_to.add(this);
147                 return ret_hu_conv;
148         }
149
150         /**
151          * Finally, the commitment_signed message which should be sent
152          */
153         public void set_commitment_signed(CommitmentSigned val) {
154                 bindings.CommitmentUpdate_set_commitment_signed(this.ptr, val == null ? 0 : val.ptr & ~1);
155                 this.ptrs_to.add(val);
156         }
157
158         /**
159          * Constructs a new CommitmentUpdate given each field
160          */
161         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) {
162                 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);
163                 if (ret < 1024) { return null; }
164                 CommitmentUpdate ret_hu_conv = new CommitmentUpdate(null, ret);
165                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
166                 for (UpdateAddHTLC update_add_htlcs_arg_conv_15: update_add_htlcs_arg) { ret_hu_conv.ptrs_to.add(update_add_htlcs_arg_conv_15); };
167                 for (UpdateFulfillHTLC update_fulfill_htlcs_arg_conv_19: update_fulfill_htlcs_arg) { ret_hu_conv.ptrs_to.add(update_fulfill_htlcs_arg_conv_19); };
168                 for (UpdateFailHTLC update_fail_htlcs_arg_conv_16: update_fail_htlcs_arg) { ret_hu_conv.ptrs_to.add(update_fail_htlcs_arg_conv_16); };
169                 for (UpdateFailMalformedHTLC update_fail_malformed_htlcs_arg_conv_25: update_fail_malformed_htlcs_arg) { ret_hu_conv.ptrs_to.add(update_fail_malformed_htlcs_arg_conv_25); };
170                 ret_hu_conv.ptrs_to.add(update_fee_arg);
171                 ret_hu_conv.ptrs_to.add(commitment_signed_arg);
172                 return ret_hu_conv;
173         }
174
175         /**
176          * Creates a copy of the CommitmentUpdate
177          */
178         public CommitmentUpdate clone() {
179                 long ret = bindings.CommitmentUpdate_clone(this.ptr);
180                 if (ret < 1024) { return null; }
181                 CommitmentUpdate ret_hu_conv = new CommitmentUpdate(null, ret);
182                 ret_hu_conv.ptrs_to.add(this);
183                 return ret_hu_conv;
184         }
185
186 }