[Java] Update auto-generated bindings to 0.0.115
[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 to a P2WPKH, spendable exclusively by our payment key (i.e., the private key
126          * which corresponds to the `payment_point` in [`ChannelSigner::pubkeys`]). The witness
127          * in the spending input is, thus, simply:
128          * ```bitcoin
129          * <BIP 143 signature> <payment key>
130          * ```
131          * 
132          * These are generally the result of our counterparty having broadcast the current state,
133          * allowing us to claim the non-HTLC-encumbered outputs immediately.
134          */
135         public final static class StaticPaymentOutput extends SpendableOutputDescriptor {
136                 public final org.ldk.structs.StaticPaymentOutputDescriptor static_payment_output;
137                 private StaticPaymentOutput(long ptr, bindings.LDKSpendableOutputDescriptor.StaticPaymentOutput obj) {
138                         super(null, ptr);
139                         long static_payment_output = obj.static_payment_output;
140                         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); }
141                         if (static_payment_output_hu_conv != null) { static_payment_output_hu_conv.ptrs_to.add(this); };
142                         this.static_payment_output = static_payment_output_hu_conv;
143                 }
144         }
145         long clone_ptr() {
146                 long ret = bindings.SpendableOutputDescriptor_clone_ptr(this.ptr);
147                 Reference.reachabilityFence(this);
148                 return ret;
149         }
150
151         /**
152          * Creates a copy of the SpendableOutputDescriptor
153          */
154         public SpendableOutputDescriptor clone() {
155                 long ret = bindings.SpendableOutputDescriptor_clone(this.ptr);
156                 Reference.reachabilityFence(this);
157                 if (ret >= 0 && ret <= 4096) { return null; }
158                 org.ldk.structs.SpendableOutputDescriptor ret_hu_conv = org.ldk.structs.SpendableOutputDescriptor.constr_from_ptr(ret);
159                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
160                 return ret_hu_conv;
161         }
162
163         /**
164          * Utility method to constructs a new StaticOutput-variant SpendableOutputDescriptor
165          */
166         public static SpendableOutputDescriptor static_output(org.ldk.structs.OutPoint outpoint, org.ldk.structs.TxOut output) {
167                 long ret = bindings.SpendableOutputDescriptor_static_output(outpoint == null ? 0 : outpoint.ptr, output.ptr);
168                 Reference.reachabilityFence(outpoint);
169                 Reference.reachabilityFence(output);
170                 if (ret >= 0 && ret <= 4096) { return null; }
171                 org.ldk.structs.SpendableOutputDescriptor ret_hu_conv = org.ldk.structs.SpendableOutputDescriptor.constr_from_ptr(ret);
172                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
173                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(outpoint); };
174                 return ret_hu_conv;
175         }
176
177         /**
178          * Utility method to constructs a new DelayedPaymentOutput-variant SpendableOutputDescriptor
179          */
180         public static SpendableOutputDescriptor delayed_payment_output(org.ldk.structs.DelayedPaymentOutputDescriptor a) {
181                 long ret = bindings.SpendableOutputDescriptor_delayed_payment_output(a == null ? 0 : a.ptr);
182                 Reference.reachabilityFence(a);
183                 if (ret >= 0 && ret <= 4096) { return null; }
184                 org.ldk.structs.SpendableOutputDescriptor ret_hu_conv = org.ldk.structs.SpendableOutputDescriptor.constr_from_ptr(ret);
185                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
186                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a); };
187                 return ret_hu_conv;
188         }
189
190         /**
191          * Utility method to constructs a new StaticPaymentOutput-variant SpendableOutputDescriptor
192          */
193         public static SpendableOutputDescriptor static_payment_output(org.ldk.structs.StaticPaymentOutputDescriptor a) {
194                 long ret = bindings.SpendableOutputDescriptor_static_payment_output(a == null ? 0 : a.ptr);
195                 Reference.reachabilityFence(a);
196                 if (ret >= 0 && ret <= 4096) { return null; }
197                 org.ldk.structs.SpendableOutputDescriptor ret_hu_conv = org.ldk.structs.SpendableOutputDescriptor.constr_from_ptr(ret);
198                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
199                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a); };
200                 return ret_hu_conv;
201         }
202
203         /**
204          * Checks if two SpendableOutputDescriptors contain equal inner contents.
205          * This ignores pointers and is_owned flags and looks at the values in fields.
206          */
207         public boolean eq(org.ldk.structs.SpendableOutputDescriptor b) {
208                 boolean ret = bindings.SpendableOutputDescriptor_eq(this.ptr, b == null ? 0 : b.ptr);
209                 Reference.reachabilityFence(this);
210                 Reference.reachabilityFence(b);
211                 return ret;
212         }
213
214         @Override public boolean equals(Object o) {
215                 if (!(o instanceof SpendableOutputDescriptor)) return false;
216                 return this.eq((SpendableOutputDescriptor)o);
217         }
218         /**
219          * Serialize the SpendableOutputDescriptor object into a byte array which can be read by SpendableOutputDescriptor_read
220          */
221         public byte[] write() {
222                 byte[] ret = bindings.SpendableOutputDescriptor_write(this.ptr);
223                 Reference.reachabilityFence(this);
224                 return ret;
225         }
226
227         /**
228          * Read a SpendableOutputDescriptor from a byte array, created by SpendableOutputDescriptor_write
229          */
230         public static Result_SpendableOutputDescriptorDecodeErrorZ read(byte[] ser) {
231                 long ret = bindings.SpendableOutputDescriptor_read(ser);
232                 Reference.reachabilityFence(ser);
233                 if (ret >= 0 && ret <= 4096) { return null; }
234                 Result_SpendableOutputDescriptorDecodeErrorZ ret_hu_conv = Result_SpendableOutputDescriptorDecodeErrorZ.constr_from_ptr(ret);
235                 return ret_hu_conv;
236         }
237
238 }