[Java] Update auto-generated Java bindings to LDK 0.0.121
[ldk-java] / src / main / java / org / ldk / structs / SpendableOutputDescriptor.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  * Describes the necessary information to spend a spendable output.
13  * 
14  * When on-chain outputs are created by LDK (which our counterparty is not able to claim at any
15  * point in the future) a [`SpendableOutputs`] event is generated which you must track and be able
16  * to spend on-chain. The information needed to do this is provided in this enum, including the
17  * outpoint describing which `txid` and output `index` is available, the full output which exists
18  * at that `txid`/`index`, and any keys or other information required to sign.
19  * 
20  * [`SpendableOutputs`]: crate::events::Event::SpendableOutputs
21  */
22 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
23 public class SpendableOutputDescriptor extends CommonBase {
24         private SpendableOutputDescriptor(Object _dummy, long ptr) { super(ptr); }
25         @Override @SuppressWarnings("deprecation")
26         protected void finalize() throws Throwable {
27                 super.finalize();
28                 if (ptr != 0) { bindings.SpendableOutputDescriptor_free(ptr); }
29         }
30         static SpendableOutputDescriptor constr_from_ptr(long ptr) {
31                 bindings.LDKSpendableOutputDescriptor raw_val = bindings.LDKSpendableOutputDescriptor_ref_from_ptr(ptr);
32                 if (raw_val.getClass() == bindings.LDKSpendableOutputDescriptor.StaticOutput.class) {
33                         return new StaticOutput(ptr, (bindings.LDKSpendableOutputDescriptor.StaticOutput)raw_val);
34                 }
35                 if (raw_val.getClass() == bindings.LDKSpendableOutputDescriptor.DelayedPaymentOutput.class) {
36                         return new DelayedPaymentOutput(ptr, (bindings.LDKSpendableOutputDescriptor.DelayedPaymentOutput)raw_val);
37                 }
38                 if (raw_val.getClass() == bindings.LDKSpendableOutputDescriptor.StaticPaymentOutput.class) {
39                         return new StaticPaymentOutput(ptr, (bindings.LDKSpendableOutputDescriptor.StaticPaymentOutput)raw_val);
40                 }
41                 assert false; return null; // Unreachable without extending the (internal) bindings interface
42         }
43
44         /**
45          * An output to a script which was provided via [`SignerProvider`] directly, either from
46          * [`get_destination_script`] or [`get_shutdown_scriptpubkey`], thus you should already
47          * know how to spend it. No secret keys are provided as LDK was never given any key.
48          * These may include outputs from a transaction punishing our counterparty or claiming an HTLC
49          * on-chain using the payment preimage or after it has timed out.
50          * 
51          * [`get_shutdown_scriptpubkey`]: SignerProvider::get_shutdown_scriptpubkey
52          * [`get_destination_script`]: SignerProvider::get_shutdown_scriptpubkey
53          */
54         public final static class StaticOutput extends SpendableOutputDescriptor {
55                 /**
56                  * The outpoint which is spendable.
57                 */
58                 public final org.ldk.structs.OutPoint outpoint;
59                 /**
60                  * The output which is referenced by the given outpoint.
61                 */
62                 public final org.ldk.structs.TxOut output;
63                 /**
64                  * The `channel_keys_id` for the channel which this output came from.
65                  * 
66                  * For channels which were generated on LDK 0.0.119 or later, this is the value which was
67                  * passed to the [`SignerProvider::get_destination_script`] call which provided this
68                  * output script.
69                  * 
70                  * For channels which were generated prior to LDK 0.0.119, no such argument existed,
71                  * however this field may still be filled in if such data is available.
72                  * 
73                  * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
74                 */
75                 @Nullable public final byte[] channel_keys_id;
76                 private StaticOutput(long ptr, bindings.LDKSpendableOutputDescriptor.StaticOutput obj) {
77                         super(null, ptr);
78                         long outpoint = obj.outpoint;
79                         org.ldk.structs.OutPoint outpoint_hu_conv = null; if (outpoint < 0 || outpoint > 4096) { outpoint_hu_conv = new org.ldk.structs.OutPoint(null, outpoint); }
80                         if (outpoint_hu_conv != null) { outpoint_hu_conv.ptrs_to.add(this); };
81                         this.outpoint = outpoint_hu_conv;
82                         long output = obj.output;
83                         TxOut output_conv = new TxOut(null, output);
84                         this.output = output_conv;
85                         this.channel_keys_id = obj.channel_keys_id;
86                 }
87         }
88         /**
89          * An output to a P2WSH script which can be spent with a single signature after an `OP_CSV`
90          * delay.
91          * 
92          * The witness in the spending input should be:
93          * ```bitcoin
94          * <BIP 143 signature> <empty vector> (MINIMALIF standard rule) <provided witnessScript>
95          * ```
96          * 
97          * Note that the `nSequence` field in the spending input must be set to
98          * [`DelayedPaymentOutputDescriptor::to_self_delay`] (which means the transaction is not
99          * broadcastable until at least [`DelayedPaymentOutputDescriptor::to_self_delay`] blocks after
100          * the outpoint confirms, see [BIP
101          * 68](https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki)). Also note that LDK
102          * won't generate a [`SpendableOutputDescriptor`] until the corresponding block height
103          * is reached.
104          * 
105          * These are generally the result of a \"revocable\" output to us, spendable only by us unless
106          * it is an output from an old state which we broadcast (which should never happen).
107          * 
108          * To derive the delayed payment key which is used to sign this input, you must pass the
109          * holder [`InMemorySigner::delayed_payment_base_key`] (i.e., the private key which corresponds to the
110          * [`ChannelPublicKeys::delayed_payment_basepoint`] in [`ChannelSigner::pubkeys`]) and the provided
111          * [`DelayedPaymentOutputDescriptor::per_commitment_point`] to [`chan_utils::derive_private_key`]. The DelayedPaymentKey can be
112          * generated without the secret key using [`DelayedPaymentKey::from_basepoint`] and only the
113          * [`ChannelPublicKeys::delayed_payment_basepoint`] which appears in [`ChannelSigner::pubkeys`].
114          * 
115          * To derive the [`DelayedPaymentOutputDescriptor::revocation_pubkey`] provided here (which is
116          * used in the witness script generation), you must pass the counterparty
117          * [`ChannelPublicKeys::revocation_basepoint`] (which appears in the call to
118          * [`ChannelSigner::provide_channel_parameters`]) and the provided
119          * [`DelayedPaymentOutputDescriptor::per_commitment_point`] to
120          * [`RevocationKey`].
121          * 
122          * The witness script which is hashed and included in the output `script_pubkey` may be
123          * regenerated by passing the [`DelayedPaymentOutputDescriptor::revocation_pubkey`] (derived
124          * as explained above), our delayed payment pubkey (derived as explained above), and the
125          * [`DelayedPaymentOutputDescriptor::to_self_delay`] contained here to
126          * [`chan_utils::get_revokeable_redeemscript`].
127          */
128         public final static class DelayedPaymentOutput extends SpendableOutputDescriptor {
129                 public final org.ldk.structs.DelayedPaymentOutputDescriptor delayed_payment_output;
130                 private DelayedPaymentOutput(long ptr, bindings.LDKSpendableOutputDescriptor.DelayedPaymentOutput obj) {
131                         super(null, ptr);
132                         long delayed_payment_output = obj.delayed_payment_output;
133                         org.ldk.structs.DelayedPaymentOutputDescriptor delayed_payment_output_hu_conv = null; if (delayed_payment_output < 0 || delayed_payment_output > 4096) { delayed_payment_output_hu_conv = new org.ldk.structs.DelayedPaymentOutputDescriptor(null, delayed_payment_output); }
134                         if (delayed_payment_output_hu_conv != null) { delayed_payment_output_hu_conv.ptrs_to.add(this); };
135                         this.delayed_payment_output = delayed_payment_output_hu_conv;
136                 }
137         }
138         /**
139          * An output spendable exclusively by our payment key (i.e., the private key that corresponds
140          * to the `payment_point` in [`ChannelSigner::pubkeys`]). The output type depends on the
141          * channel type negotiated.
142          * 
143          * On an anchor outputs channel, the witness in the spending input is:
144          * ```bitcoin
145          * <BIP 143 signature> <witness script>
146          * ```
147          * 
148          * Otherwise, it is:
149          * ```bitcoin
150          * <BIP 143 signature> <payment key>
151          * ```
152          * 
153          * These are generally the result of our counterparty having broadcast the current state,
154          * allowing us to claim the non-HTLC-encumbered outputs immediately, or after one confirmation
155          * in the case of anchor outputs channels.
156          */
157         public final static class StaticPaymentOutput extends SpendableOutputDescriptor {
158                 public final org.ldk.structs.StaticPaymentOutputDescriptor static_payment_output;
159                 private StaticPaymentOutput(long ptr, bindings.LDKSpendableOutputDescriptor.StaticPaymentOutput obj) {
160                         super(null, ptr);
161                         long static_payment_output = obj.static_payment_output;
162                         org.ldk.structs.StaticPaymentOutputDescriptor static_payment_output_hu_conv = null; if (static_payment_output < 0 || static_payment_output > 4096) { static_payment_output_hu_conv = new org.ldk.structs.StaticPaymentOutputDescriptor(null, static_payment_output); }
163                         if (static_payment_output_hu_conv != null) { static_payment_output_hu_conv.ptrs_to.add(this); };
164                         this.static_payment_output = static_payment_output_hu_conv;
165                 }
166         }
167         long clone_ptr() {
168                 long ret = bindings.SpendableOutputDescriptor_clone_ptr(this.ptr);
169                 Reference.reachabilityFence(this);
170                 return ret;
171         }
172
173         /**
174          * Creates a copy of the SpendableOutputDescriptor
175          */
176         public SpendableOutputDescriptor clone() {
177                 long ret = bindings.SpendableOutputDescriptor_clone(this.ptr);
178                 Reference.reachabilityFence(this);
179                 if (ret >= 0 && ret <= 4096) { return null; }
180                 org.ldk.structs.SpendableOutputDescriptor ret_hu_conv = org.ldk.structs.SpendableOutputDescriptor.constr_from_ptr(ret);
181                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
182                 return ret_hu_conv;
183         }
184
185         /**
186          * Utility method to constructs a new StaticOutput-variant SpendableOutputDescriptor
187          */
188         public static SpendableOutputDescriptor static_output(org.ldk.structs.OutPoint outpoint, org.ldk.structs.TxOut output, byte[] channel_keys_id) {
189                 long ret = bindings.SpendableOutputDescriptor_static_output(outpoint == null ? 0 : outpoint.ptr, output.ptr, InternalUtils.check_arr_len(channel_keys_id, 32));
190                 Reference.reachabilityFence(outpoint);
191                 Reference.reachabilityFence(output);
192                 Reference.reachabilityFence(channel_keys_id);
193                 if (ret >= 0 && ret <= 4096) { return null; }
194                 org.ldk.structs.SpendableOutputDescriptor ret_hu_conv = org.ldk.structs.SpendableOutputDescriptor.constr_from_ptr(ret);
195                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
196                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(outpoint); };
197                 return ret_hu_conv;
198         }
199
200         /**
201          * Utility method to constructs a new DelayedPaymentOutput-variant SpendableOutputDescriptor
202          */
203         public static SpendableOutputDescriptor delayed_payment_output(org.ldk.structs.DelayedPaymentOutputDescriptor a) {
204                 long ret = bindings.SpendableOutputDescriptor_delayed_payment_output(a == null ? 0 : a.ptr);
205                 Reference.reachabilityFence(a);
206                 if (ret >= 0 && ret <= 4096) { return null; }
207                 org.ldk.structs.SpendableOutputDescriptor ret_hu_conv = org.ldk.structs.SpendableOutputDescriptor.constr_from_ptr(ret);
208                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
209                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a); };
210                 return ret_hu_conv;
211         }
212
213         /**
214          * Utility method to constructs a new StaticPaymentOutput-variant SpendableOutputDescriptor
215          */
216         public static SpendableOutputDescriptor static_payment_output(org.ldk.structs.StaticPaymentOutputDescriptor a) {
217                 long ret = bindings.SpendableOutputDescriptor_static_payment_output(a == null ? 0 : a.ptr);
218                 Reference.reachabilityFence(a);
219                 if (ret >= 0 && ret <= 4096) { return null; }
220                 org.ldk.structs.SpendableOutputDescriptor ret_hu_conv = org.ldk.structs.SpendableOutputDescriptor.constr_from_ptr(ret);
221                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
222                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a); };
223                 return ret_hu_conv;
224         }
225
226         /**
227          * Generates a non-cryptographic 64-bit hash of the SpendableOutputDescriptor.
228          */
229         public long hash() {
230                 long ret = bindings.SpendableOutputDescriptor_hash(this.ptr);
231                 Reference.reachabilityFence(this);
232                 return ret;
233         }
234
235         @Override public int hashCode() {
236                 return (int)this.hash();
237         }
238         /**
239          * Checks if two SpendableOutputDescriptors contain equal inner contents.
240          * This ignores pointers and is_owned flags and looks at the values in fields.
241          */
242         public boolean eq(org.ldk.structs.SpendableOutputDescriptor b) {
243                 boolean ret = bindings.SpendableOutputDescriptor_eq(this.ptr, b == null ? 0 : b.ptr);
244                 Reference.reachabilityFence(this);
245                 Reference.reachabilityFence(b);
246                 return ret;
247         }
248
249         @Override public boolean equals(Object o) {
250                 if (!(o instanceof SpendableOutputDescriptor)) return false;
251                 return this.eq((SpendableOutputDescriptor)o);
252         }
253         /**
254          * Serialize the SpendableOutputDescriptor object into a byte array which can be read by SpendableOutputDescriptor_read
255          */
256         public byte[] write() {
257                 byte[] ret = bindings.SpendableOutputDescriptor_write(this.ptr);
258                 Reference.reachabilityFence(this);
259                 return ret;
260         }
261
262         /**
263          * Read a SpendableOutputDescriptor from a byte array, created by SpendableOutputDescriptor_write
264          */
265         public static Result_SpendableOutputDescriptorDecodeErrorZ read(byte[] ser) {
266                 long ret = bindings.SpendableOutputDescriptor_read(ser);
267                 Reference.reachabilityFence(ser);
268                 if (ret >= 0 && ret <= 4096) { return null; }
269                 Result_SpendableOutputDescriptorDecodeErrorZ ret_hu_conv = Result_SpendableOutputDescriptorDecodeErrorZ.constr_from_ptr(ret);
270                 return ret_hu_conv;
271         }
272
273 }