@ethereumjs/block
Version:
Provides Block serialization and help functions
151 lines • 5.82 kB
TypeScript
import type { Common } from '@ethereumjs/common';
import type { TypedTransaction } from '@ethereumjs/tx';
import type { VerkleExecutionWitness, Withdrawal } from '@ethereumjs/util';
import { BlockHeader } from '../index.ts';
import type { BlockBytes, BlockOptions, ExecutionPayload, JSONBlock } from '../types.ts';
/**
* Class representing a block in the Ethereum network. The {@link BlockHeader} has its own
* class and can be used independently, for a block it is included in the form of the
* {@link Block.header} property.
*
* A block object can be created with one of the following constructor methods
* (separate from the Block class to allow for tree shaking):
*
* - {@link createBlock }
* - {@link createBlockFromBytesArray }
* - {@link createBlockFromRLP }
* - {@link createBlockFromRPC }
* - {@link createBlockFromJSONRPCProvider }
* - {@link createBlockFromExecutionPayload }
* - {@link createBlockFromBeaconPayloadJSON }
*/
export declare class Block {
readonly header: BlockHeader;
readonly transactions: TypedTransaction[];
readonly uncleHeaders: BlockHeader[];
readonly withdrawals?: Withdrawal[];
readonly common: Common;
protected keccakFunction: (msg: Uint8Array) => Uint8Array;
protected sha256Function: (msg: Uint8Array) => Uint8Array;
/**
* EIP-6800: Verkle Proof Data (experimental)
* null implies that the non default executionWitness might exist but not available
* and will not lead to execution of the block via vm with verkle stateless manager
*/
readonly executionWitness?: VerkleExecutionWitness | null;
protected cache: {
txTrieRoot?: Uint8Array;
withdrawalsTrieRoot?: Uint8Array;
};
/**
* This constructor takes the values, validates them, assigns them and freezes the object.
*
* @deprecated Use the static factory methods (see {@link Block} for an overview) to assist in creating
* a Block object from varying data types and options.
*/
constructor(header?: BlockHeader, transactions?: TypedTransaction[], uncleHeaders?: BlockHeader[], withdrawals?: Withdrawal[], opts?: BlockOptions, executionWitness?: VerkleExecutionWitness | null);
/**
* Returns a Array of the raw Bytes Arrays of this block, in order.
*/
raw(): BlockBytes;
/**
* Returns the hash of the block.
*/
hash(): Uint8Array;
/**
* Determines if this block is the genesis block.
*/
isGenesis(): boolean;
/**
* Returns the rlp encoding of the block.
*/
serialize(): Uint8Array;
/**
* Generates transaction trie for validation.
*/
genTxTrie(): Promise<Uint8Array>;
/**
* Validates the transaction trie by generating a trie
* and do a check on the root hash.
* @returns True if the transaction trie is valid, false otherwise
*/
transactionsTrieIsValid(): Promise<boolean>;
/**
* Validates transaction signatures and minimum gas requirements.
* @returns {string[]} an array of error strings
*/
getTransactionsValidationErrors(): string[];
/**
* Validates transaction signatures and minimum gas requirements.
* @returns True if all transactions are valid, false otherwise
*/
transactionsAreValid(): boolean;
/**
* Validates the block data, throwing if invalid.
* This can be checked on the Block itself without needing access to any parent block
* It checks:
* - All transactions are valid
* - The transactions trie is valid
* - The uncle hash is valid
* @param onlyHeader if only passed the header, skip validating txTrie and unclesHash (default: false)
* @param verifyTxs if set to `false`, will not check for transaction validation errors (default: true)
*/
validateData(onlyHeader?: boolean, verifyTxs?: boolean): Promise<void>;
/**
* Validates that blob gas fee for each transaction is greater than or equal to the
* blobGasPrice for the block and that total blob gas in block is less than maximum
* blob gas per block
* @param parentHeader header of parent block
*/
validateBlobTransactions(parentHeader: BlockHeader): void;
/**
* Validates the uncle's hash.
* @returns true if the uncle's hash is valid, false otherwise.
*/
uncleHashIsValid(): boolean;
/**
* Validates the withdrawal root
* @returns true if the withdrawals trie root is valid, false otherwise
*/
withdrawalsTrieIsValid(): Promise<boolean>;
/**
* Consistency checks for uncles included in the block, if any.
*
* Throws if invalid.
*
* The rules for uncles checked are the following:
* Header has at most 2 uncles.
* Header does not count an uncle twice.
*/
validateUncles(): void;
/**
* Validates if the block gasLimit remains in the boundaries set by the protocol.
* Throws if invalid
*
* @param parentBlock - the parent of this `Block`
*/
validateGasLimit(parentBlock: Block): void;
/**
* Returns the block in JSON format.
*/
toJSON(): JSONBlock;
/**
* Maps the block properties to the execution payload structure from the beacon chain,
* see https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md#ExecutionPayload
*
* @returns dict with the execution payload parameters with camel case naming
*/
toExecutionPayload(): ExecutionPayload;
/**
* Return a compact error string representation of the object
*/
errorStr(): string;
/**
* Internal helper function to create an annotated error message
*
* @param msg Base error message
* @hidden
*/
protected _errorMsg(msg: string): string;
}
//# sourceMappingURL=block.d.ts.map