MCPcopy Create free account
hub / github.com/circlefin/arc-node / parseBlockId

Function parseBlockId

scripts/hardhat/tasks/query-fee.ts:32–51  ·  view source on GitHub ↗

* parseBlockId is a helper function to parse the block number or tag or hash into a viem block object. * It use the same format as the go-ethereum rpc such as eth_getBlockReceipts. * - 66 bytes string with 0x prefix will be parsed as block hash * - number or other hex string will be parsed as blo

(id: string)

Source from the content-addressed store, hash-verified

30 * @returns a viem block object
31 */
32function parseBlockId(id: string) {
33 if (/^0x[0-9a-fA-F]{64}$/.test(id)) {
34 return { blockHash: id as Hex }
35 }
36 if (/^[0-9]+$/.test(id)) {
37 return { blockNumber: BigInt(id) }
38 }
39 if (/^0x[0-9a-fA-F]+$/.test(id)) {
40 return { blockNumber: fromHex(id as Hex, 'bigint') }
41 }
42 switch (id) {
43 case 'latest':
44 case 'earliest':
45 case 'pending':
46 case 'safe':
47 case 'finalized':
48 return { blockTag: id as BlockTag }
49 }
50 throw new Error(`Invalid block id: ${id}`)
51}
52
53task('query-fee', 'query fee for the block')
54 .addOptionalParam('block', 'block height or tag or hash to query', 'latest')

Callers 1

query-fee.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected