Update auto-generated bindings to 0.0.103
[ldk-java] / src / main / java / org / ldk / structs / SpendableOutputDescriptor.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
8
9
10 /**
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.
16  */
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 {
22                 super.finalize();
23                 if (ptr != 0) { bindings.SpendableOutputDescriptor_free(ptr); }
24         }
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);
29                 }
30                 if (raw_val.getClass() == bindings.LDKSpendableOutputDescriptor.DelayedPaymentOutput.class) {
31                         return new DelayedPaymentOutput(ptr, (bindings.LDKSpendableOutputDescriptor.DelayedPaymentOutput)raw_val);
32                 }
33                 if (raw_val.getClass() == bindings.LDKSpendableOutputDescriptor.StaticPaymentOutput.class) {
34                         return new StaticPaymentOutput(ptr, (bindings.LDKSpendableOutputDescriptor.StaticPaymentOutput)raw_val);
35                 }
36                 assert false; return null; // Unreachable without extending the (internal) bindings interface
37         }
38
39         public final static class StaticOutput extends SpendableOutputDescriptor {
40                 /**
41                  * The outpoint which is spendable
42                 */
43                 public final OutPoint outpoint;
44                 /**
45                  * The output which is referenced by the given outpoint.
46                 */
47                 public final TxOut output;
48                 private StaticOutput(long ptr, bindings.LDKSpendableOutputDescriptor.StaticOutput obj) {
49                         super(null, ptr);
50                         long outpoint = obj.outpoint;
51                         OutPoint outpoint_hu_conv = null; if (outpoint < 0 || outpoint > 4096) { 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;
57                 }
58         }
59         public final static class DelayedPaymentOutput extends SpendableOutputDescriptor {
60                 public final DelayedPaymentOutputDescriptor delayed_payment_output;
61                 private DelayedPaymentOutput(long ptr, bindings.LDKSpendableOutputDescriptor.DelayedPaymentOutput obj) {
62                         super(null, ptr);
63                         long delayed_payment_output = obj.delayed_payment_output;
64                         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); }
65                         delayed_payment_output_hu_conv.ptrs_to.add(this);
66                         this.delayed_payment_output = delayed_payment_output_hu_conv;
67                 }
68         }
69         public final static class StaticPaymentOutput extends SpendableOutputDescriptor {
70                 public final StaticPaymentOutputDescriptor static_payment_output;
71                 private StaticPaymentOutput(long ptr, bindings.LDKSpendableOutputDescriptor.StaticPaymentOutput obj) {
72                         super(null, ptr);
73                         long static_payment_output = obj.static_payment_output;
74                         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); }
75                         static_payment_output_hu_conv.ptrs_to.add(this);
76                         this.static_payment_output = static_payment_output_hu_conv;
77                 }
78         }
79         /**
80          * Creates a copy of the SpendableOutputDescriptor
81          */
82         public SpendableOutputDescriptor clone() {
83                 long ret = bindings.SpendableOutputDescriptor_clone(this.ptr);
84                 if (ret >= 0 && ret <= 4096) { return null; }
85                 SpendableOutputDescriptor ret_hu_conv = SpendableOutputDescriptor.constr_from_ptr(ret);
86                 ret_hu_conv.ptrs_to.add(this);
87                 return ret_hu_conv;
88         }
89
90         /**
91          * Utility method to constructs a new StaticOutput-variant SpendableOutputDescriptor
92          */
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 >= 0 && ret <= 4096) { return null; }
96                 SpendableOutputDescriptor ret_hu_conv = SpendableOutputDescriptor.constr_from_ptr(ret);
97                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
98                 return ret_hu_conv;
99         }
100
101         /**
102          * Utility method to constructs a new DelayedPaymentOutput-variant SpendableOutputDescriptor
103          */
104         public static SpendableOutputDescriptor delayed_payment_output(DelayedPaymentOutputDescriptor a) {
105                 long ret = bindings.SpendableOutputDescriptor_delayed_payment_output(a == null ? 0 : a.ptr & ~1);
106                 if (ret >= 0 && ret <= 4096) { return null; }
107                 SpendableOutputDescriptor ret_hu_conv = SpendableOutputDescriptor.constr_from_ptr(ret);
108                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
109                 return ret_hu_conv;
110         }
111
112         /**
113          * Utility method to constructs a new StaticPaymentOutput-variant SpendableOutputDescriptor
114          */
115         public static SpendableOutputDescriptor static_payment_output(StaticPaymentOutputDescriptor a) {
116                 long ret = bindings.SpendableOutputDescriptor_static_payment_output(a == null ? 0 : a.ptr & ~1);
117                 if (ret >= 0 && ret <= 4096) { return null; }
118                 SpendableOutputDescriptor ret_hu_conv = SpendableOutputDescriptor.constr_from_ptr(ret);
119                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
120                 return ret_hu_conv;
121         }
122
123         /**
124          * Serialize the SpendableOutputDescriptor object into a byte array which can be read by SpendableOutputDescriptor_read
125          */
126         public byte[] write() {
127                 byte[] ret = bindings.SpendableOutputDescriptor_write(this.ptr);
128                 return ret;
129         }
130
131         /**
132          * Read a SpendableOutputDescriptor from a byte array, created by SpendableOutputDescriptor_write
133          */
134         public static Result_SpendableOutputDescriptorDecodeErrorZ read(byte[] ser) {
135                 long ret = bindings.SpendableOutputDescriptor_read(ser);
136                 if (ret >= 0 && ret <= 4096) { return null; }
137                 Result_SpendableOutputDescriptorDecodeErrorZ ret_hu_conv = Result_SpendableOutputDescriptorDecodeErrorZ.constr_from_ptr(ret);
138                 return ret_hu_conv;
139         }
140
141 }