X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FBestBlock.java;h=f7f60859b92da1891b5d044f2783d90e5b8a7db6;hb=ffdd56c967087cba7548599934585b8a9a3102e2;hp=cda09d30f09453df56f4cb2f34cb1c59471aeee9;hpb=12c3ea6f32816f379249a75863971a1c7e1089a1;p=ldk-java diff --git a/src/main/java/org/ldk/structs/BestBlock.java b/src/main/java/org/ldk/structs/BestBlock.java index cda09d30..f7f60859 100644 --- a/src/main/java/org/ldk/structs/BestBlock.java +++ b/src/main/java/org/ldk/structs/BestBlock.java @@ -4,6 +4,8 @@ import org.ldk.impl.bindings; import org.ldk.enums.*; import org.ldk.util.*; import java.util.Arrays; +import java.lang.ref.Reference; +import javax.annotation.Nullable; /** @@ -18,51 +20,133 @@ public class BestBlock extends CommonBase { if (ptr != 0) { bindings.BestBlock_free(ptr); } } + /** + * The block's hash + */ + public byte[] get_block_hash() { + byte[] ret = bindings.BestBlock_get_block_hash(this.ptr); + Reference.reachabilityFence(this); + return ret; + } + + /** + * The block's hash + */ + public void set_block_hash(byte[] val) { + bindings.BestBlock_set_block_hash(this.ptr, InternalUtils.check_arr_len(val, 32)); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); + } + + /** + * The height at which the block was confirmed. + */ + public int get_height() { + int ret = bindings.BestBlock_get_height(this.ptr); + Reference.reachabilityFence(this); + return ret; + } + + /** + * The height at which the block was confirmed. + */ + public void set_height(int val) { + bindings.BestBlock_set_height(this.ptr, val); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); + } + + /** + * Constructs a new BestBlock given each field + */ + public static BestBlock of(byte[] block_hash_arg, int height_arg) { + long ret = bindings.BestBlock_new(InternalUtils.check_arr_len(block_hash_arg, 32), height_arg); + Reference.reachabilityFence(block_hash_arg); + Reference.reachabilityFence(height_arg); + if (ret >= 0 && ret <= 4096) { return null; } + org.ldk.structs.BestBlock ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BestBlock(null, ret); } + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; + return ret_hu_conv; + } + + long clone_ptr() { + long ret = bindings.BestBlock_clone_ptr(this.ptr); + Reference.reachabilityFence(this); + return ret; + } + /** * Creates a copy of the BestBlock */ public BestBlock clone() { long ret = bindings.BestBlock_clone(this.ptr); - BestBlock ret_hu_conv = new BestBlock(null, ret); - ret_hu_conv.ptrs_to.add(this); + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } + org.ldk.structs.BestBlock ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BestBlock(null, ret); } + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; return ret_hu_conv; } /** - * Constructs a `BestBlock` that represents the genesis block at height 0 of the given - * network. + * Generates a non-cryptographic 64-bit hash of the BestBlock. */ - public static BestBlock from_genesis(Network network) { - long ret = bindings.BestBlock_from_genesis(network); - BestBlock ret_hu_conv = new BestBlock(null, ret); - ret_hu_conv.ptrs_to.add(ret_hu_conv); - return ret_hu_conv; + public long hash() { + long ret = bindings.BestBlock_hash(this.ptr); + Reference.reachabilityFence(this); + return ret; + } + + @Override public int hashCode() { + return (int)this.hash(); + } + /** + * Checks if two BestBlocks contain equal inner contents. + * This ignores pointers and is_owned flags and looks at the values in fields. + * Two objects with NULL inner values will be considered "equal" here. + */ + public boolean eq(org.ldk.structs.BestBlock b) { + boolean ret = bindings.BestBlock_eq(this.ptr, b.ptr); + Reference.reachabilityFence(this); + Reference.reachabilityFence(b); + if (this != null) { this.ptrs_to.add(b); }; + return ret; } + @Override public boolean equals(Object o) { + if (!(o instanceof BestBlock)) return false; + return this.eq((BestBlock)o); + } /** - * Returns a `BestBlock` as identified by the given block hash and height. + * Constructs a `BestBlock` that represents the genesis block at height 0 of the given + * network. */ - public static BestBlock of(byte[] block_hash, int height) { - long ret = bindings.BestBlock_new(block_hash, height); - BestBlock ret_hu_conv = new BestBlock(null, ret); - ret_hu_conv.ptrs_to.add(ret_hu_conv); + public static BestBlock from_network(org.ldk.enums.Network network) { + long ret = bindings.BestBlock_from_network(network); + Reference.reachabilityFence(network); + if (ret >= 0 && ret <= 4096) { return null; } + org.ldk.structs.BestBlock ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BestBlock(null, ret); } + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; return ret_hu_conv; } /** - * Returns the best block hash. + * Serialize the BestBlock object into a byte array which can be read by BestBlock_read */ - public byte[] block_hash() { - byte[] ret = bindings.BestBlock_block_hash(this.ptr); + public byte[] write() { + byte[] ret = bindings.BestBlock_write(this.ptr); + Reference.reachabilityFence(this); return ret; } /** - * Returns the best block height. + * Read a BestBlock from a byte array, created by BestBlock_write */ - public int height() { - int ret = bindings.BestBlock_height(this.ptr); - return ret; + public static Result_BestBlockDecodeErrorZ read(byte[] ser) { + long ret = bindings.BestBlock_read(ser); + Reference.reachabilityFence(ser); + if (ret >= 0 && ret <= 4096) { return null; } + Result_BestBlockDecodeErrorZ ret_hu_conv = Result_BestBlockDecodeErrorZ.constr_from_ptr(ret); + return ret_hu_conv; } }