1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * Struct used to return values from revoke_and_ack messages, containing a bunch of commitment
13 * transaction updates if they were pending.
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 {
21 if (ptr != 0) { bindings.CommitmentUpdate_free(ptr); }
25 * update_add_htlc messages which should be sent
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;
37 return ret_conv_15_arr;
41 * update_add_htlc messages which should be sent
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);
50 * update_fulfill_htlc messages which should be sent
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;
62 return ret_conv_19_arr;
66 * update_fulfill_htlc messages which should be sent
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);
75 * update_fail_htlc messages which should be sent
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;
87 return ret_conv_16_arr;
91 * update_fail_htlc messages which should be sent
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);
100 * update_fail_malformed_htlc messages which should be sent
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;
112 return ret_conv_25_arr;
116 * update_fail_malformed_htlc messages which should be sent
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);
125 * An update_fee message which should be sent
127 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
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);
140 * An update_fee message which should be sent
142 * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
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);
151 * Finally, the commitment_signed message which should be sent
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);
163 * Finally, the commitment_signed message which should be sent
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);
172 * Constructs a new CommitmentUpdate given each field
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);
189 long ret = bindings.CommitmentUpdate_clone_ptr(this.ptr);
190 Reference.reachabilityFence(this);
195 * Creates a copy of the CommitmentUpdate
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);