X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FSpendableOutputDescriptor.java;h=236a33fe07d50fd25322a433db75599bff417dcc;hb=c6bac88847b7c09560af81f00ba8dd3c2ebe3a19;hp=42dd314b731d08e1dbd5c9dc168ddff212cc1a71;hpb=110f2f104ba8fc34caa7e34e04737f36f064b050;p=ldk-java diff --git a/src/main/java/org/ldk/structs/SpendableOutputDescriptor.java b/src/main/java/org/ldk/structs/SpendableOutputDescriptor.java index 42dd314b..236a33fe 100644 --- a/src/main/java/org/ldk/structs/SpendableOutputDescriptor.java +++ b/src/main/java/org/ldk/structs/SpendableOutputDescriptor.java @@ -4,46 +4,138 @@ import org.ldk.impl.bindings; import org.ldk.enums.*; import org.ldk.util.*; import java.util.Arrays; +import javax.annotation.Nullable; + +/** + * When on-chain outputs are created by rust-lightning (which our counterparty is not able to + * claim at any point in the future) an event is generated which you must track and be able to + * spend on-chain. The information needed to do this is provided in this enum, including the + * outpoint describing which txid and output index is available, the full output which exists at + * that txid/index, and any keys or other information required to sign. + */ @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class SpendableOutputDescriptor extends CommonBase { private SpendableOutputDescriptor(Object _dummy, long ptr) { super(ptr); } - long conv_to_c() { assert false; return 0; /* Should only be called on subclasses */ } + @Override @SuppressWarnings("deprecation") + protected void finalize() throws Throwable { + super.finalize(); + if (ptr != 0) { bindings.SpendableOutputDescriptor_free(ptr); } + } static SpendableOutputDescriptor constr_from_ptr(long ptr) { bindings.LDKSpendableOutputDescriptor raw_val = bindings.LDKSpendableOutputDescriptor_ref_from_ptr(ptr); if (raw_val.getClass() == bindings.LDKSpendableOutputDescriptor.StaticOutput.class) { - return new StaticOutput(null, ptr); + return new StaticOutput(ptr, (bindings.LDKSpendableOutputDescriptor.StaticOutput)raw_val); } - if (raw_val.getClass() == bindings.LDKSpendableOutputDescriptor.DynamicOutputP2WSH.class) { - return new DynamicOutputP2WSH(null, ptr); + if (raw_val.getClass() == bindings.LDKSpendableOutputDescriptor.DelayedPaymentOutput.class) { + return new DelayedPaymentOutput(ptr, (bindings.LDKSpendableOutputDescriptor.DelayedPaymentOutput)raw_val); } - if (raw_val.getClass() == bindings.LDKSpendableOutputDescriptor.StaticOutputCounterpartyPayment.class) { - return new StaticOutputCounterpartyPayment(null, ptr); + if (raw_val.getClass() == bindings.LDKSpendableOutputDescriptor.StaticPaymentOutput.class) { + return new StaticPaymentOutput(ptr, (bindings.LDKSpendableOutputDescriptor.StaticPaymentOutput)raw_val); } assert false; return null; // Unreachable without extending the (internal) bindings interface } public final static class StaticOutput extends SpendableOutputDescriptor { - public OutPoint outpoint; - public TxOut output; - private StaticOutput(Object _dummy, long ptr) { super(null, ptr); } - @Override long conv_to_c() { return 0; /*XXX*/ } - } - public final static class DynamicOutputP2WSH extends SpendableOutputDescriptor { - public OutPoint outpoint; - public byte[] per_commitment_point; - public short to_self_delay; - public TxOut output; - public TwoTuple key_derivation_params; - public byte[] revocation_pubkey; - private DynamicOutputP2WSH(Object _dummy, long ptr) { super(null, ptr); } - @Override long conv_to_c() { return 0; /*XXX*/ } - } - public final static class StaticOutputCounterpartyPayment extends SpendableOutputDescriptor { - public OutPoint outpoint; - public TxOut output; - public TwoTuple key_derivation_params; - private StaticOutputCounterpartyPayment(Object _dummy, long ptr) { super(null, ptr); } - @Override long conv_to_c() { return 0; /*XXX*/ } + /** + * The outpoint which is spendable + */ + public final OutPoint outpoint; + /** + * The output which is referenced by the given outpoint. + */ + public final TxOut output; + private StaticOutput(long ptr, bindings.LDKSpendableOutputDescriptor.StaticOutput obj) { + super(null, ptr); + long outpoint = obj.outpoint; + OutPoint outpoint_hu_conv = null; if (outpoint < 0 || outpoint > 4096) { outpoint_hu_conv = new OutPoint(null, outpoint); } + outpoint_hu_conv.ptrs_to.add(this); + this.outpoint = outpoint_hu_conv; + long output = obj.output; + TxOut output_conv = new TxOut(null, output); + this.output = output_conv; + } + } + public final static class DelayedPaymentOutput extends SpendableOutputDescriptor { + public final DelayedPaymentOutputDescriptor delayed_payment_output; + private DelayedPaymentOutput(long ptr, bindings.LDKSpendableOutputDescriptor.DelayedPaymentOutput obj) { + super(null, ptr); + long delayed_payment_output = obj.delayed_payment_output; + 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); } + delayed_payment_output_hu_conv.ptrs_to.add(this); + this.delayed_payment_output = delayed_payment_output_hu_conv; + } + } + public final static class StaticPaymentOutput extends SpendableOutputDescriptor { + public final StaticPaymentOutputDescriptor static_payment_output; + private StaticPaymentOutput(long ptr, bindings.LDKSpendableOutputDescriptor.StaticPaymentOutput obj) { + super(null, ptr); + long static_payment_output = obj.static_payment_output; + 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); } + static_payment_output_hu_conv.ptrs_to.add(this); + this.static_payment_output = static_payment_output_hu_conv; + } + } + /** + * Creates a copy of the SpendableOutputDescriptor + */ + public SpendableOutputDescriptor clone() { + long ret = bindings.SpendableOutputDescriptor_clone(this.ptr); + if (ret >= 0 && ret <= 4096) { return null; } + SpendableOutputDescriptor ret_hu_conv = SpendableOutputDescriptor.constr_from_ptr(ret); + ret_hu_conv.ptrs_to.add(this); + return ret_hu_conv; + } + + /** + * Utility method to constructs a new StaticOutput-variant SpendableOutputDescriptor + */ + public static SpendableOutputDescriptor static_output(OutPoint outpoint, TxOut output) { + long ret = bindings.SpendableOutputDescriptor_static_output(outpoint == null ? 0 : outpoint.ptr & ~1, output.ptr); + if (ret >= 0 && ret <= 4096) { return null; } + SpendableOutputDescriptor ret_hu_conv = SpendableOutputDescriptor.constr_from_ptr(ret); + ret_hu_conv.ptrs_to.add(ret_hu_conv); + return ret_hu_conv; } + + /** + * Utility method to constructs a new DelayedPaymentOutput-variant SpendableOutputDescriptor + */ + public static SpendableOutputDescriptor delayed_payment_output(DelayedPaymentOutputDescriptor a) { + long ret = bindings.SpendableOutputDescriptor_delayed_payment_output(a == null ? 0 : a.ptr & ~1); + if (ret >= 0 && ret <= 4096) { return null; } + SpendableOutputDescriptor ret_hu_conv = SpendableOutputDescriptor.constr_from_ptr(ret); + ret_hu_conv.ptrs_to.add(ret_hu_conv); + return ret_hu_conv; + } + + /** + * Utility method to constructs a new StaticPaymentOutput-variant SpendableOutputDescriptor + */ + public static SpendableOutputDescriptor static_payment_output(StaticPaymentOutputDescriptor a) { + long ret = bindings.SpendableOutputDescriptor_static_payment_output(a == null ? 0 : a.ptr & ~1); + if (ret >= 0 && ret <= 4096) { return null; } + SpendableOutputDescriptor ret_hu_conv = SpendableOutputDescriptor.constr_from_ptr(ret); + ret_hu_conv.ptrs_to.add(ret_hu_conv); + return ret_hu_conv; + } + + /** + * Serialize the SpendableOutputDescriptor object into a byte array which can be read by SpendableOutputDescriptor_read + */ + public byte[] write() { + byte[] ret = bindings.SpendableOutputDescriptor_write(this.ptr); + return ret; + } + + /** + * Read a SpendableOutputDescriptor from a byte array, created by SpendableOutputDescriptor_write + */ + public static Result_SpendableOutputDescriptorDecodeErrorZ read(byte[] ser) { + long ret = bindings.SpendableOutputDescriptor_read(ser); + if (ret >= 0 && ret <= 4096) { return null; } + Result_SpendableOutputDescriptorDecodeErrorZ ret_hu_conv = Result_SpendableOutputDescriptorDecodeErrorZ.constr_from_ptr(ret); + return ret_hu_conv; + } + }