UNPKG

@lodestar/prover

Version:

A Typescript implementation of the Ethereum Consensus light client

53 lines 1.96 kB
import { Common, CustomChain, Hardfork } from "@ethereumjs/common"; import { isValidResponse } from "./json_rpc.js"; import { isBlockNumber, isPresent } from "./validation.js"; export async function getELCode(rpc, args) { const codeResult = await rpc.request("eth_getCode", args, { raiseError: false }); if (!isValidResponse(codeResult)) { throw new Error(`Can not find code for address=${args[0]}`); } return codeResult.result; } export async function getELProof(rpc, args) { const proof = await rpc.request("eth_getProof", args, { raiseError: false }); if (!isValidResponse(proof)) { throw new Error(`Can not find proof for address=${args[0]}`); } return proof.result; } export async function getELBlock(rpc, args) { const block = await rpc.request(isBlockNumber(args[0]) ? "eth_getBlockByNumber" : "eth_getBlockByHash", args, { raiseError: false, }); if (!isValidResponse(block)) { throw new Error(`Can not find block. id=${args[0]}`); } return block.result; } export function getChainCommon(network) { switch (network) { case "mainnet": case "sepolia": case "holesky": case "ephemery": // TODO: Not sure how to detect the fork during runtime return new Common({ chain: network, hardfork: Hardfork.Shanghai }); case "minimal": // TODO: Not sure how to detect the fork during runtime return new Common({ chain: "mainnet", hardfork: Hardfork.Shanghai }); case "gnosis": return new Common({ chain: CustomChain.xDaiChain }); default: throw new Error(`Non supported network "${network}"`); } } export function getTxType(tx) { if (isPresent(tx.maxFeePerGas) || isPresent(tx.maxPriorityFeePerGas)) { return 2; } if (isPresent(tx.accessList)) { return 1; } return 0; } //# sourceMappingURL=execution.js.map