Skip to content

Commit

Permalink
rename blockFrom... to createBlockFrom...
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottyPoi committed Jul 11, 2024
1 parent ff67b8d commit 0320141
Show file tree
Hide file tree
Showing 111 changed files with 563 additions and 521 deletions.
6 changes: 3 additions & 3 deletions packages/block/examples/1559.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Block, blockFromBlockData } from '@ethereumjs/block'
import { Block, createBlockFromBlockData } from '@ethereumjs/block'
import { Chain, Common, Hardfork } from '@ethereumjs/common'
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London })

const block = blockFromBlockData(
const block = createBlockFromBlockData(
{
header: {
baseFeePerGas: BigInt(10),
Expand All @@ -19,7 +19,7 @@ console.log(Number(block.header.calcNextBaseFee())) // 11

// So for creating a block with a matching base fee in a certain
// chain context you can do:
const blockWithMatchingBaseFee = blockFromBlockData(
const blockWithMatchingBaseFee = createBlockFromBlockData(
{
header: {
baseFeePerGas: block.header.calcNextBaseFee(),
Expand Down
4 changes: 2 additions & 2 deletions packages/block/examples/4844.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Common, Chain, Hardfork } from '@ethereumjs/common'
import { Block, blockFromBlockData } from '@ethereumjs/block'
import { Block, createBlockFromBlockData } from '@ethereumjs/block'
import { BlobEIP4844Transaction } from '@ethereumjs/tx'
import { Address } from '@ethereumjs/util'
import { loadKZG } from 'kzg-wasm'
Expand All @@ -20,7 +20,7 @@ const main = async () => {
{ common }
)

const block = blockFromBlockData(
const block = createBlockFromBlockData(
{
header: {
excessBlobGas: 0n,
Expand Down
4 changes: 2 additions & 2 deletions packages/block/examples/clique.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Block, blockFromBlockData } from '@ethereumjs/block'
import { Block, createBlockFromBlockData } from '@ethereumjs/block'
import { Chain, Common, Hardfork } from '@ethereumjs/common'

const common = new Common({ chain: Chain.Goerli, hardfork: Hardfork.Chainstart })

console.log(common.consensusType()) // 'poa'
console.log(common.consensusAlgorithm()) // 'clique'

blockFromBlockData({ header: { extraData: new Uint8Array(97) } }, { common })
createBlockFromBlockData({ header: { extraData: new Uint8Array(97) } }, { common })
console.log(`Old Clique Proof-of-Authority block created`)
4 changes: 2 additions & 2 deletions packages/block/examples/pos.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Block, blockFromBlockData } from '@ethereumjs/block'
import { Block, createBlockFromBlockData } from '@ethereumjs/block'
import { Chain, Common } from '@ethereumjs/common'

const common = new Common({ chain: Chain.Mainnet })

const block = blockFromBlockData(
const block = createBlockFromBlockData(
{
// Provide your block data here or use default values
},
Expand Down
4 changes: 2 additions & 2 deletions packages/block/examples/pow.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Block, blockFromBlockData } from '@ethereumjs/block'
import { Block, createBlockFromBlockData } from '@ethereumjs/block'
import { Chain, Common, Hardfork } from '@ethereumjs/common'

const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Chainstart })

console.log(common.consensusType()) // 'pow'
console.log(common.consensusAlgorithm()) // 'ethash'

blockFromBlockData({}, { common })
createBlockFromBlockData({}, { common })
console.log(`Old Proof-of-Work block created`)
4 changes: 2 additions & 2 deletions packages/block/examples/withdrawals.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Block, blockFromBlockData } from '@ethereumjs/block'
import { Block, createBlockFromBlockData } from '@ethereumjs/block'
import { Common, Chain } from '@ethereumjs/common'
import { Address, hexToBytes } from '@ethereumjs/util'
import type { WithdrawalData } from '@ethereumjs/util'
Expand All @@ -12,7 +12,7 @@ const withdrawal = <WithdrawalData>{
amount: BigInt(1000),
}

const block = blockFromBlockData(
const block = createBlockFromBlockData(
{
header: {
withdrawalsRoot: hexToBytes(
Expand Down
26 changes: 13 additions & 13 deletions packages/block/src/blockConstructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
isHexString,
} from '@ethereumjs/util'

import { blockFromRpc } from './from-rpc.js'
import { createBlockFromRpc } from './from-rpc.js'
import { genRequestsTrieRoot, genTransactionsTrieRoot, genWithdrawalsTrieRoot } from './helpers.js'

import { Block, BlockHeader, executionPayloadFromBeaconPayload } from './index.js'
Expand Down Expand Up @@ -51,7 +51,7 @@ import type {
* @param blockData
* @param opts
*/
export function blockFromBlockData(blockData: BlockData = {}, opts?: BlockOptions) {
export function createBlockFromBlockData(blockData: BlockData = {}, opts?: BlockOptions) {
const {
header: headerData,
transactions: txsData,
Expand Down Expand Up @@ -114,7 +114,7 @@ export function blockFromBlockData(blockData: BlockData = {}, opts?: BlockOption
* @param values
* @param opts
*/
export function blockFromValuesArray(values: BlockBytes, opts?: BlockOptions) {
export function createBlockFromValuesArray(values: BlockBytes, opts?: BlockOptions) {
if (values.length > 5) {
throw new Error(`invalid More values=${values.length} than expected were received (at most 5)`)
}
Expand Down Expand Up @@ -237,14 +237,14 @@ export function blockFromValuesArray(values: BlockBytes, opts?: BlockOptions) {
* @param serialized
* @param opts
*/
export function blockFromRLPSerializedBlock(serialized: Uint8Array, opts?: BlockOptions) {
export function createBlockFromRLPSerializedBlock(serialized: Uint8Array, opts?: BlockOptions) {
const values = RLP.decode(Uint8Array.from(serialized)) as BlockBytes

if (!Array.isArray(values)) {
throw new Error('Invalid serialized block input. Must be array')
}

return blockFromValuesArray(values, opts)
return createBlockFromValuesArray(values, opts)
}

/**
Expand All @@ -254,8 +254,8 @@ export function blockFromRLPSerializedBlock(serialized: Uint8Array, opts?: Block
* @param uncles - Optional list of Ethereum JSON RPC of uncles (eth_getUncleByBlockHashAndIndex)
* @param opts - An object describing the blockchain
*/
export function blockFromRPC(blockData: JsonRpcBlock, uncles?: any[], opts?: BlockOptions) {
return blockFromRpc(blockData, uncles, opts)
export function createBlockFromRPC(blockData: JsonRpcBlock, uncles?: any[], opts?: BlockOptions) {
return createBlockFromRpc(blockData, uncles, opts)
}

/**
Expand All @@ -265,7 +265,7 @@ export function blockFromRPC(blockData: JsonRpcBlock, uncles?: any[], opts?: Blo
* @param opts {@link BlockOptions}
* @returns the block specified by `blockTag`
*/
export const blockFromJsonRpcProvider = async (
export const createBlockFromJsonRpcProvider = async (
provider: string | EthersProvider,
blockTag: string | bigint,
opts: BlockOptions
Expand Down Expand Up @@ -316,7 +316,7 @@ export const blockFromJsonRpcProvider = async (
}
}

return blockFromRpc(blockData, uncleHeaders, opts)
return createBlockFromRpc(blockData, uncleHeaders, opts)
}

/**
Expand All @@ -325,7 +325,7 @@ export const blockFromJsonRpcProvider = async (
* @param opts {@link BlockOptions}
* @returns the block constructed block
*/
export async function blockFromExecutionPayload(
export async function createBlockFromExecutionPayload(
payload: ExecutionPayload,
opts?: BlockOptions
): Promise<Block> {
Expand Down Expand Up @@ -406,7 +406,7 @@ export async function blockFromExecutionPayload(
}

// we are not setting setHardfork as common is already set to the correct hf
const block = blockFromBlockData(
const block = createBlockFromBlockData(
{ header, transactions: txs, withdrawals, executionWitness, requests },
opts
)
Expand All @@ -433,10 +433,10 @@ export async function blockFromExecutionPayload(
* @param opts {@link BlockOptions}
* @returns the block constructed block
*/
export async function blockFromBeaconPayloadJson(
export async function createBlockFromBeaconPayloadJson(
payload: BeaconPayloadJson,
opts?: BlockOptions
): Promise<Block> {
const executionPayload = executionPayloadFromBeaconPayload(payload)
return blockFromExecutionPayload(executionPayload, opts)
return createBlockFromExecutionPayload(executionPayload, opts)
}
6 changes: 3 additions & 3 deletions packages/block/src/from-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
toType,
} from '@ethereumjs/util'

import { blockFromBlockData } from './blockConstructor.js'
import { createBlockFromBlockData } from './blockConstructor.js'
import { blockHeaderFromRpc } from './header-from-rpc.js'

import type { BlockOptions, JsonRpcBlock } from './index.js'
Expand Down Expand Up @@ -44,7 +44,7 @@ function normalizeTxParams(_txParams: any) {
* @param options - An object describing the blockchain
* @deprecated
*/
export function blockFromRpc(
export function createBlockFromRpc(
blockParams: JsonRpcBlock,
uncles: any[] = [],
options?: BlockOptions
Expand All @@ -65,7 +65,7 @@ export function blockFromRpc(
const bytes = hexToBytes(req as PrefixedHexString)
return CLRequestFactory.fromSerializedRequest(bytes)
})
return blockFromBlockData(
return createBlockFromBlockData(
{ header, transactions, uncleHeaders, withdrawals: blockParams.withdrawals, requests },
options
)
Expand Down
Loading

0 comments on commit 0320141

Please sign in to comment.