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 best known block as identified by its hash and height.
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class BestBlock extends CommonBase {
16 BestBlock(Object _dummy, long ptr) { super(ptr); }
17 @Override @SuppressWarnings("deprecation")
18 protected void finalize() throws Throwable {
20 if (ptr != 0) { bindings.BestBlock_free(ptr); }
24 long ret = bindings.BestBlock_clone_ptr(this.ptr);
25 Reference.reachabilityFence(this);
30 * Creates a copy of the BestBlock
32 public BestBlock clone() {
33 long ret = bindings.BestBlock_clone(this.ptr);
34 Reference.reachabilityFence(this);
35 if (ret >= 0 && ret <= 4096) { return null; }
36 org.ldk.structs.BestBlock ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BestBlock(null, ret); }
37 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
42 * Checks if two BestBlocks contain equal inner contents.
43 * This ignores pointers and is_owned flags and looks at the values in fields.
44 * Two objects with NULL inner values will be considered "equal" here.
46 public boolean eq(org.ldk.structs.BestBlock b) {
47 boolean ret = bindings.BestBlock_eq(this.ptr, b == null ? 0 : b.ptr);
48 Reference.reachabilityFence(this);
49 Reference.reachabilityFence(b);
50 if (this != null) { this.ptrs_to.add(b); };
54 @Override public boolean equals(Object o) {
55 if (!(o instanceof BestBlock)) return false;
56 return this.eq((BestBlock)o);
59 * Constructs a `BestBlock` that represents the genesis block at height 0 of the given
62 public static BestBlock from_network(org.ldk.enums.Network network) {
63 long ret = bindings.BestBlock_from_network(network);
64 Reference.reachabilityFence(network);
65 if (ret >= 0 && ret <= 4096) { return null; }
66 org.ldk.structs.BestBlock ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BestBlock(null, ret); }
67 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
72 * Returns a `BestBlock` as identified by the given block hash and height.
74 public static BestBlock of(byte[] block_hash, int height) {
75 long ret = bindings.BestBlock_new(InternalUtils.check_arr_len(block_hash, 32), height);
76 Reference.reachabilityFence(block_hash);
77 Reference.reachabilityFence(height);
78 if (ret >= 0 && ret <= 4096) { return null; }
79 org.ldk.structs.BestBlock ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BestBlock(null, ret); }
80 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
85 * Returns the best block hash.
87 public byte[] block_hash() {
88 byte[] ret = bindings.BestBlock_block_hash(this.ptr);
89 Reference.reachabilityFence(this);
94 * Returns the best block height.
97 int ret = bindings.BestBlock_height(this.ptr);
98 Reference.reachabilityFence(this);