Use Bytes Primitive
This commit is contained in:
@@ -23,15 +23,18 @@ import { hash256 } from '@bitauth/libauth';
|
||||
* ```
|
||||
*/
|
||||
export class BlockHeader {
|
||||
protected readonly bytes: Bytes;
|
||||
|
||||
// View of our data so that we can extract as numbers.
|
||||
private view: DataView;
|
||||
protected readonly view: DataView;
|
||||
|
||||
/**
|
||||
* Creates a new BlockHeader instance.
|
||||
* @param bytes The bytes representing our Block Header (Big Endian)
|
||||
*/
|
||||
protected constructor(private readonly bytes: Uint8Array) {
|
||||
this.view = new DataView(bytes.buffer);
|
||||
protected constructor(bytes: Bytes | Uint8Array) {
|
||||
this.bytes = Bytes.from(bytes);
|
||||
this.view = new DataView(this.bytes.buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,7 +61,7 @@ export class BlockHeader {
|
||||
* @returns A new BlockHeader instance
|
||||
* @throws Error if the byte array length is not 80
|
||||
*/
|
||||
static fromBytes(bytes: Uint8Array): BlockHeader {
|
||||
static fromBytes(bytes: Bytes | Uint8Array): BlockHeader {
|
||||
if (bytes.length !== 80) {
|
||||
throw new Error('Invalid block header length');
|
||||
}
|
||||
@@ -134,7 +137,7 @@ export class BlockHeader {
|
||||
* Serializes the block header to a byte array.
|
||||
* @returns 80-byte array containing the serialized block header
|
||||
*/
|
||||
toBytes(): Uint8Array {
|
||||
toBytes(): Bytes {
|
||||
return this.bytes;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user