e6c730611c5e33bae85c72024f815d47297ff1e7
[ldk-java] / src / main / java / org / ldk / structs / CommitmentSigned.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  * A [`commitment_signed`] message to be sent to or received from a peer.
13  * 
14  * [`commitment_signed`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#committing-updates-so-far-commitment_signed
15  */
16 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
17 public class CommitmentSigned extends CommonBase {
18         CommitmentSigned(Object _dummy, long ptr) { super(ptr); }
19         @Override @SuppressWarnings("deprecation")
20         protected void finalize() throws Throwable {
21                 super.finalize();
22                 if (ptr != 0) { bindings.CommitmentSigned_free(ptr); }
23         }
24
25         /**
26          * The channel ID
27          */
28         public byte[] get_channel_id() {
29                 byte[] ret = bindings.CommitmentSigned_get_channel_id(this.ptr);
30                 Reference.reachabilityFence(this);
31                 return ret;
32         }
33
34         /**
35          * The channel ID
36          */
37         public void set_channel_id(byte[] val) {
38                 bindings.CommitmentSigned_set_channel_id(this.ptr, InternalUtils.check_arr_len(val, 32));
39                 Reference.reachabilityFence(this);
40                 Reference.reachabilityFence(val);
41         }
42
43         /**
44          * A signature on the commitment transaction
45          */
46         public byte[] get_signature() {
47                 byte[] ret = bindings.CommitmentSigned_get_signature(this.ptr);
48                 Reference.reachabilityFence(this);
49                 return ret;
50         }
51
52         /**
53          * A signature on the commitment transaction
54          */
55         public void set_signature(byte[] val) {
56                 bindings.CommitmentSigned_set_signature(this.ptr, InternalUtils.check_arr_len(val, 64));
57                 Reference.reachabilityFence(this);
58                 Reference.reachabilityFence(val);
59         }
60
61         /**
62          * Signatures on the HTLC transactions
63          * 
64          * Returns a copy of the field.
65          */
66         public byte[][] get_htlc_signatures() {
67                 byte[][] ret = bindings.CommitmentSigned_get_htlc_signatures(this.ptr);
68                 Reference.reachabilityFence(this);
69                 return ret;
70         }
71
72         /**
73          * Signatures on the HTLC transactions
74          */
75         public void set_htlc_signatures(byte[][] val) {
76                 bindings.CommitmentSigned_set_htlc_signatures(this.ptr, val != null ? Arrays.stream(val).map(val_conv_8 -> InternalUtils.check_arr_len(val_conv_8, 64)).toArray(byte[][]::new) : null);
77                 Reference.reachabilityFence(this);
78                 Reference.reachabilityFence(val);
79         }
80
81         /**
82          * Constructs a new CommitmentSigned given each field
83          */
84         public static CommitmentSigned of(byte[] channel_id_arg, byte[] signature_arg, byte[][] htlc_signatures_arg) {
85                 long ret = bindings.CommitmentSigned_new(InternalUtils.check_arr_len(channel_id_arg, 32), InternalUtils.check_arr_len(signature_arg, 64), htlc_signatures_arg != null ? Arrays.stream(htlc_signatures_arg).map(htlc_signatures_arg_conv_8 -> InternalUtils.check_arr_len(htlc_signatures_arg_conv_8, 64)).toArray(byte[][]::new) : null);
86                 Reference.reachabilityFence(channel_id_arg);
87                 Reference.reachabilityFence(signature_arg);
88                 Reference.reachabilityFence(htlc_signatures_arg);
89                 if (ret >= 0 && ret <= 4096) { return null; }
90                 org.ldk.structs.CommitmentSigned ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.CommitmentSigned(null, ret); }
91                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
92                 return ret_hu_conv;
93         }
94
95         long clone_ptr() {
96                 long ret = bindings.CommitmentSigned_clone_ptr(this.ptr);
97                 Reference.reachabilityFence(this);
98                 return ret;
99         }
100
101         /**
102          * Creates a copy of the CommitmentSigned
103          */
104         public CommitmentSigned clone() {
105                 long ret = bindings.CommitmentSigned_clone(this.ptr);
106                 Reference.reachabilityFence(this);
107                 if (ret >= 0 && ret <= 4096) { return null; }
108                 org.ldk.structs.CommitmentSigned ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.CommitmentSigned(null, ret); }
109                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
110                 return ret_hu_conv;
111         }
112
113         /**
114          * Checks if two CommitmentSigneds contain equal inner contents.
115          * This ignores pointers and is_owned flags and looks at the values in fields.
116          * Two objects with NULL inner values will be considered "equal" here.
117          */
118         public boolean eq(org.ldk.structs.CommitmentSigned b) {
119                 boolean ret = bindings.CommitmentSigned_eq(this.ptr, b == null ? 0 : b.ptr);
120                 Reference.reachabilityFence(this);
121                 Reference.reachabilityFence(b);
122                 if (this != null) { this.ptrs_to.add(b); };
123                 return ret;
124         }
125
126         @Override public boolean equals(Object o) {
127                 if (!(o instanceof CommitmentSigned)) return false;
128                 return this.eq((CommitmentSigned)o);
129         }
130         /**
131          * Serialize the CommitmentSigned object into a byte array which can be read by CommitmentSigned_read
132          */
133         public byte[] write() {
134                 byte[] ret = bindings.CommitmentSigned_write(this.ptr);
135                 Reference.reachabilityFence(this);
136                 return ret;
137         }
138
139         /**
140          * Read a CommitmentSigned from a byte array, created by CommitmentSigned_write
141          */
142         public static Result_CommitmentSignedDecodeErrorZ read(byte[] ser) {
143                 long ret = bindings.CommitmentSigned_read(ser);
144                 Reference.reachabilityFence(ser);
145                 if (ret >= 0 && ret <= 4096) { return null; }
146                 Result_CommitmentSignedDecodeErrorZ ret_hu_conv = Result_CommitmentSignedDecodeErrorZ.constr_from_ptr(ret);
147                 return ret_hu_conv;
148         }
149
150 }