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 * When on-chain outputs are created by rust-lightning (which our counterparty is not able to
13 * claim at any point in the future) an event is generated which you must track and be able to
14 * spend on-chain. The information needed to do this is provided in this enum, including the
15 * outpoint describing which txid and output index is available, the full output which exists at
16 * that txid/index, and any keys or other information required to sign.
18 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
19 public class SpendableOutputDescriptor extends CommonBase {
20 private SpendableOutputDescriptor(Object _dummy, long ptr) { super(ptr); }
21 @Override @SuppressWarnings("deprecation")
22 protected void finalize() throws Throwable {
24 if (ptr != 0) { bindings.SpendableOutputDescriptor_free(ptr); }
26 static SpendableOutputDescriptor constr_from_ptr(long ptr) {
27 bindings.LDKSpendableOutputDescriptor raw_val = bindings.LDKSpendableOutputDescriptor_ref_from_ptr(ptr);
28 if (raw_val.getClass() == bindings.LDKSpendableOutputDescriptor.StaticOutput.class) {
29 return new StaticOutput(ptr, (bindings.LDKSpendableOutputDescriptor.StaticOutput)raw_val);
31 if (raw_val.getClass() == bindings.LDKSpendableOutputDescriptor.DelayedPaymentOutput.class) {
32 return new DelayedPaymentOutput(ptr, (bindings.LDKSpendableOutputDescriptor.DelayedPaymentOutput)raw_val);
34 if (raw_val.getClass() == bindings.LDKSpendableOutputDescriptor.StaticPaymentOutput.class) {
35 return new StaticPaymentOutput(ptr, (bindings.LDKSpendableOutputDescriptor.StaticPaymentOutput)raw_val);
37 assert false; return null; // Unreachable without extending the (internal) bindings interface
41 * An output to a script which was provided via KeysInterface directly, either from
42 * `get_destination_script()` or `get_shutdown_scriptpubkey()`, thus you should already know
43 * how to spend it. No secret keys are provided as rust-lightning was never given any key.
44 * These may include outputs from a transaction punishing our counterparty or claiming an HTLC
45 * on-chain using the payment preimage or after it has timed out.
47 public final static class StaticOutput extends SpendableOutputDescriptor {
49 * The outpoint which is spendable
51 public final org.ldk.structs.OutPoint outpoint;
53 * The output which is referenced by the given outpoint.
55 public final org.ldk.structs.TxOut output;
56 private StaticOutput(long ptr, bindings.LDKSpendableOutputDescriptor.StaticOutput obj) {
58 long outpoint = obj.outpoint;
59 OutPoint outpoint_hu_conv = null; if (outpoint < 0 || outpoint > 4096) { outpoint_hu_conv = new OutPoint(null, outpoint); }
60 outpoint_hu_conv.ptrs_to.add(this);
61 this.outpoint = outpoint_hu_conv;
62 long output = obj.output;
63 TxOut output_conv = new TxOut(null, output);
64 this.output = output_conv;
68 * An output to a P2WSH script which can be spent with a single signature after a CSV delay.
70 * The witness in the spending input should be:
71 * <BIP 143 signature> <empty vector> (MINIMALIF standard rule) <provided witnessScript>
73 * Note that the nSequence field in the spending input must be set to to_self_delay
74 * (which means the transaction is not broadcastable until at least to_self_delay
75 * blocks after the outpoint confirms).
77 * These are generally the result of a \"revocable\" output to us, spendable only by us unless
78 * it is an output from an old state which we broadcast (which should never happen).
80 * To derive the delayed_payment key which is used to sign for this input, you must pass the
81 * holder delayed_payment_base_key (ie the private key which corresponds to the pubkey in
82 * Sign::pubkeys().delayed_payment_basepoint) and the provided per_commitment_point to
83 * chan_utils::derive_private_key. The public key can be generated without the secret key
84 * using chan_utils::derive_public_key and only the delayed_payment_basepoint which appears in
87 * To derive the revocation_pubkey provided here (which is used in the witness
88 * script generation), you must pass the counterparty revocation_basepoint (which appears in the
89 * call to Sign::ready_channel) and the provided per_commitment point
90 * to chan_utils::derive_public_revocation_key.
92 * The witness script which is hashed and included in the output script_pubkey may be
93 * regenerated by passing the revocation_pubkey (derived as above), our delayed_payment pubkey
94 * (derived as above), and the to_self_delay contained here to
95 * chan_utils::get_revokeable_redeemscript.
97 public final static class DelayedPaymentOutput extends SpendableOutputDescriptor {
98 public final org.ldk.structs.DelayedPaymentOutputDescriptor delayed_payment_output;
99 private DelayedPaymentOutput(long ptr, bindings.LDKSpendableOutputDescriptor.DelayedPaymentOutput obj) {
101 long delayed_payment_output = obj.delayed_payment_output;
102 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); }
103 delayed_payment_output_hu_conv.ptrs_to.add(this);
104 this.delayed_payment_output = delayed_payment_output_hu_conv;
108 * An output to a P2WPKH, spendable exclusively by our payment key (ie the private key which
109 * corresponds to the public key in Sign::pubkeys().payment_point).
110 * The witness in the spending input, is, thus, simply:
111 * <BIP 143 signature> <payment key>
113 * These are generally the result of our counterparty having broadcast the current state,
114 * allowing us to claim the non-HTLC-encumbered outputs immediately.
116 public final static class StaticPaymentOutput extends SpendableOutputDescriptor {
117 public final org.ldk.structs.StaticPaymentOutputDescriptor static_payment_output;
118 private StaticPaymentOutput(long ptr, bindings.LDKSpendableOutputDescriptor.StaticPaymentOutput obj) {
120 long static_payment_output = obj.static_payment_output;
121 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); }
122 static_payment_output_hu_conv.ptrs_to.add(this);
123 this.static_payment_output = static_payment_output_hu_conv;
127 long ret = bindings.SpendableOutputDescriptor_clone_ptr(this.ptr);
128 Reference.reachabilityFence(this);
133 * Creates a copy of the SpendableOutputDescriptor
135 public SpendableOutputDescriptor clone() {
136 long ret = bindings.SpendableOutputDescriptor_clone(this.ptr);
137 Reference.reachabilityFence(this);
138 if (ret >= 0 && ret <= 4096) { return null; }
139 org.ldk.structs.SpendableOutputDescriptor ret_hu_conv = org.ldk.structs.SpendableOutputDescriptor.constr_from_ptr(ret);
140 ret_hu_conv.ptrs_to.add(this);
145 * Utility method to constructs a new StaticOutput-variant SpendableOutputDescriptor
147 public static SpendableOutputDescriptor static_output(OutPoint outpoint, TxOut output) {
148 long ret = bindings.SpendableOutputDescriptor_static_output(outpoint == null ? 0 : outpoint.ptr & ~1, output.ptr);
149 Reference.reachabilityFence(outpoint);
150 Reference.reachabilityFence(output);
151 if (ret >= 0 && ret <= 4096) { return null; }
152 org.ldk.structs.SpendableOutputDescriptor ret_hu_conv = org.ldk.structs.SpendableOutputDescriptor.constr_from_ptr(ret);
153 ret_hu_conv.ptrs_to.add(ret_hu_conv);
158 * Utility method to constructs a new DelayedPaymentOutput-variant SpendableOutputDescriptor
160 public static SpendableOutputDescriptor delayed_payment_output(DelayedPaymentOutputDescriptor a) {
161 long ret = bindings.SpendableOutputDescriptor_delayed_payment_output(a == null ? 0 : a.ptr & ~1);
162 Reference.reachabilityFence(a);
163 if (ret >= 0 && ret <= 4096) { return null; }
164 org.ldk.structs.SpendableOutputDescriptor ret_hu_conv = org.ldk.structs.SpendableOutputDescriptor.constr_from_ptr(ret);
165 ret_hu_conv.ptrs_to.add(ret_hu_conv);
170 * Utility method to constructs a new StaticPaymentOutput-variant SpendableOutputDescriptor
172 public static SpendableOutputDescriptor static_payment_output(StaticPaymentOutputDescriptor a) {
173 long ret = bindings.SpendableOutputDescriptor_static_payment_output(a == null ? 0 : a.ptr & ~1);
174 Reference.reachabilityFence(a);
175 if (ret >= 0 && ret <= 4096) { return null; }
176 org.ldk.structs.SpendableOutputDescriptor ret_hu_conv = org.ldk.structs.SpendableOutputDescriptor.constr_from_ptr(ret);
177 ret_hu_conv.ptrs_to.add(ret_hu_conv);
182 * Serialize the SpendableOutputDescriptor object into a byte array which can be read by SpendableOutputDescriptor_read
184 public byte[] write() {
185 byte[] ret = bindings.SpendableOutputDescriptor_write(this.ptr);
186 Reference.reachabilityFence(this);
191 * Read a SpendableOutputDescriptor from a byte array, created by SpendableOutputDescriptor_write
193 public static Result_SpendableOutputDescriptorDecodeErrorZ read(byte[] ser) {
194 long ret = bindings.SpendableOutputDescriptor_read(ser);
195 Reference.reachabilityFence(ser);
196 if (ret >= 0 && ret <= 4096) { return null; }
197 Result_SpendableOutputDescriptorDecodeErrorZ ret_hu_conv = Result_SpendableOutputDescriptorDecodeErrorZ.constr_from_ptr(ret);