1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
11 * When on-chain outputs are created by rust-lightning (which our counterparty is not able to
12 * claim at any point in the future) an event is generated which you must track and be able to
13 * spend on-chain. The information needed to do this is provided in this enum, including the
14 * outpoint describing which txid and output index is available, the full output which exists at
15 * that txid/index, and any keys or other information required to sign.
17 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
18 public class SpendableOutputDescriptor extends CommonBase {
19 private SpendableOutputDescriptor(Object _dummy, long ptr) { super(ptr); }
20 @Override @SuppressWarnings("deprecation")
21 protected void finalize() throws Throwable {
23 if (ptr != 0) { bindings.SpendableOutputDescriptor_free(ptr); }
25 static SpendableOutputDescriptor constr_from_ptr(long ptr) {
26 bindings.LDKSpendableOutputDescriptor raw_val = bindings.LDKSpendableOutputDescriptor_ref_from_ptr(ptr);
27 if (raw_val.getClass() == bindings.LDKSpendableOutputDescriptor.StaticOutput.class) {
28 return new StaticOutput(ptr, (bindings.LDKSpendableOutputDescriptor.StaticOutput)raw_val);
30 if (raw_val.getClass() == bindings.LDKSpendableOutputDescriptor.DelayedPaymentOutput.class) {
31 return new DelayedPaymentOutput(ptr, (bindings.LDKSpendableOutputDescriptor.DelayedPaymentOutput)raw_val);
33 if (raw_val.getClass() == bindings.LDKSpendableOutputDescriptor.StaticPaymentOutput.class) {
34 return new StaticPaymentOutput(ptr, (bindings.LDKSpendableOutputDescriptor.StaticPaymentOutput)raw_val);
36 assert false; return null; // Unreachable without extending the (internal) bindings interface
40 * An output to a script which was provided via KeysInterface directly, either from
41 * `get_destination_script()` or `get_shutdown_scriptpubkey()`, thus you should already know
42 * how to spend it. No secret keys are provided as rust-lightning was never given any key.
43 * These may include outputs from a transaction punishing our counterparty or claiming an HTLC
44 * on-chain using the payment preimage or after it has timed out.
46 public final static class StaticOutput extends SpendableOutputDescriptor {
48 * The outpoint which is spendable
50 public final OutPoint outpoint;
52 * The output which is referenced by the given outpoint.
54 public final TxOut output;
55 private StaticOutput(long ptr, bindings.LDKSpendableOutputDescriptor.StaticOutput obj) {
57 long outpoint = obj.outpoint;
58 OutPoint outpoint_hu_conv = null; if (outpoint < 0 || outpoint > 4096) { outpoint_hu_conv = new OutPoint(null, outpoint); }
59 outpoint_hu_conv.ptrs_to.add(this);
60 this.outpoint = outpoint_hu_conv;
61 long output = obj.output;
62 TxOut output_conv = new TxOut(null, output);
63 this.output = output_conv;
67 * An output to a P2WSH script which can be spent with a single signature after a CSV delay.
69 * The witness in the spending input should be:
70 * <BIP 143 signature> <empty vector> (MINIMALIF standard rule) <provided witnessScript>
72 * Note that the nSequence field in the spending input must be set to to_self_delay
73 * (which means the transaction is not broadcastable until at least to_self_delay
74 * blocks after the outpoint confirms).
76 * These are generally the result of a \"revocable\" output to us, spendable only by us unless
77 * it is an output from an old state which we broadcast (which should never happen).
79 * To derive the delayed_payment key which is used to sign for this input, you must pass the
80 * holder delayed_payment_base_key (ie the private key which corresponds to the pubkey in
81 * Sign::pubkeys().delayed_payment_basepoint) and the provided per_commitment_point to
82 * chan_utils::derive_private_key. The public key can be generated without the secret key
83 * using chan_utils::derive_public_key and only the delayed_payment_basepoint which appears in
86 * To derive the revocation_pubkey provided here (which is used in the witness
87 * script generation), you must pass the counterparty revocation_basepoint (which appears in the
88 * call to Sign::ready_channel) and the provided per_commitment point
89 * to chan_utils::derive_public_revocation_key.
91 * The witness script which is hashed and included in the output script_pubkey may be
92 * regenerated by passing the revocation_pubkey (derived as above), our delayed_payment pubkey
93 * (derived as above), and the to_self_delay contained here to
94 * chan_utils::get_revokeable_redeemscript.
96 public final static class DelayedPaymentOutput extends SpendableOutputDescriptor {
97 public final DelayedPaymentOutputDescriptor delayed_payment_output;
98 private DelayedPaymentOutput(long ptr, bindings.LDKSpendableOutputDescriptor.DelayedPaymentOutput obj) {
100 long delayed_payment_output = obj.delayed_payment_output;
101 DelayedPaymentOutputDescriptor delayed_payment_output_hu_conv = null; if (delayed_payment_output < 0 || delayed_payment_output > 4096) { delayed_payment_output_hu_conv = new DelayedPaymentOutputDescriptor(null, delayed_payment_output); }
102 delayed_payment_output_hu_conv.ptrs_to.add(this);
103 this.delayed_payment_output = delayed_payment_output_hu_conv;
107 * An output to a P2WPKH, spendable exclusively by our payment key (ie the private key which
108 * corresponds to the public key in Sign::pubkeys().payment_point).
109 * The witness in the spending input, is, thus, simply:
110 * <BIP 143 signature> <payment key>
112 * These are generally the result of our counterparty having broadcast the current state,
113 * allowing us to claim the non-HTLC-encumbered outputs immediately.
115 public final static class StaticPaymentOutput extends SpendableOutputDescriptor {
116 public final StaticPaymentOutputDescriptor static_payment_output;
117 private StaticPaymentOutput(long ptr, bindings.LDKSpendableOutputDescriptor.StaticPaymentOutput obj) {
119 long static_payment_output = obj.static_payment_output;
120 StaticPaymentOutputDescriptor static_payment_output_hu_conv = null; if (static_payment_output < 0 || static_payment_output > 4096) { static_payment_output_hu_conv = new StaticPaymentOutputDescriptor(null, static_payment_output); }
121 static_payment_output_hu_conv.ptrs_to.add(this);
122 this.static_payment_output = static_payment_output_hu_conv;
126 long ret = bindings.SpendableOutputDescriptor_clone_ptr(this.ptr);
131 * Creates a copy of the SpendableOutputDescriptor
133 public SpendableOutputDescriptor clone() {
134 long ret = bindings.SpendableOutputDescriptor_clone(this.ptr);
135 if (ret >= 0 && ret <= 4096) { return null; }
136 SpendableOutputDescriptor ret_hu_conv = SpendableOutputDescriptor.constr_from_ptr(ret);
137 ret_hu_conv.ptrs_to.add(this);
142 * Utility method to constructs a new StaticOutput-variant SpendableOutputDescriptor
144 public static SpendableOutputDescriptor static_output(OutPoint outpoint, TxOut output) {
145 long ret = bindings.SpendableOutputDescriptor_static_output(outpoint == null ? 0 : outpoint.ptr & ~1, output.ptr);
146 if (ret >= 0 && ret <= 4096) { return null; }
147 SpendableOutputDescriptor ret_hu_conv = SpendableOutputDescriptor.constr_from_ptr(ret);
148 ret_hu_conv.ptrs_to.add(ret_hu_conv);
153 * Utility method to constructs a new DelayedPaymentOutput-variant SpendableOutputDescriptor
155 public static SpendableOutputDescriptor delayed_payment_output(DelayedPaymentOutputDescriptor a) {
156 long ret = bindings.SpendableOutputDescriptor_delayed_payment_output(a == null ? 0 : a.ptr & ~1);
157 if (ret >= 0 && ret <= 4096) { return null; }
158 SpendableOutputDescriptor ret_hu_conv = SpendableOutputDescriptor.constr_from_ptr(ret);
159 ret_hu_conv.ptrs_to.add(ret_hu_conv);
164 * Utility method to constructs a new StaticPaymentOutput-variant SpendableOutputDescriptor
166 public static SpendableOutputDescriptor static_payment_output(StaticPaymentOutputDescriptor a) {
167 long ret = bindings.SpendableOutputDescriptor_static_payment_output(a == null ? 0 : a.ptr & ~1);
168 if (ret >= 0 && ret <= 4096) { return null; }
169 SpendableOutputDescriptor ret_hu_conv = SpendableOutputDescriptor.constr_from_ptr(ret);
170 ret_hu_conv.ptrs_to.add(ret_hu_conv);
175 * Serialize the SpendableOutputDescriptor object into a byte array which can be read by SpendableOutputDescriptor_read
177 public byte[] write() {
178 byte[] ret = bindings.SpendableOutputDescriptor_write(this.ptr);
183 * Read a SpendableOutputDescriptor from a byte array, created by SpendableOutputDescriptor_write
185 public static Result_SpendableOutputDescriptorDecodeErrorZ read(byte[] ser) {
186 long ret = bindings.SpendableOutputDescriptor_read(ser);
187 if (ret >= 0 && ret <= 4096) { return null; }
188 Result_SpendableOutputDescriptorDecodeErrorZ ret_hu_conv = Result_SpendableOutputDescriptorDecodeErrorZ.constr_from_ptr(ret);