1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * Describes the necessary information to spend a spendable output.
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.
20 * [`SpendableOutputs`]: crate::events::Event::SpendableOutputs
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 {
28 if (ptr != 0) { bindings.SpendableOutputDescriptor_free(ptr); }
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);
35 if (raw_val.getClass() == bindings.LDKSpendableOutputDescriptor.DelayedPaymentOutput.class) {
36 return new DelayedPaymentOutput(ptr, (bindings.LDKSpendableOutputDescriptor.DelayedPaymentOutput)raw_val);
38 if (raw_val.getClass() == bindings.LDKSpendableOutputDescriptor.StaticPaymentOutput.class) {
39 return new StaticPaymentOutput(ptr, (bindings.LDKSpendableOutputDescriptor.StaticPaymentOutput)raw_val);
41 assert false; return null; // Unreachable without extending the (internal) bindings interface
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.
51 * [`get_shutdown_scriptpubkey`]: SignerProvider::get_shutdown_scriptpubkey
52 * [`get_destination_script`]: SignerProvider::get_shutdown_scriptpubkey
54 public final static class StaticOutput extends SpendableOutputDescriptor {
56 * The outpoint which is spendable.
58 public final org.ldk.structs.OutPoint outpoint;
60 * The output which is referenced by the given outpoint.
62 public final org.ldk.structs.TxOut output;
64 * The `channel_keys_id` for the channel which this output came from.
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
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.
73 * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
75 @Nullable public final byte[] channel_keys_id;
76 private StaticOutput(long ptr, bindings.LDKSpendableOutputDescriptor.StaticOutput obj) {
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;
89 * An output to a P2WSH script which can be spent with a single signature after an `OP_CSV`
92 * The witness in the spending input should be:
94 * <BIP 143 signature> <empty vector> (MINIMALIF standard rule) <provided witnessScript>
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
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).
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`].
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
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`].
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) {
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;
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.
143 * On an anchor outputs channel, the witness in the spending input is:
145 * <BIP 143 signature> <witness script>
150 * <BIP 143 signature> <payment key>
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.
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) {
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;
168 long ret = bindings.SpendableOutputDescriptor_clone_ptr(this.ptr);
169 Reference.reachabilityFence(this);
174 * Creates a copy of the SpendableOutputDescriptor
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); };
186 * Utility method to constructs a new StaticOutput-variant SpendableOutputDescriptor
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.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); };
201 * Utility method to constructs a new DelayedPaymentOutput-variant SpendableOutputDescriptor
203 public static SpendableOutputDescriptor delayed_payment_output(org.ldk.structs.DelayedPaymentOutputDescriptor a) {
204 long ret = bindings.SpendableOutputDescriptor_delayed_payment_output(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); };
214 * Utility method to constructs a new StaticPaymentOutput-variant SpendableOutputDescriptor
216 public static SpendableOutputDescriptor static_payment_output(org.ldk.structs.StaticPaymentOutputDescriptor a) {
217 long ret = bindings.SpendableOutputDescriptor_static_payment_output(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); };
227 * Generates a non-cryptographic 64-bit hash of the SpendableOutputDescriptor.
230 long ret = bindings.SpendableOutputDescriptor_hash(this.ptr);
231 Reference.reachabilityFence(this);
235 @Override public int hashCode() {
236 return (int)this.hash();
239 * Checks if two SpendableOutputDescriptors contain equal inner contents.
240 * This ignores pointers and is_owned flags and looks at the values in fields.
242 public boolean eq(org.ldk.structs.SpendableOutputDescriptor b) {
243 boolean ret = bindings.SpendableOutputDescriptor_eq(this.ptr, b.ptr);
244 Reference.reachabilityFence(this);
245 Reference.reachabilityFence(b);
249 @Override public boolean equals(Object o) {
250 if (!(o instanceof SpendableOutputDescriptor)) return false;
251 return this.eq((SpendableOutputDescriptor)o);
254 * Serialize the SpendableOutputDescriptor object into a byte array which can be read by SpendableOutputDescriptor_read
256 public byte[] write() {
257 byte[] ret = bindings.SpendableOutputDescriptor_write(this.ptr);
258 Reference.reachabilityFence(this);
263 * Read a SpendableOutputDescriptor from a byte array, created by SpendableOutputDescriptor_write
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);