From ab1d9f459cffbc5bc5cb1b6fbaac9204cb3d8a3c Mon Sep 17 00:00:00 2001 From: tenthirtyone Date: Tue, 14 Jun 2022 09:02:23 -0500 Subject: [PATCH] estimateOrToBigIntOrString function for defaultTransactionGasLimit cliCoerce minerFunction --- src/chains/ethereum/options/src/miner-options.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/chains/ethereum/options/src/miner-options.ts b/src/chains/ethereum/options/src/miner-options.ts index 0f36586ec8..670cb0dff5 100644 --- a/src/chains/ethereum/options/src/miner-options.ts +++ b/src/chains/ethereum/options/src/miner-options.ts @@ -195,6 +195,18 @@ const toBigIntOrString = (str: string) => { return BigInt(str); } }; +/** + * Handles defaultTransactionGasLimit special case of 'estimate' for tx value. + * + * @param str - the string literal 'estimate' or string that that represents a bigint, number, or hexadecimal value. + */ +const estimateOrToBigIntOrString = (str: string) => { + if (str === "estimate") { + return str; + } else { + return toBigIntOrString(str); + } +}; /** * Attempts to convert strings that don't start with `0x` to a number @@ -259,7 +271,7 @@ export const MinerOptions: Definitions = { 'Sets the default transaction gas limit in WEI. Set to "estimate" to use an estimate (slows down transaction execution by 40%+).', default: () => Quantity.from(90_000), cliType: "string", - cliCoerce: toBigIntOrString + cliCoerce: estimateOrToBigIntOrString }, difficulty: { normalize: Quantity.from,