91319a3bd51215376639bb915d6a9a2f0a828faf
[ldk-java] / src / main / java / org / ldk / structs / HTLCDescriptor.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 descriptor used to sign for a commitment transaction's HTLC output.
13  */
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class HTLCDescriptor extends CommonBase {
16         HTLCDescriptor(Object _dummy, long ptr) { super(ptr); }
17         @Override @SuppressWarnings("deprecation")
18         protected void finalize() throws Throwable {
19                 super.finalize();
20                 if (ptr != 0) { bindings.HTLCDescriptor_free(ptr); }
21         }
22
23         /**
24          * The parameters required to derive the signer for the HTLC input.
25          */
26         public ChannelDerivationParameters get_channel_derivation_parameters() {
27                 long ret = bindings.HTLCDescriptor_get_channel_derivation_parameters(this.ptr);
28                 Reference.reachabilityFence(this);
29                 if (ret >= 0 && ret <= 4096) { return null; }
30                 org.ldk.structs.ChannelDerivationParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelDerivationParameters(null, ret); }
31                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
32                 return ret_hu_conv;
33         }
34
35         /**
36          * The parameters required to derive the signer for the HTLC input.
37          */
38         public void set_channel_derivation_parameters(org.ldk.structs.ChannelDerivationParameters val) {
39                 bindings.HTLCDescriptor_set_channel_derivation_parameters(this.ptr, val == null ? 0 : val.ptr);
40                 Reference.reachabilityFence(this);
41                 Reference.reachabilityFence(val);
42                 if (this != null) { this.ptrs_to.add(val); };
43         }
44
45         /**
46          * The number of the commitment transaction in which the HTLC output lives.
47          */
48         public long get_per_commitment_number() {
49                 long ret = bindings.HTLCDescriptor_get_per_commitment_number(this.ptr);
50                 Reference.reachabilityFence(this);
51                 return ret;
52         }
53
54         /**
55          * The number of the commitment transaction in which the HTLC output lives.
56          */
57         public void set_per_commitment_number(long val) {
58                 bindings.HTLCDescriptor_set_per_commitment_number(this.ptr, val);
59                 Reference.reachabilityFence(this);
60                 Reference.reachabilityFence(val);
61         }
62
63         /**
64          * The key tweak corresponding to the number of the commitment transaction in which the HTLC
65          * output lives. This tweak is applied to all the basepoints for both parties in the channel to
66          * arrive at unique keys per commitment.
67          * 
68          * See <https://github.com/lightning/bolts/blob/master/03-transactions.md#keys> for more info.
69          */
70         public byte[] get_per_commitment_point() {
71                 byte[] ret = bindings.HTLCDescriptor_get_per_commitment_point(this.ptr);
72                 Reference.reachabilityFence(this);
73                 return ret;
74         }
75
76         /**
77          * The key tweak corresponding to the number of the commitment transaction in which the HTLC
78          * output lives. This tweak is applied to all the basepoints for both parties in the channel to
79          * arrive at unique keys per commitment.
80          * 
81          * See <https://github.com/lightning/bolts/blob/master/03-transactions.md#keys> for more info.
82          */
83         public void set_per_commitment_point(byte[] val) {
84                 bindings.HTLCDescriptor_set_per_commitment_point(this.ptr, InternalUtils.check_arr_len(val, 33));
85                 Reference.reachabilityFence(this);
86                 Reference.reachabilityFence(val);
87         }
88
89         /**
90          * The details of the HTLC as it appears in the commitment transaction.
91          */
92         public HTLCOutputInCommitment get_htlc() {
93                 long ret = bindings.HTLCDescriptor_get_htlc(this.ptr);
94                 Reference.reachabilityFence(this);
95                 if (ret >= 0 && ret <= 4096) { return null; }
96                 org.ldk.structs.HTLCOutputInCommitment ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.HTLCOutputInCommitment(null, ret); }
97                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
98                 return ret_hu_conv;
99         }
100
101         /**
102          * The details of the HTLC as it appears in the commitment transaction.
103          */
104         public void set_htlc(org.ldk.structs.HTLCOutputInCommitment val) {
105                 bindings.HTLCDescriptor_set_htlc(this.ptr, val == null ? 0 : val.ptr);
106                 Reference.reachabilityFence(this);
107                 Reference.reachabilityFence(val);
108                 if (this != null) { this.ptrs_to.add(val); };
109         }
110
111         /**
112          * The preimage, if `Some`, to claim the HTLC output with. If `None`, the timeout path must be
113          * taken.
114          */
115         public Option_PaymentPreimageZ get_preimage() {
116                 long ret = bindings.HTLCDescriptor_get_preimage(this.ptr);
117                 Reference.reachabilityFence(this);
118                 if (ret >= 0 && ret <= 4096) { return null; }
119                 org.ldk.structs.Option_PaymentPreimageZ ret_hu_conv = org.ldk.structs.Option_PaymentPreimageZ.constr_from_ptr(ret);
120                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
121                 return ret_hu_conv;
122         }
123
124         /**
125          * The preimage, if `Some`, to claim the HTLC output with. If `None`, the timeout path must be
126          * taken.
127          */
128         public void set_preimage(org.ldk.structs.Option_PaymentPreimageZ val) {
129                 bindings.HTLCDescriptor_set_preimage(this.ptr, val.ptr);
130                 Reference.reachabilityFence(this);
131                 Reference.reachabilityFence(val);
132                 if (this != null) { this.ptrs_to.add(val); };
133         }
134
135         /**
136          * The counterparty's signature required to spend the HTLC output.
137          */
138         public byte[] get_counterparty_sig() {
139                 byte[] ret = bindings.HTLCDescriptor_get_counterparty_sig(this.ptr);
140                 Reference.reachabilityFence(this);
141                 return ret;
142         }
143
144         /**
145          * The counterparty's signature required to spend the HTLC output.
146          */
147         public void set_counterparty_sig(byte[] val) {
148                 bindings.HTLCDescriptor_set_counterparty_sig(this.ptr, InternalUtils.check_arr_len(val, 64));
149                 Reference.reachabilityFence(this);
150                 Reference.reachabilityFence(val);
151         }
152
153         long clone_ptr() {
154                 long ret = bindings.HTLCDescriptor_clone_ptr(this.ptr);
155                 Reference.reachabilityFence(this);
156                 return ret;
157         }
158
159         /**
160          * Creates a copy of the HTLCDescriptor
161          */
162         public HTLCDescriptor clone() {
163                 long ret = bindings.HTLCDescriptor_clone(this.ptr);
164                 Reference.reachabilityFence(this);
165                 if (ret >= 0 && ret <= 4096) { return null; }
166                 org.ldk.structs.HTLCDescriptor ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.HTLCDescriptor(null, ret); }
167                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
168                 return ret_hu_conv;
169         }
170
171         /**
172          * Checks if two HTLCDescriptors contain equal inner contents.
173          * This ignores pointers and is_owned flags and looks at the values in fields.
174          * Two objects with NULL inner values will be considered "equal" here.
175          */
176         public boolean eq(org.ldk.structs.HTLCDescriptor b) {
177                 boolean ret = bindings.HTLCDescriptor_eq(this.ptr, b == null ? 0 : b.ptr);
178                 Reference.reachabilityFence(this);
179                 Reference.reachabilityFence(b);
180                 if (this != null) { this.ptrs_to.add(b); };
181                 return ret;
182         }
183
184         @Override public boolean equals(Object o) {
185                 if (!(o instanceof HTLCDescriptor)) return false;
186                 return this.eq((HTLCDescriptor)o);
187         }
188         /**
189          * Returns the outpoint of the HTLC output in the commitment transaction. This is the outpoint
190          * being spent by the HTLC input in the HTLC transaction.
191          */
192         public OutPoint outpoint() {
193                 long ret = bindings.HTLCDescriptor_outpoint(this.ptr);
194                 Reference.reachabilityFence(this);
195                 if (ret >= 0 && ret <= 4096) { return null; }
196                 org.ldk.structs.OutPoint ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OutPoint(null, ret); }
197                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
198                 return ret_hu_conv;
199         }
200
201         /**
202          * Returns the UTXO to be spent by the HTLC input, which can be obtained via
203          * [`Self::unsigned_tx_input`].
204          */
205         public TxOut previous_utxo() {
206                 long ret = bindings.HTLCDescriptor_previous_utxo(this.ptr);
207                 Reference.reachabilityFence(this);
208                 if (ret >= 0 && ret <= 4096) { return null; }
209                 TxOut ret_conv = new TxOut(null, ret);
210                 return ret_conv;
211         }
212
213         /**
214          * Returns the unsigned transaction input spending the HTLC output in the commitment
215          * transaction.
216          */
217         public TxIn unsigned_tx_input() {
218                 long ret = bindings.HTLCDescriptor_unsigned_tx_input(this.ptr);
219                 Reference.reachabilityFence(this);
220                 if (ret >= 0 && ret <= 4096) { return null; }
221                 TxIn ret_conv = new TxIn(null, ret);
222                 return ret_conv;
223         }
224
225         /**
226          * Returns the delayed output created as a result of spending the HTLC output in the commitment
227          * transaction.
228          */
229         public TxOut tx_output() {
230                 long ret = bindings.HTLCDescriptor_tx_output(this.ptr);
231                 Reference.reachabilityFence(this);
232                 if (ret >= 0 && ret <= 4096) { return null; }
233                 TxOut ret_conv = new TxOut(null, ret);
234                 return ret_conv;
235         }
236
237         /**
238          * Returns the witness script of the HTLC output in the commitment transaction.
239          */
240         public byte[] witness_script() {
241                 byte[] ret = bindings.HTLCDescriptor_witness_script(this.ptr);
242                 Reference.reachabilityFence(this);
243                 return ret;
244         }
245
246         /**
247          * Returns the fully signed witness required to spend the HTLC output in the commitment
248          * transaction.
249          */
250         public byte[] tx_input_witness(byte[] signature, byte[] witness_script) {
251                 byte[] ret = bindings.HTLCDescriptor_tx_input_witness(this.ptr, InternalUtils.check_arr_len(signature, 64), witness_script);
252                 Reference.reachabilityFence(this);
253                 Reference.reachabilityFence(signature);
254                 Reference.reachabilityFence(witness_script);
255                 return ret;
256         }
257
258         /**
259          * Derives the channel signer required to sign the HTLC input.
260          */
261         public WriteableEcdsaChannelSigner derive_channel_signer(org.ldk.structs.SignerProvider signer_provider) {
262                 long ret = bindings.HTLCDescriptor_derive_channel_signer(this.ptr, signer_provider.ptr);
263                 Reference.reachabilityFence(this);
264                 Reference.reachabilityFence(signer_provider);
265                 if (ret >= 0 && ret <= 4096) { return null; }
266                 WriteableEcdsaChannelSigner ret_hu_conv = new WriteableEcdsaChannelSigner(null, ret);
267                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
268                 if (this != null) { this.ptrs_to.add(signer_provider); };
269                 return ret_hu_conv;
270         }
271
272 }