X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=ts%2Fstructs%2FBestBlock.mts;h=d9dd2a1b938f12b1458f6c53a030c8aec4db2234;hb=0fcde6be16ac8c2d63bd5398d5396da5890461d7;hp=541f27e6314a5ae56a3e9f400922395c21dbbeda;hpb=2a65456aa0b540060dcf3ca707a54dc98cc3f38a;p=ldk-java diff --git a/ts/structs/BestBlock.mts b/ts/structs/BestBlock.mts index 541f27e6..d9dd2a1b 100644 --- a/ts/structs/BestBlock.mts +++ b/ts/structs/BestBlock.mts @@ -279,9 +279,11 @@ import { MultiThreadedLockableScore } from '../structs/MultiThreadedLockableScor import CommonBase from './CommonBase.mjs'; import * as bindings from '../bindings.mjs' -import * as InternalUtils from '../InternalUtils.mjs' +/** + * The best known block as identified by its hash and height. + */ export class BestBlock extends CommonBase { /* @internal */ public constructor(_dummy: object, ptr: number) { @@ -293,6 +295,9 @@ export class BestBlock extends CommonBase { return ret; } + /** + * Creates a copy of the BestBlock + */ public clone(): BestBlock { const ret: number = bindings.BestBlock_clone(this.ptr); const ret_hu_conv: BestBlock = new BestBlock(null, ret); @@ -300,6 +305,10 @@ export class BestBlock extends CommonBase { return ret_hu_conv; } + /** + * Constructs a `BestBlock` that represents the genesis block at height 0 of the given + * network. + */ public static constructor_from_genesis(network: Network): BestBlock { const ret: number = bindings.BestBlock_from_genesis(network); const ret_hu_conv: BestBlock = new BestBlock(null, ret); @@ -307,18 +316,28 @@ export class BestBlock extends CommonBase { return ret_hu_conv; } + /** + * Returns a `BestBlock` as identified by the given block hash and height. + */ public static constructor_new(block_hash: Uint8Array, height: number): BestBlock { - const ret: number = bindings.BestBlock_new(InternalUtils.check_arr_len(block_hash, 32), height); + const ret: number = bindings.BestBlock_new(bindings.encodeUint8Array(bindings.check_arr_len(block_hash, 32)), height); const ret_hu_conv: BestBlock = new BestBlock(null, ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; } + /** + * Returns the best block hash. + */ public block_hash(): Uint8Array { - const ret: Uint8Array = bindings.BestBlock_block_hash(this.ptr); - return ret; + const ret: number = bindings.BestBlock_block_hash(this.ptr); + const ret_conv: Uint8Array = bindings.decodeUint8Array(ret); + return ret_conv; } + /** + * Returns the best block height. + */ public height(): number { const ret: number = bindings.BestBlock_height(this.ptr); return ret;