Draft Inverse Bloom Filter
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { binToHex, hexToBin, isHex, hash256 } from '@bitauth/libauth';
|
||||
import { Bytes } from './bytes.js';
|
||||
|
||||
import { hash256 } from '@bitauth/libauth';
|
||||
|
||||
export interface BlockHeaderRaw {
|
||||
version: number;
|
||||
@@ -13,6 +15,21 @@ export interface BlockHeaderRaw {
|
||||
* Represents a Bitcoin Cash block header.
|
||||
* This class handles parsing and serialization of BCH block headers between different formats
|
||||
* (raw object, bytes, hex) and provides access to individual header fields.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Import our primitives.
|
||||
* import { BlockHeader } from '@xocash/primitives';
|
||||
*
|
||||
* // Instantiate BlockHeader Primitive from Hex.
|
||||
* const blockHeader = BlockHeader.from('blockHeaderHex');
|
||||
*
|
||||
* // Output Block Header information.
|
||||
* console.log(blockHeader.getVersion());
|
||||
* console.log(blockHeader.getTimestamp());
|
||||
* console.log(blockHeader.getNonce());
|
||||
* ```
|
||||
*/
|
||||
export class BlockHeader {
|
||||
/**
|
||||
@@ -80,12 +97,7 @@ export class BlockHeader {
|
||||
* @throws Error if the hex string length is not 160
|
||||
*/
|
||||
static fromHex(hex: string): BlockHeader {
|
||||
// Ensure that the given string is hex.
|
||||
if (!isHex(hex)) {
|
||||
throw new Error('The given string is not valid hexadecimal.');
|
||||
}
|
||||
|
||||
return this.fromBytes(hexToBin(hex));
|
||||
return this.fromBytes(Bytes.fromHex(hex).toBytes());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,7 +161,7 @@ export class BlockHeader {
|
||||
* @returns 160-character hex string representing the block header
|
||||
*/
|
||||
toHex(): string {
|
||||
return binToHex(this.toBytes());
|
||||
return Bytes.fromBytes(this.toBytes()).toHex();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -193,7 +205,7 @@ export class BlockHeader {
|
||||
* @returns 64-character hex string
|
||||
*/
|
||||
getPreviousBlockHashHex(): string {
|
||||
return binToHex(this.previousBlockHash);
|
||||
return Bytes.fromBytes(this.previousBlockHash).toHex();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -201,7 +213,7 @@ export class BlockHeader {
|
||||
* @returns 64-character hex string
|
||||
*/
|
||||
getMerkleRootHex(): string {
|
||||
return binToHex(this.merkleRoot);
|
||||
return Bytes.fromBytes(this.merkleRoot).toHex();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -217,6 +229,6 @@ export class BlockHeader {
|
||||
* @returns 64-character hex string
|
||||
*/
|
||||
getHashHex(): string {
|
||||
return binToHex(this.getHash());
|
||||
return Bytes.fromBytes(this.getHash()).toHex();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user