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 * The current status of the output spend.
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class OutputSpendStatus extends CommonBase {
16 private OutputSpendStatus(Object _dummy, long ptr) { super(ptr); }
17 @Override @SuppressWarnings("deprecation")
18 protected void finalize() throws Throwable {
20 if (ptr != 0) { bindings.OutputSpendStatus_free(ptr); }
22 static OutputSpendStatus constr_from_ptr(long ptr) {
23 bindings.LDKOutputSpendStatus raw_val = bindings.LDKOutputSpendStatus_ref_from_ptr(ptr);
24 if (raw_val.getClass() == bindings.LDKOutputSpendStatus.PendingInitialBroadcast.class) {
25 return new PendingInitialBroadcast(ptr, (bindings.LDKOutputSpendStatus.PendingInitialBroadcast)raw_val);
27 if (raw_val.getClass() == bindings.LDKOutputSpendStatus.PendingFirstConfirmation.class) {
28 return new PendingFirstConfirmation(ptr, (bindings.LDKOutputSpendStatus.PendingFirstConfirmation)raw_val);
30 if (raw_val.getClass() == bindings.LDKOutputSpendStatus.PendingThresholdConfirmations.class) {
31 return new PendingThresholdConfirmations(ptr, (bindings.LDKOutputSpendStatus.PendingThresholdConfirmations)raw_val);
33 assert false; return null; // Unreachable without extending the (internal) bindings interface
37 * The output is tracked but an initial spending transaction hasn't been generated and
40 public final static class PendingInitialBroadcast extends OutputSpendStatus {
42 * The height at which we will first generate and broadcast a spending transaction.
44 public final org.ldk.structs.Option_u32Z delayed_until_height;
45 private PendingInitialBroadcast(long ptr, bindings.LDKOutputSpendStatus.PendingInitialBroadcast obj) {
47 long delayed_until_height = obj.delayed_until_height;
48 org.ldk.structs.Option_u32Z delayed_until_height_hu_conv = org.ldk.structs.Option_u32Z.constr_from_ptr(delayed_until_height);
49 if (delayed_until_height_hu_conv != null) { delayed_until_height_hu_conv.ptrs_to.add(this); };
50 this.delayed_until_height = delayed_until_height_hu_conv;
54 * A transaction spending the output has been broadcasted but is pending its first confirmation on-chain.
56 public final static class PendingFirstConfirmation extends OutputSpendStatus {
58 * The hash of the chain tip when we first broadcast a transaction spending this output.
60 public final byte[] first_broadcast_hash;
62 * The best height when we last broadcast a transaction spending this output.
64 public final int latest_broadcast_height;
66 * The transaction spending this output we last broadcasted.
68 public final byte[] latest_spending_tx;
69 private PendingFirstConfirmation(long ptr, bindings.LDKOutputSpendStatus.PendingFirstConfirmation obj) {
71 this.first_broadcast_hash = obj.first_broadcast_hash;
72 this.latest_broadcast_height = obj.latest_broadcast_height;
73 this.latest_spending_tx = obj.latest_spending_tx;
77 * A transaction spending the output has been confirmed on-chain but will be tracked until it
78 * reaches [`ANTI_REORG_DELAY`] confirmations.
80 public final static class PendingThresholdConfirmations extends OutputSpendStatus {
82 * The hash of the chain tip when we first broadcast a transaction spending this output.
84 public final byte[] first_broadcast_hash;
86 * The best height when we last broadcast a transaction spending this output.
88 public final int latest_broadcast_height;
90 * The transaction spending this output we saw confirmed on-chain.
92 public final byte[] latest_spending_tx;
94 * The height at which the spending transaction was confirmed.
96 public final int confirmation_height;
98 * The hash of the block in which the spending transaction was confirmed.
100 public final byte[] confirmation_hash;
101 private PendingThresholdConfirmations(long ptr, bindings.LDKOutputSpendStatus.PendingThresholdConfirmations obj) {
103 this.first_broadcast_hash = obj.first_broadcast_hash;
104 this.latest_broadcast_height = obj.latest_broadcast_height;
105 this.latest_spending_tx = obj.latest_spending_tx;
106 this.confirmation_height = obj.confirmation_height;
107 this.confirmation_hash = obj.confirmation_hash;
111 long ret = bindings.OutputSpendStatus_clone_ptr(this.ptr);
112 Reference.reachabilityFence(this);
117 * Creates a copy of the OutputSpendStatus
119 public OutputSpendStatus clone() {
120 long ret = bindings.OutputSpendStatus_clone(this.ptr);
121 Reference.reachabilityFence(this);
122 if (ret >= 0 && ret <= 4096) { return null; }
123 org.ldk.structs.OutputSpendStatus ret_hu_conv = org.ldk.structs.OutputSpendStatus.constr_from_ptr(ret);
124 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
129 * Utility method to constructs a new PendingInitialBroadcast-variant OutputSpendStatus
131 public static OutputSpendStatus pending_initial_broadcast(org.ldk.structs.Option_u32Z delayed_until_height) {
132 long ret = bindings.OutputSpendStatus_pending_initial_broadcast(delayed_until_height.ptr);
133 Reference.reachabilityFence(delayed_until_height);
134 if (ret >= 0 && ret <= 4096) { return null; }
135 org.ldk.structs.OutputSpendStatus ret_hu_conv = org.ldk.structs.OutputSpendStatus.constr_from_ptr(ret);
136 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
137 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(delayed_until_height); };
142 * Utility method to constructs a new PendingFirstConfirmation-variant OutputSpendStatus
144 public static OutputSpendStatus pending_first_confirmation(byte[] first_broadcast_hash, int latest_broadcast_height, byte[] latest_spending_tx) {
145 long ret = bindings.OutputSpendStatus_pending_first_confirmation(InternalUtils.check_arr_len(first_broadcast_hash, 32), latest_broadcast_height, latest_spending_tx);
146 Reference.reachabilityFence(first_broadcast_hash);
147 Reference.reachabilityFence(latest_broadcast_height);
148 Reference.reachabilityFence(latest_spending_tx);
149 if (ret >= 0 && ret <= 4096) { return null; }
150 org.ldk.structs.OutputSpendStatus ret_hu_conv = org.ldk.structs.OutputSpendStatus.constr_from_ptr(ret);
151 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
156 * Utility method to constructs a new PendingThresholdConfirmations-variant OutputSpendStatus
158 public static OutputSpendStatus pending_threshold_confirmations(byte[] first_broadcast_hash, int latest_broadcast_height, byte[] latest_spending_tx, int confirmation_height, byte[] confirmation_hash) {
159 long ret = bindings.OutputSpendStatus_pending_threshold_confirmations(InternalUtils.check_arr_len(first_broadcast_hash, 32), latest_broadcast_height, latest_spending_tx, confirmation_height, InternalUtils.check_arr_len(confirmation_hash, 32));
160 Reference.reachabilityFence(first_broadcast_hash);
161 Reference.reachabilityFence(latest_broadcast_height);
162 Reference.reachabilityFence(latest_spending_tx);
163 Reference.reachabilityFence(confirmation_height);
164 Reference.reachabilityFence(confirmation_hash);
165 if (ret >= 0 && ret <= 4096) { return null; }
166 org.ldk.structs.OutputSpendStatus ret_hu_conv = org.ldk.structs.OutputSpendStatus.constr_from_ptr(ret);
167 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
172 * Checks if two OutputSpendStatuss contain equal inner contents.
173 * This ignores pointers and is_owned flags and looks at the values in fields.
175 public boolean eq(org.ldk.structs.OutputSpendStatus b) {
176 boolean ret = bindings.OutputSpendStatus_eq(this.ptr, b.ptr);
177 Reference.reachabilityFence(this);
178 Reference.reachabilityFence(b);
182 @Override public boolean equals(Object o) {
183 if (!(o instanceof OutputSpendStatus)) return false;
184 return this.eq((OutputSpendStatus)o);
187 * Serialize the OutputSpendStatus object into a byte array which can be read by OutputSpendStatus_read
189 public byte[] write() {
190 byte[] ret = bindings.OutputSpendStatus_write(this.ptr);
191 Reference.reachabilityFence(this);
196 * Read a OutputSpendStatus from a byte array, created by OutputSpendStatus_write
198 public static Result_OutputSpendStatusDecodeErrorZ read(byte[] ser) {
199 long ret = bindings.OutputSpendStatus_read(ser);
200 Reference.reachabilityFence(ser);
201 if (ret >= 0 && ret <= 4096) { return null; }
202 Result_OutputSpendStatusDecodeErrorZ ret_hu_conv = Result_OutputSpendStatusDecodeErrorZ.constr_from_ptr(ret);