[Java] Update auto-generated bindings to 0.0.117
[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                 private StaticOutput(long ptr, bindings.LDKSpendableOutputDescriptor.StaticOutput obj) {
64                         super(null, ptr);
65                         long outpoint = obj.outpoint;
66                         org.ldk.structs.OutPoint outpoint_hu_conv = null; if (outpoint < 0 || outpoint > 4096) { outpoint_hu_conv = new org.ldk.structs.OutPoint(null, outpoint); }
67                         if (outpoint_hu_conv != null) { outpoint_hu_conv.ptrs_to.add(this); };
68                         this.outpoint = outpoint_hu_conv;
69                         long output = obj.output;
70                         TxOut output_conv = new TxOut(null, output);
71                         this.output = output_conv;
72                 }
73         }
74         /**
75          * An output to a P2WSH script which can be spent with a single signature after an `OP_CSV`
76          * delay.
77          * 
78          * The witness in the spending input should be:
79          * ```bitcoin
80          * <BIP 143 signature> <empty vector> (MINIMALIF standard rule) <provided witnessScript>
81          * ```
82          * 
83          * Note that the `nSequence` field in the spending input must be set to
84          * [`DelayedPaymentOutputDescriptor::to_self_delay`] (which means the transaction is not
85          * broadcastable until at least [`DelayedPaymentOutputDescriptor::to_self_delay`] blocks after
86          * the outpoint confirms, see [BIP
87          * 68](https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki)). Also note that LDK
88          * won't generate a [`SpendableOutputDescriptor`] until the corresponding block height
89          * is reached.
90          * 
91          * These are generally the result of a \"revocable\" output to us, spendable only by us unless
92          * it is an output from an old state which we broadcast (which should never happen).
93          * 
94          * To derive the delayed payment key which is used to sign this input, you must pass the
95          * holder [`InMemorySigner::delayed_payment_base_key`] (i.e., the private key which corresponds to the
96          * [`ChannelPublicKeys::delayed_payment_basepoint`] in [`ChannelSigner::pubkeys`]) and the provided
97          * [`DelayedPaymentOutputDescriptor::per_commitment_point`] to [`chan_utils::derive_private_key`]. The public key can be
98          * generated without the secret key using [`chan_utils::derive_public_key`] and only the
99          * [`ChannelPublicKeys::delayed_payment_basepoint`] which appears in [`ChannelSigner::pubkeys`].
100          * 
101          * To derive the [`DelayedPaymentOutputDescriptor::revocation_pubkey`] provided here (which is
102          * used in the witness script generation), you must pass the counterparty
103          * [`ChannelPublicKeys::revocation_basepoint`] (which appears in the call to
104          * [`ChannelSigner::provide_channel_parameters`]) and the provided
105          * [`DelayedPaymentOutputDescriptor::per_commitment_point`] to
106          * [`chan_utils::derive_public_revocation_key`].
107          * 
108          * The witness script which is hashed and included in the output `script_pubkey` may be
109          * regenerated by passing the [`DelayedPaymentOutputDescriptor::revocation_pubkey`] (derived
110          * as explained above), our delayed payment pubkey (derived as explained above), and the
111          * [`DelayedPaymentOutputDescriptor::to_self_delay`] contained here to
112          * [`chan_utils::get_revokeable_redeemscript`].
113          */
114         public final static class DelayedPaymentOutput extends SpendableOutputDescriptor {
115                 public final org.ldk.structs.DelayedPaymentOutputDescriptor delayed_payment_output;
116                 private DelayedPaymentOutput(long ptr, bindings.LDKSpendableOutputDescriptor.DelayedPaymentOutput obj) {
117                         super(null, ptr);
118                         long delayed_payment_output = obj.delayed_payment_output;
119                         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); }
120                         if (delayed_payment_output_hu_conv != null) { delayed_payment_output_hu_conv.ptrs_to.add(this); };
121                         this.delayed_payment_output = delayed_payment_output_hu_conv;
122                 }
123         }
124         /**
125          * An output spendable exclusively by our payment key (i.e., the private key that corresponds
126          * to the `payment_point` in [`ChannelSigner::pubkeys`]). The output type depends on the
127          * channel type negotiated.
128          * 
129          * On an anchor outputs channel, the witness in the spending input is:
130          * ```bitcoin
131          * <BIP 143 signature> <witness script>
132          * ```
133          * 
134          * Otherwise, it is:
135          * ```bitcoin
136          * <BIP 143 signature> <payment key>
137          * ```
138          * 
139          * These are generally the result of our counterparty having broadcast the current state,
140          * allowing us to claim the non-HTLC-encumbered outputs immediately, or after one confirmation
141          * in the case of anchor outputs channels.
142          */
143         public final static class StaticPaymentOutput extends SpendableOutputDescriptor {
144                 public final org.ldk.structs.StaticPaymentOutputDescriptor static_payment_output;
145                 private StaticPaymentOutput(long ptr, bindings.LDKSpendableOutputDescriptor.StaticPaymentOutput obj) {
146                         super(null, ptr);
147                         long static_payment_output = obj.static_payment_output;
148                         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); }
149                         if (static_payment_output_hu_conv != null) { static_payment_output_hu_conv.ptrs_to.add(this); };
150                         this.static_payment_output = static_payment_output_hu_conv;
151                 }
152         }
153         long clone_ptr() {
154                 long ret = bindings.SpendableOutputDescriptor_clone_ptr(this.ptr);
155                 Reference.reachabilityFence(this);
156                 return ret;
157         }
158
159         /**
160          * Creates a copy of the SpendableOutputDescriptor
161          */
162         public SpendableOutputDescriptor clone() {
163                 long ret = bindings.SpendableOutputDescriptor_clone(this.ptr);
164                 Reference.reachabilityFence(this);
165                 if (ret >= 0 && ret <= 4096) { return null; }
166                 org.ldk.structs.SpendableOutputDescriptor ret_hu_conv = org.ldk.structs.SpendableOutputDescriptor.constr_from_ptr(ret);
167                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
168                 return ret_hu_conv;
169         }
170
171         /**
172          * Utility method to constructs a new StaticOutput-variant SpendableOutputDescriptor
173          */
174         public static SpendableOutputDescriptor static_output(org.ldk.structs.OutPoint outpoint, org.ldk.structs.TxOut output) {
175                 long ret = bindings.SpendableOutputDescriptor_static_output(outpoint == null ? 0 : outpoint.ptr, output.ptr);
176                 Reference.reachabilityFence(outpoint);
177                 Reference.reachabilityFence(output);
178                 if (ret >= 0 && ret <= 4096) { return null; }
179                 org.ldk.structs.SpendableOutputDescriptor ret_hu_conv = org.ldk.structs.SpendableOutputDescriptor.constr_from_ptr(ret);
180                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
181                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(outpoint); };
182                 return ret_hu_conv;
183         }
184
185         /**
186          * Utility method to constructs a new DelayedPaymentOutput-variant SpendableOutputDescriptor
187          */
188         public static SpendableOutputDescriptor delayed_payment_output(org.ldk.structs.DelayedPaymentOutputDescriptor a) {
189                 long ret = bindings.SpendableOutputDescriptor_delayed_payment_output(a == null ? 0 : a.ptr);
190                 Reference.reachabilityFence(a);
191                 if (ret >= 0 && ret <= 4096) { return null; }
192                 org.ldk.structs.SpendableOutputDescriptor ret_hu_conv = org.ldk.structs.SpendableOutputDescriptor.constr_from_ptr(ret);
193                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
194                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a); };
195                 return ret_hu_conv;
196         }
197
198         /**
199          * Utility method to constructs a new StaticPaymentOutput-variant SpendableOutputDescriptor
200          */
201         public static SpendableOutputDescriptor static_payment_output(org.ldk.structs.StaticPaymentOutputDescriptor a) {
202                 long ret = bindings.SpendableOutputDescriptor_static_payment_output(a == null ? 0 : a.ptr);
203                 Reference.reachabilityFence(a);
204                 if (ret >= 0 && ret <= 4096) { return null; }
205                 org.ldk.structs.SpendableOutputDescriptor ret_hu_conv = org.ldk.structs.SpendableOutputDescriptor.constr_from_ptr(ret);
206                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
207                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a); };
208                 return ret_hu_conv;
209         }
210
211         /**
212          * Generates a non-cryptographic 64-bit hash of the SpendableOutputDescriptor.
213          */
214         public long hash() {
215                 long ret = bindings.SpendableOutputDescriptor_hash(this.ptr);
216                 Reference.reachabilityFence(this);
217                 return ret;
218         }
219
220         @Override public int hashCode() {
221                 return (int)this.hash();
222         }
223         /**
224          * Checks if two SpendableOutputDescriptors contain equal inner contents.
225          * This ignores pointers and is_owned flags and looks at the values in fields.
226          */
227         public boolean eq(org.ldk.structs.SpendableOutputDescriptor b) {
228                 boolean ret = bindings.SpendableOutputDescriptor_eq(this.ptr, b == null ? 0 : b.ptr);
229                 Reference.reachabilityFence(this);
230                 Reference.reachabilityFence(b);
231                 return ret;
232         }
233
234         @Override public boolean equals(Object o) {
235                 if (!(o instanceof SpendableOutputDescriptor)) return false;
236                 return this.eq((SpendableOutputDescriptor)o);
237         }
238         /**
239          * Serialize the SpendableOutputDescriptor object into a byte array which can be read by SpendableOutputDescriptor_read
240          */
241         public byte[] write() {
242                 byte[] ret = bindings.SpendableOutputDescriptor_write(this.ptr);
243                 Reference.reachabilityFence(this);
244                 return ret;
245         }
246
247         /**
248          * Read a SpendableOutputDescriptor from a byte array, created by SpendableOutputDescriptor_write
249          */
250         public static Result_SpendableOutputDescriptorDecodeErrorZ read(byte[] ser) {
251                 long ret = bindings.SpendableOutputDescriptor_read(ser);
252                 Reference.reachabilityFence(ser);
253                 if (ret >= 0 && ret <= 4096) { return null; }
254                 Result_SpendableOutputDescriptorDecodeErrorZ ret_hu_conv = Result_SpendableOutputDescriptorDecodeErrorZ.constr_from_ptr(ret);
255                 return ret_hu_conv;
256         }
257
258 }