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 * A `enum` signalling to the [`OutputSweeper`] that it should delay spending an output until a
13 * future block height is reached.
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class SpendingDelay extends CommonBase {
17 private SpendingDelay(Object _dummy, long ptr) { super(ptr); }
18 @Override @SuppressWarnings("deprecation")
19 protected void finalize() throws Throwable {
21 if (ptr != 0) { bindings.SpendingDelay_free(ptr); }
23 static SpendingDelay constr_from_ptr(long ptr) {
24 bindings.LDKSpendingDelay raw_val = bindings.LDKSpendingDelay_ref_from_ptr(ptr);
25 if (raw_val.getClass() == bindings.LDKSpendingDelay.Relative.class) {
26 return new Relative(ptr, (bindings.LDKSpendingDelay.Relative)raw_val);
28 if (raw_val.getClass() == bindings.LDKSpendingDelay.Absolute.class) {
29 return new Absolute(ptr, (bindings.LDKSpendingDelay.Absolute)raw_val);
31 assert false; return null; // Unreachable without extending the (internal) bindings interface
35 * A relative delay indicating we shouldn't spend the output before `cur_height + num_blocks`
38 public final static class Relative extends SpendingDelay {
40 * The number of blocks until we'll generate and broadcast the spending transaction.
42 public final int num_blocks;
43 private Relative(long ptr, bindings.LDKSpendingDelay.Relative obj) {
45 this.num_blocks = obj.num_blocks;
49 * An absolute delay indicating we shouldn't spend the output before `height` is reached.
51 public final static class Absolute extends SpendingDelay {
53 * The height at which we'll generate and broadcast the spending transaction.
55 public final int height;
56 private Absolute(long ptr, bindings.LDKSpendingDelay.Absolute obj) {
58 this.height = obj.height;
62 long ret = bindings.SpendingDelay_clone_ptr(this.ptr);
63 Reference.reachabilityFence(this);
68 * Creates a copy of the SpendingDelay
70 public SpendingDelay clone() {
71 long ret = bindings.SpendingDelay_clone(this.ptr);
72 Reference.reachabilityFence(this);
73 if (ret >= 0 && ret <= 4096) { return null; }
74 org.ldk.structs.SpendingDelay ret_hu_conv = org.ldk.structs.SpendingDelay.constr_from_ptr(ret);
75 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
80 * Utility method to constructs a new Relative-variant SpendingDelay
82 public static SpendingDelay relative(int num_blocks) {
83 long ret = bindings.SpendingDelay_relative(num_blocks);
84 Reference.reachabilityFence(num_blocks);
85 if (ret >= 0 && ret <= 4096) { return null; }
86 org.ldk.structs.SpendingDelay ret_hu_conv = org.ldk.structs.SpendingDelay.constr_from_ptr(ret);
87 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
92 * Utility method to constructs a new Absolute-variant SpendingDelay
94 public static SpendingDelay absolute(int height) {
95 long ret = bindings.SpendingDelay_absolute(height);
96 Reference.reachabilityFence(height);
97 if (ret >= 0 && ret <= 4096) { return null; }
98 org.ldk.structs.SpendingDelay ret_hu_conv = org.ldk.structs.SpendingDelay.constr_from_ptr(ret);
99 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };