1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
11 * Struct used to return values from revoke_and_ack messages, containing a bunch of commitment
12 * transaction updates if they were pending.
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 {
20 if (ptr != 0) { bindings.CommitmentUpdate_free(ptr); }
24 * update_add_htlc messages which should be sent
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 = null; if (ret_conv_15 < 0 || ret_conv_15 > 4096) { 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;
35 return ret_conv_15_arr;
39 * update_add_htlc messages which should be sent
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);
46 * update_fulfill_htlc messages which should be sent
48 public UpdateFulfillHTLC[] get_update_fulfill_htlcs() {
49 long[] ret = bindings.CommitmentUpdate_get_update_fulfill_htlcs(this.ptr);
50 UpdateFulfillHTLC[] ret_conv_19_arr = new UpdateFulfillHTLC[ret.length];
51 for (int t = 0; t < ret.length; t++) {
52 long ret_conv_19 = ret[t];
53 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); }
54 ret_conv_19_hu_conv.ptrs_to.add(this);
55 ret_conv_19_arr[t] = ret_conv_19_hu_conv;
57 return ret_conv_19_arr;
61 * update_fulfill_htlc messages which should be sent
63 public void set_update_fulfill_htlcs(UpdateFulfillHTLC[] val) {
64 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);
68 * update_fail_htlc messages which should be sent
70 public UpdateFailHTLC[] get_update_fail_htlcs() {
71 long[] ret = bindings.CommitmentUpdate_get_update_fail_htlcs(this.ptr);
72 UpdateFailHTLC[] ret_conv_16_arr = new UpdateFailHTLC[ret.length];
73 for (int q = 0; q < ret.length; q++) {
74 long ret_conv_16 = ret[q];
75 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); }
76 ret_conv_16_hu_conv.ptrs_to.add(this);
77 ret_conv_16_arr[q] = ret_conv_16_hu_conv;
79 return ret_conv_16_arr;
83 * update_fail_htlc messages which should be sent
85 public void set_update_fail_htlcs(UpdateFailHTLC[] val) {
86 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);
90 * update_fail_malformed_htlc messages which should be sent
92 public UpdateFailMalformedHTLC[] get_update_fail_malformed_htlcs() {
93 long[] ret = bindings.CommitmentUpdate_get_update_fail_malformed_htlcs(this.ptr);
94 UpdateFailMalformedHTLC[] ret_conv_25_arr = new UpdateFailMalformedHTLC[ret.length];
95 for (int z = 0; z < ret.length; z++) {
96 long ret_conv_25 = ret[z];
97 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); }
98 ret_conv_25_hu_conv.ptrs_to.add(this);
99 ret_conv_25_arr[z] = ret_conv_25_hu_conv;
101 return ret_conv_25_arr;
105 * update_fail_malformed_htlc messages which should be sent
107 public void set_update_fail_malformed_htlcs(UpdateFailMalformedHTLC[] val) {
108 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 * An update_fee message which should be sent
114 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
117 public UpdateFee get_update_fee() {
118 long ret = bindings.CommitmentUpdate_get_update_fee(this.ptr);
119 if (ret >= 0 && ret <= 4096) { return null; }
120 UpdateFee ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new UpdateFee(null, ret); }
121 ret_hu_conv.ptrs_to.add(this);
126 * An update_fee message which should be sent
128 * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
130 public void set_update_fee(@Nullable UpdateFee val) {
131 bindings.CommitmentUpdate_set_update_fee(this.ptr, val == null ? 0 : val.ptr & ~1);
135 * Finally, the commitment_signed message which should be sent
137 public CommitmentSigned get_commitment_signed() {
138 long ret = bindings.CommitmentUpdate_get_commitment_signed(this.ptr);
139 if (ret >= 0 && ret <= 4096) { return null; }
140 CommitmentSigned ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new CommitmentSigned(null, ret); }
141 ret_hu_conv.ptrs_to.add(this);
146 * Finally, the commitment_signed message which should be sent
148 public void set_commitment_signed(CommitmentSigned val) {
149 bindings.CommitmentUpdate_set_commitment_signed(this.ptr, val == null ? 0 : val.ptr & ~1);
153 * Constructs a new CommitmentUpdate given each field
155 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) {
156 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);
157 if (ret >= 0 && ret <= 4096) { return null; }
158 CommitmentUpdate ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new CommitmentUpdate(null, ret); }
159 ret_hu_conv.ptrs_to.add(ret_hu_conv);
164 * Creates a copy of the CommitmentUpdate
166 public CommitmentUpdate clone() {
167 long ret = bindings.CommitmentUpdate_clone(this.ptr);
168 if (ret >= 0 && ret <= 4096) { return null; }
169 CommitmentUpdate ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new CommitmentUpdate(null, ret); }
170 ret_hu_conv.ptrs_to.add(this);