@ethereumjs/block
Advanced tools
Comparing version 4.2.1 to 4.2.2
/// <reference types="node" /> | ||
import { Trie } from '@ethereumjs/trie'; | ||
import { Withdrawal } from '@ethereumjs/util'; | ||
import { ethers } from 'ethers'; | ||
import { BlockHeader } from './header'; | ||
@@ -72,3 +71,3 @@ import type { BlockBuffer, BlockData, BlockOptions, JsonBlock, JsonRpcBlock } from './types'; | ||
*/ | ||
static fromEthersProvider: (provider: ethers.providers.JsonRpcProvider | string, blockTag: string | bigint, opts: BlockOptions) => Promise<Block>; | ||
static fromEthersProvider: (provider: any, blockTag: string | bigint, opts: BlockOptions) => Promise<Block>; | ||
/** | ||
@@ -75,0 +74,0 @@ * This constructor takes the values, validates them, assigns them and freezes the object. |
@@ -11,3 +11,2 @@ "use strict"; | ||
const keccak_1 = require("ethereum-cryptography/keccak"); | ||
const ethers_1 = require("ethers"); | ||
const from_rpc_1 = require("./from-rpc"); | ||
@@ -148,2 +147,7 @@ const header_1 = require("./header"); | ||
} | ||
if (opts?.common !== undefined && | ||
opts?.common?.isActivatedEIP(4895) && | ||
(values[3] === undefined || !Array.isArray(values[3]))) { | ||
throw new Error('Invalid serialized block input: EIP-4895 is active, and no withdrawals were provided as array'); | ||
} | ||
const [headerData, txsData, uhsData, withdrawalsBuffer] = values; | ||
@@ -459,8 +463,14 @@ const header = header_1.BlockHeader.fromValuesArray(headerData, opts); | ||
let blockData; | ||
const prov = typeof provider === 'string' ? new ethers_1.ethers.providers.JsonRpcProvider(provider) : provider; | ||
const providerUrl = (0, util_1.getProvider)(provider); | ||
if (typeof blockTag === 'string' && blockTag.length === 66) { | ||
blockData = await prov.send('eth_getBlockByHash', [blockTag, true]); | ||
blockData = await (0, util_1.fetchFromProvider)(providerUrl, { | ||
method: 'eth_getBlockByHash', | ||
params: [blockTag, true], | ||
}); | ||
} | ||
else if (typeof blockTag === 'bigint') { | ||
blockData = await prov.send('eth_getBlockByNumber', [(0, util_1.bigIntToHex)(blockTag), true]); | ||
blockData = await (0, util_1.fetchFromProvider)(providerUrl, { | ||
method: 'eth_getBlockByNumber', | ||
params: [(0, util_1.bigIntToHex)(blockTag), true], | ||
}); | ||
} | ||
@@ -471,3 +481,6 @@ else if ((0, util_1.isHexPrefixed)(blockTag) || | ||
blockTag === 'pending') { | ||
blockData = await prov.send('eth_getBlockByNumber', [blockTag, true]); | ||
blockData = await (0, util_1.fetchFromProvider)(providerUrl, { | ||
method: 'eth_getBlockByNumber', | ||
params: [blockTag, true], | ||
}); | ||
} | ||
@@ -477,9 +490,12 @@ else { | ||
} | ||
if (blockData === null) { | ||
throw new Error('No block data returned from provider'); | ||
} | ||
const uncleHeaders = []; | ||
if (blockData.uncles.length > 0) { | ||
for (let x = 0; x < blockData.uncles.length; x++) { | ||
const headerData = await prov.send('eth_getUncleByBlockHashAndIndex', [ | ||
blockData.hash, | ||
(0, util_1.intToHex)(x), | ||
]); | ||
const headerData = await (0, util_1.fetchFromProvider)(providerUrl, { | ||
method: 'eth_getUncleByBlockHashAndIndex', | ||
params: [blockData.hash, (0, util_1.intToHex)(x)], | ||
}); | ||
uncleHeaders.push(headerData); | ||
@@ -486,0 +502,0 @@ } |
@@ -41,5 +41,5 @@ "use strict"; | ||
const uncleHeaders = uncles.map((uh) => (0, header_from_rpc_1.blockHeaderFromRpc)(uh, options)); | ||
return index_1.Block.fromBlockData({ header, transactions, uncleHeaders }, options); | ||
return index_1.Block.fromBlockData({ header, transactions, uncleHeaders, withdrawals: blockParams.withdrawals }, options); | ||
} | ||
exports.blockFromRpc = blockFromRpc; | ||
//# sourceMappingURL=from-rpc.js.map |
@@ -13,3 +13,3 @@ "use strict"; | ||
function blockHeaderFromRpc(blockParams, options) { | ||
const { parentHash, sha3Uncles, miner, stateRoot, transactionsRoot, receiptsRoot, logsBloom, difficulty, number, gasLimit, gasUsed, timestamp, extraData, mixHash, nonce, baseFeePerGas, } = blockParams; | ||
const { parentHash, sha3Uncles, miner, stateRoot, transactionsRoot, receiptsRoot, logsBloom, difficulty, number, gasLimit, gasUsed, timestamp, extraData, mixHash, nonce, baseFeePerGas, withdrawalsRoot, } = blockParams; | ||
const blockHeader = header_1.BlockHeader.fromHeaderData({ | ||
@@ -32,2 +32,3 @@ parentHash, | ||
baseFeePerGas, | ||
withdrawalsRoot, | ||
}, options); | ||
@@ -34,0 +35,0 @@ return blockHeader; |
@@ -174,4 +174,5 @@ /// <reference types="node" /> | ||
withdrawals?: Array<JsonRpcWithdrawal>; | ||
withdrawalsRoot?: string; | ||
excessDataGas?: string; | ||
} | ||
//# sourceMappingURL=types.d.ts.map |
{ | ||
"name": "@ethereumjs/block", | ||
"version": "4.2.1", | ||
"version": "4.2.2", | ||
"description": "Provides Block serialization and help functions", | ||
@@ -41,13 +41,13 @@ "keywords": [ | ||
"dependencies": { | ||
"@ethereumjs/common": "^3.1.1", | ||
"@ethereumjs/common": "^3.1.2", | ||
"@ethereumjs/rlp": "^4.0.1", | ||
"@ethereumjs/trie": "^5.0.4", | ||
"@ethereumjs/tx": "^4.1.1", | ||
"@ethereumjs/util": "^8.0.5", | ||
"ethereum-cryptography": "^1.1.2", | ||
"ethers": "^5.7.1" | ||
"@ethereumjs/trie": "^5.0.5", | ||
"@ethereumjs/tx": "^4.1.2", | ||
"@ethereumjs/util": "^8.0.6", | ||
"ethereum-cryptography": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/lru-cache": "^5.1.0", | ||
"c-kzg": "^1.0.8" | ||
"c-kzg": "^1.0.8", | ||
"testdouble": "^3.17.2" | ||
}, | ||
@@ -54,0 +54,0 @@ "engines": { |
@@ -12,2 +12,4 @@ import { ConsensusType } from '@ethereumjs/common' | ||
bufferToHex, | ||
fetchFromProvider, | ||
getProvider, | ||
intToHex, | ||
@@ -18,3 +20,2 @@ isHexPrefixed, | ||
import { keccak256 } from 'ethereum-cryptography/keccak' | ||
import { ethers } from 'ethers' | ||
@@ -158,2 +159,12 @@ import { blockFromRpc } from './from-rpc' | ||
} | ||
if ( | ||
opts?.common !== undefined && | ||
opts?.common?.isActivatedEIP(4895) && | ||
(values[3] === undefined || !Array.isArray(values[3])) | ||
) { | ||
throw new Error( | ||
'Invalid serialized block input: EIP-4895 is active, and no withdrawals were provided as array' | ||
) | ||
} | ||
const [headerData, txsData, uhsData, withdrawalsBuffer] = values | ||
@@ -226,3 +237,3 @@ | ||
public static fromEthersProvider = async ( | ||
provider: ethers.providers.JsonRpcProvider | string, | ||
provider: any, | ||
blockTag: string | bigint, | ||
@@ -232,8 +243,14 @@ opts: BlockOptions | ||
let blockData | ||
const prov = | ||
typeof provider === 'string' ? new ethers.providers.JsonRpcProvider(provider) : provider | ||
const providerUrl = getProvider(provider) | ||
if (typeof blockTag === 'string' && blockTag.length === 66) { | ||
blockData = await prov.send('eth_getBlockByHash', [blockTag, true]) | ||
blockData = await fetchFromProvider(providerUrl, { | ||
method: 'eth_getBlockByHash', | ||
params: [blockTag, true], | ||
}) | ||
} else if (typeof blockTag === 'bigint') { | ||
blockData = await prov.send('eth_getBlockByNumber', [bigIntToHex(blockTag), true]) | ||
blockData = await fetchFromProvider(providerUrl, { | ||
method: 'eth_getBlockByNumber', | ||
params: [bigIntToHex(blockTag), true], | ||
}) | ||
} else if ( | ||
@@ -245,3 +262,6 @@ isHexPrefixed(blockTag) || | ||
) { | ||
blockData = await prov.send('eth_getBlockByNumber', [blockTag, true]) | ||
blockData = await fetchFromProvider(providerUrl, { | ||
method: 'eth_getBlockByNumber', | ||
params: [blockTag, true], | ||
}) | ||
} else { | ||
@@ -253,9 +273,13 @@ throw new Error( | ||
if (blockData === null) { | ||
throw new Error('No block data returned from provider') | ||
} | ||
const uncleHeaders = [] | ||
if (blockData.uncles.length > 0) { | ||
for (let x = 0; x < blockData.uncles.length; x++) { | ||
const headerData = await prov.send('eth_getUncleByBlockHashAndIndex', [ | ||
blockData.hash, | ||
intToHex(x), | ||
]) | ||
const headerData = await fetchFromProvider(providerUrl, { | ||
method: 'eth_getUncleByBlockHashAndIndex', | ||
params: [blockData.hash, intToHex(x)], | ||
}) | ||
uncleHeaders.push(headerData) | ||
@@ -262,0 +286,0 @@ } |
@@ -57,3 +57,6 @@ import { TransactionFactory } from '@ethereumjs/tx' | ||
return Block.fromBlockData({ header, transactions, uncleHeaders }, options) | ||
return Block.fromBlockData( | ||
{ header, transactions, uncleHeaders, withdrawals: blockParams.withdrawals }, | ||
options | ||
) | ||
} |
@@ -30,2 +30,3 @@ import { BlockHeader } from './header' | ||
baseFeePerGas, | ||
withdrawalsRoot, | ||
} = blockParams | ||
@@ -51,2 +52,3 @@ | ||
baseFeePerGas, | ||
withdrawalsRoot, | ||
}, | ||
@@ -53,0 +55,0 @@ options |
@@ -199,3 +199,4 @@ import type { BlockHeader } from './header' | ||
withdrawals?: Array<JsonRpcWithdrawal> // If EIP-4895 is enabled for this block, array of withdrawals | ||
withdrawalsRoot?: string // If EIP-4895 is enabled for this block, the root of the withdrawal trie of the block. | ||
excessDataGas?: string // If EIP-4844 is enabled for this block, returns the excess data gas for the block | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
235710
6
3846
3
- Removedethers@^5.7.1
- Removed@ethersproject/abi@5.7.0(transitive)
- Removed@ethersproject/abstract-provider@5.7.0(transitive)
- Removed@ethersproject/abstract-signer@5.7.0(transitive)
- Removed@ethersproject/address@5.7.0(transitive)
- Removed@ethersproject/base64@5.7.0(transitive)
- Removed@ethersproject/basex@5.7.0(transitive)
- Removed@ethersproject/bignumber@5.7.0(transitive)
- Removed@ethersproject/bytes@5.7.0(transitive)
- Removed@ethersproject/constants@5.7.0(transitive)
- Removed@ethersproject/contracts@5.7.0(transitive)
- Removed@ethersproject/hash@5.7.0(transitive)
- Removed@ethersproject/hdnode@5.7.0(transitive)
- Removed@ethersproject/json-wallets@5.7.0(transitive)
- Removed@ethersproject/keccak256@5.7.0(transitive)
- Removed@ethersproject/logger@5.7.0(transitive)
- Removed@ethersproject/networks@5.7.1(transitive)
- Removed@ethersproject/pbkdf2@5.7.0(transitive)
- Removed@ethersproject/properties@5.7.0(transitive)
- Removed@ethersproject/providers@5.7.2(transitive)
- Removed@ethersproject/random@5.7.0(transitive)
- Removed@ethersproject/rlp@5.7.0(transitive)
- Removed@ethersproject/sha2@5.7.0(transitive)
- Removed@ethersproject/signing-key@5.7.0(transitive)
- Removed@ethersproject/solidity@5.7.0(transitive)
- Removed@ethersproject/strings@5.7.0(transitive)
- Removed@ethersproject/transactions@5.7.0(transitive)
- Removed@ethersproject/units@5.7.0(transitive)
- Removed@ethersproject/wallet@5.7.0(transitive)
- Removed@ethersproject/web@5.7.1(transitive)
- Removed@ethersproject/wordlists@5.7.0(transitive)
- Removed@noble/hashes@1.2.0(transitive)
- Removed@noble/secp256k1@1.7.1(transitive)
- Removed@scure/bip32@1.1.5(transitive)
- Removed@scure/bip39@1.1.1(transitive)
- Removedaes-js@3.0.0(transitive)
- Removedbech32@1.1.4(transitive)
- Removedbn.js@4.12.05.2.1(transitive)
- Removedbrorand@1.1.0(transitive)
- Removedelliptic@6.5.4(transitive)
- Removedethereum-cryptography@1.2.0(transitive)
- Removedethers@5.7.2(transitive)
- Removedhash.js@1.1.7(transitive)
- Removedhmac-drbg@1.0.1(transitive)
- Removedjs-sha3@0.8.0(transitive)
- Removedminimalistic-assert@1.0.1(transitive)
- Removedminimalistic-crypto-utils@1.0.1(transitive)
- Removedscrypt-js@3.0.1(transitive)
- Removedws@7.4.6(transitive)
Updated@ethereumjs/common@^3.1.2
Updated@ethereumjs/trie@^5.0.5
Updated@ethereumjs/tx@^4.1.2
Updated@ethereumjs/util@^8.0.6
Updatedethereum-cryptography@^2.0.0