Skip to content

Latest commit

 

History

History
436 lines (254 loc) · 12 KB

_index_.block.md

File metadata and controls

436 lines (254 loc) · 12 KB

@ethereumjs/block"index"Block

Class: Block

An object that represents the block.

Hierarchy

  • Block

Index

Constructors

Properties

Methods

Constructors

constructor

+ new Block(header?: BlockHeader, transactions: Transaction[], uncleHeaders: BlockHeader[], opts: BlockOptions): Block

Defined in block.ts:107

This constructor takes the values, validates them, assigns them and freezes the object. Use the static factory methods to assist in creating a Block object from varying data types and options.

Parameters:

Name Type Default
header? BlockHeader -
transactions Transaction[] []
uncleHeaders BlockHeader[] []
opts BlockOptions {}

Returns: Block

Properties

_common

_common: Common

Defined in block.ts:18


header

header: BlockHeader

Defined in block.ts:14


transactions

transactions: Transaction[] = []

Defined in block.ts:15


txTrie

txTrie: Trie‹› = new Trie()

Defined in block.ts:17


uncleHeaders

uncleHeaders: BlockHeader[] = []

Defined in block.ts:16

Methods

canonicalDifficulty

canonicalDifficulty(parentBlock: Block): BN

Defined in block.ts:307

Returns the canonical difficulty for this block.

Parameters:

Name Type Description
parentBlock Block the parent of this Block

Returns: BN


genTxTrie

genTxTrie(): Promise‹void›

Defined in block.ts:168

Generates transaction trie for validation.

Returns: Promise‹void›


hash

hash(): Buffer

Defined in block.ts:147

Produces a hash the RLP of the block.

Returns: Buffer


isGenesis

isGenesis(): boolean

Defined in block.ts:154

Determines if this block is the genesis block.

Returns: boolean


raw

raw(): BlockBuffer

Defined in block.ts:136

Returns a Buffer Array of the raw Buffers of this block, in order.

Returns: BlockBuffer


serialize

serialize(): Buffer

Defined in block.ts:161

Returns the rlp encoding of the block.

Returns: Buffer


toJSON

toJSON(): JsonBlock

Defined in block.ts:333

Returns the block in JSON format.

Returns: JsonBlock


validate

validate(blockchain: Blockchain): Promise‹void›

Defined in block.ts:229

Performs the following consistency checks on the block:

  • Value checks on the header fields
  • Signature and gasLimit validation for included txs
  • Validation of the tx trie
  • Consistency checks and header validation of included uncles

Throws if invalid.

Parameters:

Name Type Description
blockchain Blockchain validate against a @ethereumjs/blockchain

Returns: Promise‹void›


validateData

validateData(): Promise‹void›

Defined in block.ts:242

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

Returns: Promise‹void›


validateDifficulty

validateDifficulty(parentBlock: Block): boolean

Defined in block.ts:316

Checks that the block's difficulty matches the canonical difficulty.

Parameters:

Name Type Description
parentBlock Block the parent of this Block

Returns: boolean


validateGasLimit

validateGasLimit(parentBlock: Block): boolean

Defined in block.ts:326

Validates if the block gasLimit remains in the boundaries set by the protocol.

Parameters:

Name Type Description
parentBlock Block the parent of this Block

Returns: boolean


validateTransactions

validateTransactions(): boolean

Defined in block.ts:201

Validates transaction signatures and minimum gas requirements.

Returns: boolean

validateTransactions(stringError: false): boolean

Defined in block.ts:202

Parameters:

Name Type
stringError false

Returns: boolean

validateTransactions(stringError: true): string[]

Defined in block.ts:203

Parameters:

Name Type
stringError true

Returns: string[]


validateTransactionsTrie

validateTransactionsTrie(): Promise‹boolean›

Defined in block.ts:182

Validates the transaction trie by generating a trie and do a check on the root hash.

Returns: Promise‹boolean›


validateUncles

validateUncles(blockchain: Blockchain): Promise‹void›

Defined in block.ts:283

Consistency checks and header validation for uncles included, in the block, if any.

Throws if invalid.

The rules of uncles are the following: Uncle Header is a valid header. Uncle Header is an orphan, i.e. it is not one of the headers of the canonical chain. Uncle Header has a parentHash which points to the canonical chain. This parentHash is within the last 7 blocks. Uncle Header is not already included as uncle in another block. Header has at most 2 uncles. Header does not count an uncle twice.

Parameters:

Name Type Description
blockchain Blockchain additionally validate against an @ethereumjs/blockchain instance

Returns: Promise‹void›


validateUnclesHash

validateUnclesHash(): boolean

Defined in block.ts:262

Validates the uncle's hash.

Returns: boolean


Static fromBlockData

fromBlockData(blockData: BlockData, opts?: BlockOptions): Block‹›

Defined in block.ts:20

Parameters:

Name Type Default
blockData BlockData {}
opts? BlockOptions -

Returns: Block‹›


Static fromRLPSerializedBlock

fromRLPSerializedBlock(serialized: Buffer, opts?: BlockOptions): Block‹›

Defined in block.ts:53

Parameters:

Name Type
serialized Buffer
opts? BlockOptions

Returns: Block‹›


Static fromValuesArray

fromValuesArray(values: BlockBuffer, opts?: BlockOptions): Block‹›

Defined in block.ts:63

Parameters:

Name Type
values BlockBuffer
opts? BlockOptions

Returns: Block‹›


Static genesis

genesis(blockData: BlockData, opts?: BlockOptions): Block‹›

Defined in block.ts:104

Alias for Block.fromBlockData() with initWithGenesisHeader set to true.

Parameters:

Name Type Default
blockData BlockData {}
opts? BlockOptions -

Returns: Block‹›