eee1fcd1410476febf4b05bce040997bcf5bc6ce
[ldk-java] / src / main / java / org / ldk / structs / ClosingSigned.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 closing_signed message to be sent or received from a peer
13  */
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class ClosingSigned extends CommonBase {
16         ClosingSigned(Object _dummy, long ptr) { super(ptr); }
17         @Override @SuppressWarnings("deprecation")
18         protected void finalize() throws Throwable {
19                 super.finalize();
20                 if (ptr != 0) { bindings.ClosingSigned_free(ptr); }
21         }
22
23         /**
24          * The channel ID
25          */
26         public byte[] get_channel_id() {
27                 byte[] ret = bindings.ClosingSigned_get_channel_id(this.ptr);
28                 Reference.reachabilityFence(this);
29                 return ret;
30         }
31
32         /**
33          * The channel ID
34          */
35         public void set_channel_id(byte[] val) {
36                 bindings.ClosingSigned_set_channel_id(this.ptr, InternalUtils.check_arr_len(val, 32));
37                 Reference.reachabilityFence(this);
38                 Reference.reachabilityFence(val);
39         }
40
41         /**
42          * The proposed total fee for the closing transaction
43          */
44         public long get_fee_satoshis() {
45                 long ret = bindings.ClosingSigned_get_fee_satoshis(this.ptr);
46                 Reference.reachabilityFence(this);
47                 return ret;
48         }
49
50         /**
51          * The proposed total fee for the closing transaction
52          */
53         public void set_fee_satoshis(long val) {
54                 bindings.ClosingSigned_set_fee_satoshis(this.ptr, val);
55                 Reference.reachabilityFence(this);
56                 Reference.reachabilityFence(val);
57         }
58
59         /**
60          * A signature on the closing transaction
61          */
62         public byte[] get_signature() {
63                 byte[] ret = bindings.ClosingSigned_get_signature(this.ptr);
64                 Reference.reachabilityFence(this);
65                 return ret;
66         }
67
68         /**
69          * A signature on the closing transaction
70          */
71         public void set_signature(byte[] val) {
72                 bindings.ClosingSigned_set_signature(this.ptr, InternalUtils.check_arr_len(val, 64));
73                 Reference.reachabilityFence(this);
74                 Reference.reachabilityFence(val);
75         }
76
77         /**
78          * The minimum and maximum fees which the sender is willing to accept, provided only by new
79          * nodes.
80          * 
81          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
82          */
83         @Nullable
84         public ClosingSignedFeeRange get_fee_range() {
85                 long ret = bindings.ClosingSigned_get_fee_range(this.ptr);
86                 Reference.reachabilityFence(this);
87                 if (ret >= 0 && ret <= 4096) { return null; }
88                 org.ldk.structs.ClosingSignedFeeRange ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ClosingSignedFeeRange(null, ret); }
89                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
90                 return ret_hu_conv;
91         }
92
93         /**
94          * The minimum and maximum fees which the sender is willing to accept, provided only by new
95          * nodes.
96          * 
97          * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
98          */
99         public void set_fee_range(@Nullable ClosingSignedFeeRange val) {
100                 bindings.ClosingSigned_set_fee_range(this.ptr, val == null ? 0 : val.ptr);
101                 Reference.reachabilityFence(this);
102                 Reference.reachabilityFence(val);
103                 if (this != null) { this.ptrs_to.add(val); };
104         }
105
106         /**
107          * Constructs a new ClosingSigned given each field
108          */
109         public static ClosingSigned of(byte[] channel_id_arg, long fee_satoshis_arg, byte[] signature_arg, ClosingSignedFeeRange fee_range_arg) {
110                 long ret = bindings.ClosingSigned_new(InternalUtils.check_arr_len(channel_id_arg, 32), fee_satoshis_arg, InternalUtils.check_arr_len(signature_arg, 64), fee_range_arg == null ? 0 : fee_range_arg.ptr);
111                 Reference.reachabilityFence(channel_id_arg);
112                 Reference.reachabilityFence(fee_satoshis_arg);
113                 Reference.reachabilityFence(signature_arg);
114                 Reference.reachabilityFence(fee_range_arg);
115                 if (ret >= 0 && ret <= 4096) { return null; }
116                 org.ldk.structs.ClosingSigned ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ClosingSigned(null, ret); }
117                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
118                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(fee_range_arg); };
119                 return ret_hu_conv;
120         }
121
122         long clone_ptr() {
123                 long ret = bindings.ClosingSigned_clone_ptr(this.ptr);
124                 Reference.reachabilityFence(this);
125                 return ret;
126         }
127
128         /**
129          * Creates a copy of the ClosingSigned
130          */
131         public ClosingSigned clone() {
132                 long ret = bindings.ClosingSigned_clone(this.ptr);
133                 Reference.reachabilityFence(this);
134                 if (ret >= 0 && ret <= 4096) { return null; }
135                 org.ldk.structs.ClosingSigned ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ClosingSigned(null, ret); }
136                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
137                 return ret_hu_conv;
138         }
139
140         /**
141          * Checks if two ClosingSigneds contain equal inner contents.
142          * This ignores pointers and is_owned flags and looks at the values in fields.
143          * Two objects with NULL inner values will be considered "equal" here.
144          */
145         public boolean eq(ClosingSigned b) {
146                 boolean ret = bindings.ClosingSigned_eq(this.ptr, b == null ? 0 : b.ptr);
147                 Reference.reachabilityFence(this);
148                 Reference.reachabilityFence(b);
149                 if (this != null) { this.ptrs_to.add(b); };
150                 return ret;
151         }
152
153         @Override public boolean equals(Object o) {
154                 if (!(o instanceof ClosingSigned)) return false;
155                 return this.eq((ClosingSigned)o);
156         }
157         /**
158          * Serialize the ClosingSigned object into a byte array which can be read by ClosingSigned_read
159          */
160         public byte[] write() {
161                 byte[] ret = bindings.ClosingSigned_write(this.ptr);
162                 Reference.reachabilityFence(this);
163                 return ret;
164         }
165
166         /**
167          * Read a ClosingSigned from a byte array, created by ClosingSigned_write
168          */
169         public static Result_ClosingSignedDecodeErrorZ read(byte[] ser) {
170                 long ret = bindings.ClosingSigned_read(ser);
171                 Reference.reachabilityFence(ser);
172                 if (ret >= 0 && ret <= 4096) { return null; }
173                 Result_ClosingSignedDecodeErrorZ ret_hu_conv = Result_ClosingSignedDecodeErrorZ.constr_from_ptr(ret);
174                 return ret_hu_conv;
175         }
176
177 }