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
39 public final static class StaticOutput extends SpendableOutputDescriptor {
41 * The outpoint which is spendable
43 public final OutPoint outpoint;
45 * The output which is referenced by the given outpoint.
47 public final TxOut output;
48 private StaticOutput(long ptr, bindings.LDKSpendableOutputDescriptor.StaticOutput obj) {
50 long outpoint = obj.outpoint;
51 OutPoint outpoint_hu_conv = new OutPoint(null, outpoint);
52 outpoint_hu_conv.ptrs_to.add(this);
53 this.outpoint = outpoint_hu_conv;
54 long output = obj.output;
55 TxOut output_conv = new TxOut(null, output);
56 this.output = output_conv;
59 public final static class DelayedPaymentOutput extends SpendableOutputDescriptor {
60 public final DelayedPaymentOutputDescriptor delayed_payment_output;
61 private DelayedPaymentOutput(long ptr, bindings.LDKSpendableOutputDescriptor.DelayedPaymentOutput obj) {
63 long delayed_payment_output = obj.delayed_payment_output;
64 DelayedPaymentOutputDescriptor delayed_payment_output_hu_conv = new DelayedPaymentOutputDescriptor(null, delayed_payment_output);
65 delayed_payment_output_hu_conv.ptrs_to.add(this);
66 this.delayed_payment_output = delayed_payment_output_hu_conv;
69 public final static class StaticPaymentOutput extends SpendableOutputDescriptor {
70 public final StaticPaymentOutputDescriptor static_payment_output;
71 private StaticPaymentOutput(long ptr, bindings.LDKSpendableOutputDescriptor.StaticPaymentOutput obj) {
73 long static_payment_output = obj.static_payment_output;
74 StaticPaymentOutputDescriptor static_payment_output_hu_conv = new StaticPaymentOutputDescriptor(null, static_payment_output);
75 static_payment_output_hu_conv.ptrs_to.add(this);
76 this.static_payment_output = static_payment_output_hu_conv;
80 * Creates a copy of the SpendableOutputDescriptor
82 public SpendableOutputDescriptor clone() {
83 long ret = bindings.SpendableOutputDescriptor_clone(this.ptr);
84 if (ret < 1024) { return null; }
85 SpendableOutputDescriptor ret_hu_conv = SpendableOutputDescriptor.constr_from_ptr(ret);
86 ret_hu_conv.ptrs_to.add(this);
91 * Utility method to constructs a new StaticOutput-variant SpendableOutputDescriptor
93 public static SpendableOutputDescriptor static_output(OutPoint outpoint, TxOut output) {
94 long ret = bindings.SpendableOutputDescriptor_static_output(outpoint == null ? 0 : outpoint.ptr & ~1, output.ptr);
95 if (ret < 1024) { return null; }
96 SpendableOutputDescriptor ret_hu_conv = SpendableOutputDescriptor.constr_from_ptr(ret);
97 ret_hu_conv.ptrs_to.add(ret_hu_conv);
98 ret_hu_conv.ptrs_to.add(outpoint);
103 * Utility method to constructs a new DelayedPaymentOutput-variant SpendableOutputDescriptor
105 public static SpendableOutputDescriptor delayed_payment_output(DelayedPaymentOutputDescriptor a) {
106 long ret = bindings.SpendableOutputDescriptor_delayed_payment_output(a == null ? 0 : a.ptr & ~1);
107 if (ret < 1024) { return null; }
108 SpendableOutputDescriptor ret_hu_conv = SpendableOutputDescriptor.constr_from_ptr(ret);
109 ret_hu_conv.ptrs_to.add(ret_hu_conv);
110 ret_hu_conv.ptrs_to.add(a);
115 * Utility method to constructs a new StaticPaymentOutput-variant SpendableOutputDescriptor
117 public static SpendableOutputDescriptor static_payment_output(StaticPaymentOutputDescriptor a) {
118 long ret = bindings.SpendableOutputDescriptor_static_payment_output(a == null ? 0 : a.ptr & ~1);
119 if (ret < 1024) { return null; }
120 SpendableOutputDescriptor ret_hu_conv = SpendableOutputDescriptor.constr_from_ptr(ret);
121 ret_hu_conv.ptrs_to.add(ret_hu_conv);
122 ret_hu_conv.ptrs_to.add(a);
127 * Serialize the SpendableOutputDescriptor object into a byte array which can be read by SpendableOutputDescriptor_read
129 public byte[] write() {
130 byte[] ret = bindings.SpendableOutputDescriptor_write(this.ptr);
135 * Read a SpendableOutputDescriptor from a byte array, created by SpendableOutputDescriptor_write
137 public static Result_SpendableOutputDescriptorDecodeErrorZ read(byte[] ser) {
138 long ret = bindings.SpendableOutputDescriptor_read(ser);
139 if (ret < 1024) { return null; }
140 Result_SpendableOutputDescriptorDecodeErrorZ ret_hu_conv = Result_SpendableOutputDescriptorDecodeErrorZ.constr_from_ptr(ret);