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 BestBlock ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new BestBlock(null, ret); }
37 ret_hu_conv.ptrs_to.add(this);
42 * Constructs a `BestBlock` that represents the genesis block at height 0 of the given
45 public static BestBlock from_genesis(org.ldk.enums.Network network) {
46 long ret = bindings.BestBlock_from_genesis(network);
47 Reference.reachabilityFence(network);
48 if (ret >= 0 && ret <= 4096) { return null; }
49 BestBlock ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new BestBlock(null, ret); }
50 ret_hu_conv.ptrs_to.add(ret_hu_conv);
55 * Returns a `BestBlock` as identified by the given block hash and height.
57 public static BestBlock of(byte[] block_hash, int height) {
58 long ret = bindings.BestBlock_new(InternalUtils.check_arr_len(block_hash, 32), height);
59 Reference.reachabilityFence(block_hash);
60 Reference.reachabilityFence(height);
61 if (ret >= 0 && ret <= 4096) { return null; }
62 BestBlock ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new BestBlock(null, ret); }
63 ret_hu_conv.ptrs_to.add(ret_hu_conv);
68 * Returns the best block hash.
70 public byte[] block_hash() {
71 byte[] ret = bindings.BestBlock_block_hash(this.ptr);
72 Reference.reachabilityFence(this);
77 * Returns the best block height.
80 int ret = bindings.BestBlock_height(this.ptr);
81 Reference.reachabilityFence(this);