UNPKG

hardhat

Version:

Hardhat is an extensible developer tool that helps smart contract developers increase productivity by reliably bringing together the tools they want.

28 lines 999 B
import { isObject } from "@nomicfoundation/hardhat-utils/lang"; import { getRequestParams } from "../../../json-rpc.js"; /** * This class ensures that a fixed gas is applied to transaction requests. * For `eth_sendTransaction` requests, it sets the gas field with the value provided via the class constructor, if it hasn't been specified already. */ export class FixedGasHandler { #methods = new Set(["eth_sendTransaction"]); #gas; constructor(gas) { this.#gas = gas; } isSupportedMethod(jsonRpcRequest) { return this.#methods.has(jsonRpcRequest.method); } async handle(jsonRpcRequest) { if (!this.isSupportedMethod(jsonRpcRequest)) { return jsonRpcRequest; } const params = getRequestParams(jsonRpcRequest); const [tx] = params; if (isObject(tx) && tx.gas === undefined) { tx.gas = this.#gas; } return jsonRpcRequest; } } //# sourceMappingURL=fixed-gas-handler.js.map