From fc4d0f93ca6ffac97e6e162cacd43e2d85921fd6 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Tue, 30 Aug 2022 00:34:42 -0400 Subject: [PATCH 1/4] block: remove isTruthy and isFalsy --- packages/block/src/block.ts | 6 +++--- packages/block/src/from-rpc.ts | 27 +++++++++++++++---------- packages/block/src/header-from-rpc.ts | 13 ++++++------ packages/block/src/header.ts | 24 +++++++++++++--------- packages/block/src/helpers.ts | 4 ++-- packages/block/src/types.ts | 29 +++++++++++++++++++++++++++ packages/block/test/block.spec.ts | 2 +- packages/block/test/from-rpc.spec.ts | 18 ++++++++++------- packages/block/test/util.ts | 4 ++-- packages/tx/src/types.ts | 27 ++++++++++++++++++++++++- 10 files changed, 112 insertions(+), 42 deletions(-) diff --git a/packages/block/src/block.ts b/packages/block/src/block.ts index 579d1daa33..e4426e3fbc 100644 --- a/packages/block/src/block.ts +++ b/packages/block/src/block.ts @@ -2,7 +2,7 @@ import { ConsensusType } from '@ethereumjs/common' import { RLP } from '@ethereumjs/rlp' import { Trie } from '@ethereumjs/trie' import { Capability, TransactionFactory } from '@ethereumjs/tx' -import { KECCAK256_RLP, arrToBufArr, bufArrToArr, bufferToHex, isTruthy } from '@ethereumjs/util' +import { KECCAK256_RLP, arrToBufArr, bufArrToArr, bufferToHex } from '@ethereumjs/util' import { keccak256 } from 'ethereum-cryptography/keccak' import { BlockHeader } from './header' @@ -104,7 +104,7 @@ export class Block { // parse transactions const transactions = [] - for (const txData of isTruthy(txsData) ? txsData : []) { + for (const txData of txsData ?? []) { transactions.push( TransactionFactory.fromBlockBodyData(txData, { ...opts, @@ -130,7 +130,7 @@ export class Block { if (opts?.hardforkByTTD !== undefined) { uncleOpts.hardforkByBlockNumber = true } - for (const uncleHeaderData of isTruthy(uhsData) ? uhsData : []) { + for (const uncleHeaderData of uhsData ?? []) { uncleHeaders.push(BlockHeader.fromValuesArray(uncleHeaderData, uncleOpts)) } diff --git a/packages/block/src/from-rpc.ts b/packages/block/src/from-rpc.ts index e6fc4841a7..cc4178f276 100644 --- a/packages/block/src/from-rpc.ts +++ b/packages/block/src/from-rpc.ts @@ -1,12 +1,12 @@ import { TransactionFactory } from '@ethereumjs/tx' -import { isTruthy, setLengthLeft, toBuffer } from '@ethereumjs/util' +import { setLengthLeft, toBuffer } from '@ethereumjs/util' import { blockHeaderFromRpc } from './header-from-rpc' import { numberToHex } from './helpers' import { Block } from './index' -import type { BlockOptions } from './index' +import type { BlockOptions, JsonRpcBlock } from './index' import type { TxData, TypedTransaction } from '@ethereumjs/tx' function normalizeTxParams(_txParams: any) { @@ -20,7 +20,10 @@ function normalizeTxParams(_txParams: any) { txParams.value = numberToHex(txParams.value) // strict byte length checking - txParams.to = isTruthy(txParams.to) ? setLengthLeft(toBuffer(txParams.to), 20) : null + txParams.to = + txParams.to !== null && txParams.to !== undefined + ? setLengthLeft(toBuffer(txParams.to), 20) + : null // v as raw signature value {0,1} // v is the recovery bit and can be either {0,1} or {27,28}. @@ -38,17 +41,19 @@ function normalizeTxParams(_txParams: any) { * @param uncles - Optional list of Ethereum JSON RPC of uncles (eth_getUncleByBlockHashAndIndex) * @param options - An object describing the blockchain */ -export function blockFromRpc(blockParams: any, uncles: any[] = [], options?: BlockOptions) { +export function blockFromRpc( + blockParams: JsonRpcBlock, + uncles: any[] = [], + options?: BlockOptions +) { const header = blockHeaderFromRpc(blockParams, options) const transactions: TypedTransaction[] = [] - if (isTruthy(blockParams.transactions)) { - const opts = { common: header._common } - for (const _txParams of blockParams.transactions) { - const txParams = normalizeTxParams(_txParams) - const tx = TransactionFactory.fromTxData(txParams as TxData, opts) - transactions.push(tx) - } + const opts = { common: header._common } + for (const _txParams of blockParams.transactions) { + const txParams = normalizeTxParams(_txParams) + const tx = TransactionFactory.fromTxData(txParams as TxData, opts) + transactions.push(tx) } const uncleHeaders = uncles.map((uh) => blockHeaderFromRpc(uh, options)) diff --git a/packages/block/src/header-from-rpc.ts b/packages/block/src/header-from-rpc.ts index 00bb2b6b3b..3da0e739e9 100644 --- a/packages/block/src/header-from-rpc.ts +++ b/packages/block/src/header-from-rpc.ts @@ -1,9 +1,7 @@ -import { isTruthy } from '@ethereumjs/util' - import { BlockHeader } from './header' import { numberToHex } from './helpers' -import type { BlockOptions } from './types' +import type { BlockOptions, JsonRpcBlock } from './types' /** * Creates a new block header object from Ethereum JSON RPC. @@ -11,14 +9,17 @@ import type { BlockOptions } from './types' * @param blockParams - Ethereum JSON RPC of block (eth_getBlockByNumber) * @param options - An object describing the blockchain */ -export function blockHeaderFromRpc(blockParams: any, options?: BlockOptions) { +export function blockHeaderFromRpc( + blockParams: Omit & { receiptRoot?: string; receiptsRoot?: string }, + options?: BlockOptions +) { const { parentHash, sha3Uncles, miner, stateRoot, transactionsRoot, - receiptRoot, + receiptRoot, // TODO: Investigate dual receiptRoot/receiptsRoot usage. receiptsRoot, logsBloom, difficulty, @@ -39,7 +40,7 @@ export function blockHeaderFromRpc(blockParams: any, options?: BlockOptions) { coinbase: miner, stateRoot, transactionsTrie: transactionsRoot, - receiptTrie: isTruthy(receiptRoot) ? receiptRoot : receiptsRoot, + receiptTrie: receiptRoot ?? receiptsRoot, logsBloom, difficulty: numberToHex(difficulty), number, diff --git a/packages/block/src/header.ts b/packages/block/src/header.ts index b7bd067973..f99e584208 100644 --- a/packages/block/src/header.ts +++ b/packages/block/src/header.ts @@ -14,8 +14,6 @@ import { bufferToHex, ecrecover, ecsign, - isFalsy, - isTruthy, toType, zeros, } from '@ethereumjs/util' @@ -160,9 +158,9 @@ export class BlockHeader { const parentHash = toType(headerData.parentHash, TypeOutput.Buffer) ?? defaults.parentHash const uncleHash = toType(headerData.uncleHash, TypeOutput.Buffer) ?? defaults.uncleHash - const coinbase = isTruthy(headerData.coinbase) - ? new Address(toType(headerData.coinbase, TypeOutput.Buffer)) - : defaults.coinbase + const coinbase = new Address( + toType(headerData.coinbase ?? defaults.coinbase, TypeOutput.Buffer) + ) const stateRoot = toType(headerData.stateRoot, TypeOutput.Buffer) ?? defaults.stateRoot const transactionsTrie = toType(headerData.transactionsTrie, TypeOutput.Buffer) ?? defaults.transactionsTrie @@ -300,9 +298,13 @@ export class BlockHeader { throw new Error(msg) } const londonHfBlock = this._common.hardforkBlock(Hardfork.London) - if (isTruthy(londonHfBlock) && this.number === londonHfBlock) { + if ( + typeof londonHfBlock === 'bigint' && + londonHfBlock !== BigInt(0) && + this.number === londonHfBlock + ) { const initialBaseFee = this._common.param('gasConfig', 'initialBaseFee') - if (this.baseFeePerGas! !== initialBaseFee) { + if (this.baseFeePerGas !== initialBaseFee) { const msg = this._errorMsg('Initial EIP1559 block does not have initial base fee') throw new Error(msg) } @@ -404,7 +406,11 @@ export class BlockHeader { // EIP-1559: assume double the parent gas limit on fork block // to adopt to the new gas target centered logic const londonHardforkBlock = this._common.hardforkBlock(Hardfork.London) - if (isTruthy(londonHardforkBlock) && this.number === londonHardforkBlock) { + if ( + typeof londonHardforkBlock === 'bigint' && + londonHardforkBlock !== BigInt(0) && + this.number === londonHardforkBlock + ) { const elasticity = this._common.param('gasConfig', 'elasticityMultiplier') parentGasLimit = parentGasLimit * elasticity } @@ -774,7 +780,7 @@ export class BlockHeader { return } const DAOActivationBlock = this._common.hardforkBlock(Hardfork.Dao) - if (isFalsy(DAOActivationBlock) || this.number < DAOActivationBlock) { + if (DAOActivationBlock === null || this.number < DAOActivationBlock) { return } const DAO_ExtraData = Buffer.from('64616f2d686172642d666f726b', 'hex') diff --git a/packages/block/src/helpers.ts b/packages/block/src/helpers.ts index 353e313dce..1c05c39494 100644 --- a/packages/block/src/helpers.ts +++ b/packages/block/src/helpers.ts @@ -1,4 +1,4 @@ -import { TypeOutput, isFalsy, isHexString, toType } from '@ethereumjs/util' +import { TypeOutput, isHexString, toType } from '@ethereumjs/util' import type { BlockHeaderBuffer, HeaderData } from './types' @@ -7,7 +7,7 @@ import type { BlockHeaderBuffer, HeaderData } from './types' * @param {string} input string to check, convert, and return */ export const numberToHex = function (input?: string) { - if (isFalsy(input)) return undefined + if (input === undefined) return undefined if (!isHexString(input)) { const regex = new RegExp(/^\d+$/) // test to make sure input contains only digits if (!regex.test(input)) { diff --git a/packages/block/src/types.ts b/packages/block/src/types.ts index 3365efd46a..58cdd141cc 100644 --- a/packages/block/src/types.ts +++ b/packages/block/src/types.ts @@ -3,6 +3,7 @@ import type { Common } from '@ethereumjs/common' import type { AccessListEIP2930TxData, FeeMarketEIP1559TxData, + JsonRpcTx, JsonTx, TxData, } from '@ethereumjs/tx' @@ -150,3 +151,31 @@ export interface JsonHeader { nonce?: string baseFeePerGas?: string } + +/* + * Based on https://eth.wiki/json-rpc/API + */ +export interface JsonRpcBlock { + number: string // the block number. null when pending block. + hash: string // hash of the block. null when pending block. + parentHash: string // hash of the parent block. + mixHash?: string // bit hash which proves combined with the nonce that a sufficient amount of computation has been carried out on this block. + nonce: string // hash of the generated proof-of-work. null when pending block. + sha3Uncles: string // SHA3 of the uncles data in the block. + logsBloom: string // the bloom filter for the logs of the block. null when pending block. + transactionsRoot: string // the root of the transaction trie of the block. + stateRoot: string // the root of the final state trie of the block. + receiptRoot?: string // the root of the receipts trie of the block. + receiptsRoot: string // the root of the receipts trie of the block. + miner: string // the address of the beneficiary to whom the mining rewards were given. + difficulty: string // integer of the difficulty for this block. + totalDifficulty: string // integer of the total difficulty of the chain until this block. + extraData: string // the “extra data” field of this block. + size: string // integer the size of this block in bytes. + gasLimit: string // the maximum gas allowed in this block. + gasUsed: string // the total used gas by all transactions in this block. + timestamp: string // the unix timestamp for when the block was collated. + transactions: Array // Array of transaction objects, or 32 Bytes transaction hashes depending on the last given parameter. + uncles: string[] // Array of uncle hashes + baseFeePerGas?: string // If EIP-1559 is enabled for this block, returns the base fee per gas +} diff --git a/packages/block/test/block.spec.ts b/packages/block/test/block.spec.ts index 60ba7e802b..1ac920f962 100644 --- a/packages/block/test/block.spec.ts +++ b/packages/block/test/block.spec.ts @@ -176,7 +176,7 @@ tape('[Block]: block functions', function (t) { const common = new Common({ chain: Chain.Goerli, hardfork: Hardfork.Chainstart }) try { - blockFromRpc(testDataFromRpcGoerli, [], { common }) + blockFromRpc(testDataFromRpcGoerli as any, [], { common }) st.pass('does not throw') } catch (error: any) { st.fail('error thrown') diff --git a/packages/block/test/from-rpc.spec.ts b/packages/block/test/from-rpc.spec.ts index 7cba2bfda0..ab14c32570 100644 --- a/packages/block/test/from-rpc.spec.ts +++ b/packages/block/test/from-rpc.spec.ts @@ -16,14 +16,14 @@ tape('[fromRPC]: block #2924874', function (t) { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul }) t.test('should create a block with transactions with valid signatures', function (st) { - const block = blockFromRpc(blockData, [], { common }) + const block = blockFromRpc(blockData as any, [], { common }) const allValid = block.transactions.every((tx) => tx.verifySignature()) st.equal(allValid, true, 'all transaction signatures are valid') st.end() }) t.test('should create a block header with the correct hash', function (st) { - const block = blockHeaderFromRpc(blockData, { common }) + const block = blockHeaderFromRpc(blockData as any, { common }) const hash = Buffer.from(blockData.hash.slice(2), 'hex') st.ok(block.hash().equals(hash)) st.end() @@ -45,7 +45,7 @@ tape('[fromRPC]:', function (t) { const blockDataTransactionValueAsInteger = blockData blockDataTransactionValueAsInteger.transactions[0].value = valueAsIntegerString const blockFromTransactionValueAsInteger = blockFromRpc( - blockDataTransactionValueAsInteger, + blockDataTransactionValueAsInteger as any, undefined, { common } ) @@ -66,7 +66,7 @@ tape('[fromRPC]:', function (t) { const blockDataTransactionGasPriceAsInteger = blockData blockDataTransactionGasPriceAsInteger.transactions[0].gasPrice = gasPriceAsIntegerString const blockFromTransactionGasPriceAsInteger = blockFromRpc( - blockDataTransactionGasPriceAsInteger, + blockDataTransactionGasPriceAsInteger as any, undefined, { common } ) @@ -83,9 +83,13 @@ tape('[fromRPC]:', function (t) { 'should create a block given json data that includes a difficulty parameter of type integer string', function (st) { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London }) - const blockDifficultyAsInteger = blockFromRpc(blockDataDifficultyAsInteger, undefined, { - common, - }) + const blockDifficultyAsInteger = blockFromRpc( + blockDataDifficultyAsInteger as any, + undefined, + { + common, + } + ) st.equal( blockDifficultyAsInteger.header.difficulty.toString(), blockDataDifficultyAsInteger.difficulty diff --git a/packages/block/test/util.ts b/packages/block/test/util.ts index e3f7fcb23e..7f4f0c9b91 100644 --- a/packages/block/test/util.ts +++ b/packages/block/test/util.ts @@ -1,6 +1,6 @@ import { Chain, Common, Hardfork } from '@ethereumjs/common' import { RLP } from '@ethereumjs/rlp' -import { bufArrToArr, isTruthy } from '@ethereumjs/util' +import { bufArrToArr } from '@ethereumjs/util' import { keccak256 } from 'ethereum-cryptography/keccak' import { Block } from '../src' @@ -33,7 +33,7 @@ function createBlock( const londonHfBlock = common.hardforkBlock(Hardfork.London) const baseFeePerGas = - isTruthy(londonHfBlock) && number > londonHfBlock + typeof londonHfBlock === 'bigint' && londonHfBlock !== BigInt(0) && number > londonHfBlock ? parentBlock.header.calcNextBaseFee() : undefined diff --git a/packages/tx/src/types.ts b/packages/tx/src/types.ts index cdadf6eca1..f0cf7fc25b 100644 --- a/packages/tx/src/types.ts +++ b/packages/tx/src/types.ts @@ -16,7 +16,7 @@ export enum Capability { EIP155ReplayProtection = 155, /** - * Tx supports EIP-1559 gas fee market mechansim + * Tx supports EIP-1559 gas fee market mechanism * See: [1559](https://eips.ethereum.org/EIPS/eip-1559) Fee Market EIP */ EIP1559FeeMarket = 1559, @@ -263,3 +263,28 @@ export interface JsonTx { maxPriorityFeePerGas?: string maxFeePerGas?: string } + +/* + * Based on https://ethereum.org/en/developers/docs/apis/json-rpc/ + */ +export interface JsonRpcTx { + blockHash: string | null // DATA, 32 Bytes - hash of the block where this transaction was in. null when it's pending. + blockNumber: string | null // QUANTITY - block number where this transaction was in. null when it's pending. + from: string // DATA, 20 Bytes - address of the sender. + gas: string // QUANTITY - gas provided by the sender. + gasPrice: string // QUANTITY - gas price provided by the sender in wei. If EIP-1559 tx, defaults to maxFeePerGas. + maxFeePerGas?: string // QUANTITY - max total fee per gas provided by the sender in wei. + maxPriorityFeePerGas?: string // QUANTITY - max priority fee per gas provided by the sender in wei. + type: string // QUANTITY - EIP-2718 Typed Transaction type + accessList?: JsonTx['accessList'] // EIP-2930 access list + chainId?: string // Chain ID that this transaction is valid on. + hash: string // DATA, 32 Bytes - hash of the transaction. + input: string // DATA - the data send along with the transaction. + nonce: string // QUANTITY - the number of transactions made by the sender prior to this one. + to: string | null /// DATA, 20 Bytes - address of the receiver. null when it's a contract creation transaction. + transactionIndex: string | null // QUANTITY - integer of the transactions index position in the block. null when it's pending. + value: string // QUANTITY - value transferred in Wei. + v: string // QUANTITY - ECDSA recovery id + r: string // DATA, 32 Bytes - ECDSA signature r + s: string // DATA, 32 Bytes - ECDSA signature s +} From 33507c65930c61d88819c251c34ab035c6dd5e6d Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Tue, 30 Aug 2022 17:18:39 -0400 Subject: [PATCH 2/4] block: address review --- packages/block/test/block.spec.ts | 4 ++-- packages/block/test/from-rpc.spec.ts | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/block/test/block.spec.ts b/packages/block/test/block.spec.ts index 1ac920f962..a7cd917d88 100644 --- a/packages/block/test/block.spec.ts +++ b/packages/block/test/block.spec.ts @@ -15,7 +15,7 @@ import * as testDataPreLondon2 from './testdata/testdata_pre-london-2.json' import * as testDataPreLondon from './testdata/testdata_pre-london.json' import * as testnetMerge from './testdata/testnetMerge.json' -import type { BlockBuffer } from '../src' +import type { BlockBuffer, JsonRpcBlock } from '../src' import type { NestedUint8Array } from '@ethereumjs/util' tape('[Block]: block functions', function (t) { @@ -176,7 +176,7 @@ tape('[Block]: block functions', function (t) { const common = new Common({ chain: Chain.Goerli, hardfork: Hardfork.Chainstart }) try { - blockFromRpc(testDataFromRpcGoerli as any, [], { common }) + blockFromRpc(testDataFromRpcGoerli as JsonRpcBlock, [], { common }) st.pass('does not throw') } catch (error: any) { st.fail('error thrown') diff --git a/packages/block/test/from-rpc.spec.ts b/packages/block/test/from-rpc.spec.ts index ab14c32570..bf0ec6c838 100644 --- a/packages/block/test/from-rpc.spec.ts +++ b/packages/block/test/from-rpc.spec.ts @@ -10,20 +10,21 @@ import * as blockDataWithUncles from './testdata/testdata-from-rpc-with-uncles.j import * as uncleBlockData from './testdata/testdata-from-rpc-with-uncles_uncle-block-data.json' import * as blockData from './testdata/testdata-from-rpc.json' +import type { JsonRpcBlock } from '../src/types' import type { Transaction } from '@ethereumjs/tx' tape('[fromRPC]: block #2924874', function (t) { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul }) t.test('should create a block with transactions with valid signatures', function (st) { - const block = blockFromRpc(blockData as any, [], { common }) + const block = blockFromRpc(blockData as JsonRpcBlock, [], { common }) const allValid = block.transactions.every((tx) => tx.verifySignature()) st.equal(allValid, true, 'all transaction signatures are valid') st.end() }) t.test('should create a block header with the correct hash', function (st) { - const block = blockHeaderFromRpc(blockData as any, { common }) + const block = blockHeaderFromRpc(blockData as JsonRpcBlock, { common }) const hash = Buffer.from(blockData.hash.slice(2), 'hex') st.ok(block.hash().equals(hash)) st.end() @@ -45,7 +46,7 @@ tape('[fromRPC]:', function (t) { const blockDataTransactionValueAsInteger = blockData blockDataTransactionValueAsInteger.transactions[0].value = valueAsIntegerString const blockFromTransactionValueAsInteger = blockFromRpc( - blockDataTransactionValueAsInteger as any, + blockDataTransactionValueAsInteger as JsonRpcBlock, undefined, { common } ) @@ -66,7 +67,7 @@ tape('[fromRPC]:', function (t) { const blockDataTransactionGasPriceAsInteger = blockData blockDataTransactionGasPriceAsInteger.transactions[0].gasPrice = gasPriceAsIntegerString const blockFromTransactionGasPriceAsInteger = blockFromRpc( - blockDataTransactionGasPriceAsInteger as any, + blockDataTransactionGasPriceAsInteger as JsonRpcBlock, undefined, { common } ) @@ -84,7 +85,7 @@ tape('[fromRPC]:', function (t) { function (st) { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London }) const blockDifficultyAsInteger = blockFromRpc( - blockDataDifficultyAsInteger as any, + blockDataDifficultyAsInteger as JsonRpcBlock, undefined, { common, From e058606de009f410073ccf2a830090c8ecd1c64a Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Wed, 31 Aug 2022 08:23:21 -0400 Subject: [PATCH 3/4] block: fix type errors --- packages/block/test/block.spec.ts | 2 +- packages/block/test/from-rpc.spec.ts | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/block/test/block.spec.ts b/packages/block/test/block.spec.ts index a7cd917d88..520f0c22cd 100644 --- a/packages/block/test/block.spec.ts +++ b/packages/block/test/block.spec.ts @@ -176,7 +176,7 @@ tape('[Block]: block functions', function (t) { const common = new Common({ chain: Chain.Goerli, hardfork: Hardfork.Chainstart }) try { - blockFromRpc(testDataFromRpcGoerli as JsonRpcBlock, [], { common }) + blockFromRpc(testDataFromRpcGoerli as unknown as JsonRpcBlock, [], { common }) st.pass('does not throw') } catch (error: any) { st.fail('error thrown') diff --git a/packages/block/test/from-rpc.spec.ts b/packages/block/test/from-rpc.spec.ts index bf0ec6c838..8d97ccf770 100644 --- a/packages/block/test/from-rpc.spec.ts +++ b/packages/block/test/from-rpc.spec.ts @@ -17,14 +17,14 @@ tape('[fromRPC]: block #2924874', function (t) { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul }) t.test('should create a block with transactions with valid signatures', function (st) { - const block = blockFromRpc(blockData as JsonRpcBlock, [], { common }) + const block = blockFromRpc(blockData as unknown as JsonRpcBlock, [], { common }) const allValid = block.transactions.every((tx) => tx.verifySignature()) st.equal(allValid, true, 'all transaction signatures are valid') st.end() }) t.test('should create a block header with the correct hash', function (st) { - const block = blockHeaderFromRpc(blockData as JsonRpcBlock, { common }) + const block = blockHeaderFromRpc(blockData as unknown as JsonRpcBlock, { common }) const hash = Buffer.from(blockData.hash.slice(2), 'hex') st.ok(block.hash().equals(hash)) st.end() @@ -46,7 +46,7 @@ tape('[fromRPC]:', function (t) { const blockDataTransactionValueAsInteger = blockData blockDataTransactionValueAsInteger.transactions[0].value = valueAsIntegerString const blockFromTransactionValueAsInteger = blockFromRpc( - blockDataTransactionValueAsInteger as JsonRpcBlock, + blockDataTransactionValueAsInteger as unknown as JsonRpcBlock, undefined, { common } ) @@ -67,7 +67,7 @@ tape('[fromRPC]:', function (t) { const blockDataTransactionGasPriceAsInteger = blockData blockDataTransactionGasPriceAsInteger.transactions[0].gasPrice = gasPriceAsIntegerString const blockFromTransactionGasPriceAsInteger = blockFromRpc( - blockDataTransactionGasPriceAsInteger as JsonRpcBlock, + blockDataTransactionGasPriceAsInteger as unknown as JsonRpcBlock, undefined, { common } ) @@ -85,7 +85,7 @@ tape('[fromRPC]:', function (t) { function (st) { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London }) const blockDifficultyAsInteger = blockFromRpc( - blockDataDifficultyAsInteger as JsonRpcBlock, + blockDataDifficultyAsInteger as unknown as JsonRpcBlock, undefined, { common, From 2239bf6dfeef0d99d4de18423c55852a7edc009a Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Wed, 31 Aug 2022 10:06:31 -0400 Subject: [PATCH 4/4] block: undo receiptRoot accidental reverts --- packages/block/src/header-from-rpc.ts | 5 +---- packages/block/src/types.ts | 1 - 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/block/src/header-from-rpc.ts b/packages/block/src/header-from-rpc.ts index a8f3383cae..070befc301 100644 --- a/packages/block/src/header-from-rpc.ts +++ b/packages/block/src/header-from-rpc.ts @@ -9,10 +9,7 @@ import type { BlockOptions, JsonRpcBlock } from './types' * @param blockParams - Ethereum JSON RPC of block (eth_getBlockByNumber) * @param options - An object describing the blockchain */ -export function blockHeaderFromRpc( - blockParams: Omit & { receiptRoot?: string; receiptsRoot?: string }, - options?: BlockOptions -) { +export function blockHeaderFromRpc(blockParams: JsonRpcBlock, options?: BlockOptions) { const { parentHash, sha3Uncles, diff --git a/packages/block/src/types.ts b/packages/block/src/types.ts index 58cdd141cc..cf9b078042 100644 --- a/packages/block/src/types.ts +++ b/packages/block/src/types.ts @@ -165,7 +165,6 @@ export interface JsonRpcBlock { logsBloom: string // the bloom filter for the logs of the block. null when pending block. transactionsRoot: string // the root of the transaction trie of the block. stateRoot: string // the root of the final state trie of the block. - receiptRoot?: string // the root of the receipts trie of the block. receiptsRoot: string // the root of the receipts trie of the block. miner: string // the address of the beneficiary to whom the mining rewards were given. difficulty: string // integer of the difficulty for this block.