@ethereumjs/block
Version:
Provides Block serialization and help functions
132 lines • 4.51 kB
TypeScript
import { Common } from '@ethereumjs/common';
import { Address } from '@ethereumjs/util';
import type { BlockHeaderBytes, BlockOptions, HeaderData, JSONHeader } from '../types.ts';
interface HeaderCache {
hash: Uint8Array | undefined;
}
/**
* An object that represents the block header.
*/
export declare class BlockHeader {
readonly parentHash: Uint8Array;
readonly uncleHash: Uint8Array;
readonly coinbase: Address;
readonly stateRoot: Uint8Array;
readonly transactionsTrie: Uint8Array;
readonly receiptTrie: Uint8Array;
readonly logsBloom: Uint8Array;
readonly difficulty: bigint;
readonly number: bigint;
readonly gasLimit: bigint;
readonly gasUsed: bigint;
readonly timestamp: bigint;
readonly extraData: Uint8Array;
readonly mixHash: Uint8Array;
readonly nonce: Uint8Array;
readonly baseFeePerGas?: bigint;
readonly withdrawalsRoot?: Uint8Array;
readonly blobGasUsed?: bigint;
readonly excessBlobGas?: bigint;
readonly parentBeaconBlockRoot?: Uint8Array;
readonly requestsHash?: Uint8Array;
readonly common: Common;
protected keccakFunction: (msg: Uint8Array) => Uint8Array;
protected cache: HeaderCache;
/**
* EIP-4399: After merge to PoS, `mixHash` supplanted as `prevRandao`
*/
get prevRandao(): Uint8Array<ArrayBufferLike>;
/**
* This constructor takes the values, validates them, assigns them and freezes the object.
*
* @deprecated Use the public static factory methods to assist in creating a Header object from
* varying data types. For a default empty header, use {@link createBlockHeader}.
*
*/
constructor(headerData: HeaderData, opts?: BlockOptions);
/**
* Validates correct buffer lengths, throws if invalid.
*/
protected _genericFormatValidation(): void;
/**
* Checks static parameters related to consensus algorithm
* @throws if any check fails
*/
protected _consensusFormatValidation(): void;
/**
* Validates if the block gasLimit remains in the boundaries set by the protocol.
* Throws if out of bounds.
*
* @param parentBlockHeader - the header from the parent `Block` of this header
*/
validateGasLimit(parentBlockHeader: BlockHeader): void;
/**
* Calculates the base fee for a potential next block
*/
calcNextBaseFee(): bigint;
/**
* Returns the price per unit of blob gas for a blob transaction in the current/pending block
* @returns the price in gwei per unit of blob gas spent
*/
getBlobGasPrice(): bigint;
/**
* Returns the total fee for blob gas spent for including blobs in block.
*
* @param numBlobs number of blobs in the transaction/block
* @returns the total blob gas fee for numBlobs blobs
*/
calcDataFee(numBlobs: number): bigint;
/**
* Calculates the excess blob gas for next (hopefully) post EIP 4844 block.
*/
calcNextExcessBlobGas(childCommon: Common): bigint;
/**
* Calculate the blob gas price of the block built on top of this one
* @returns The blob gas price
*/
calcNextBlobGasPrice(childCommon: Common): bigint;
/**
* Returns a Uint8Array Array of the raw Bytes in this header, in order.
*/
raw(): BlockHeaderBytes;
/**
* Returns the hash of the block header.
*/
hash(): Uint8Array;
/**
* Checks if the block header is a genesis header.
*/
isGenesis(): boolean;
/**
* Returns the canonical difficulty for this block.
*
* @param parentBlockHeader - the header from the parent `Block` of this header
*/
ethashCanonicalDifficulty(parentBlockHeader: BlockHeader): bigint;
/**
* Returns the rlp encoding of the block header.
*/
serialize(): Uint8Array;
/**
* Returns the block header in JSON format.
*/
toJSON(): JSONHeader;
/**
* Validates extra data is DAO_ExtraData for DAO_ForceExtraDataRange blocks after DAO
* activation block (see: https://blog.slock.it/hard-fork-specification-24b889e70703)
*/
protected _validateDAOExtraData(): void;
/**
* Return a compact error string representation of the object
*/
errorStr(): string;
/**
* Helper function to create an annotated error message
*
* @param msg Base error message
* @hidden
*/
protected _errorMsg(msg: string): string;
}
export {};
//# sourceMappingURL=header.d.ts.map