@ganache/ethereum-options
Version:
152 lines • 6.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MinerOptions = void 0;
const helpers_1 = require("./helpers");
const utils_1 = require("@ganache/utils");
const ethereum_address_1 = require("@ganache/ethereum-address");
/**
* Attempts to convert strings that don't start with `0x` to a BigInt
*
* @param str - a string that represents a bigint, number, or hexadecimal value
*/
const toBigIntOrString = (str) => {
if (str.startsWith("0x")) {
return str;
}
else {
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) => {
if (str === "estimate") {
return str;
}
else {
return toBigIntOrString(str);
}
};
/**
* Attempts to convert strings that don't start with `0x` to a number
*
* @param str - a string that represents a number, or hexadecimal value
*/
const toNumberOrString = (str) => {
if (str.startsWith("0x")) {
return str;
}
else {
return parseInt(str);
}
};
// The `normalize` property expects a function with a signature of
// `normalize(value, config)`, but `Quantity.from(value, nullable)` doesn't
// match, so we wrap the `from` method in a function that matches the signature.
// We only instantiate the wrapper function once to avoid unnecessary function
// allocations.
const normalizeQuantity = value => utils_1.Quantity.from(value);
exports.MinerOptions = {
blockTime: {
normalize: rawInput => {
if (rawInput < 0) {
throw new Error("miner.blockTime must be 0 or a positive number.");
}
return rawInput;
},
cliDescription: 'Sets the `blockTime` in seconds for automatic mining. A blockTime of `0` enables "instamine mode", where new executable transactions will be mined instantly.',
default: () => 0,
legacyName: "blockTime",
cliAliases: ["b", "blockTime"],
cliType: "number"
},
timestampIncrement: {
normalize: rawType => rawType === "clock" ? "clock" : utils_1.Quantity.from(BigInt(rawType)),
cliDescription: 'The amount of time, in seconds, to add to the `timestamp` of each new block header. By default the value is `"clock"`, which uses your system clock time as the timestamp for each block.',
default: () => "clock",
cliType: "string"
},
defaultGasPrice: {
normalize: normalizeQuantity,
cliDescription: "Sets the default gas price in WEI for transactions if not otherwise specified.",
default: () => utils_1.Quantity.from(2000000000),
legacyName: "gasPrice",
cliAliases: ["g", "gasPrice"],
cliType: "string",
cliCoerce: toBigIntOrString
},
blockGasLimit: {
normalize: normalizeQuantity,
cliDescription: "Sets the block gas limit in WEI.",
default: () => utils_1.Quantity.from(30000000),
legacyName: "gasLimit",
cliAliases: ["l", "gasLimit"],
cliType: "string",
cliCoerce: toBigIntOrString
},
defaultTransactionGasLimit: {
normalize: rawType => rawType === "estimate" ? utils_1.Quantity.Empty : utils_1.Quantity.from(rawType),
cliDescription: 'Sets the default transaction gas limit in WEI. Set to "estimate" to use an estimate (slows down transaction execution by 40%+).',
default: () => utils_1.Quantity.from(90000),
cliType: "string",
cliCoerce: estimateOrToBigIntOrString
},
difficulty: {
normalize: normalizeQuantity,
cliDescription: "Sets the block difficulty. Value is always 0 after the merge hardfork.",
default: () => utils_1.Quantity.One,
cliType: "string",
cliCoerce: toBigIntOrString
},
callGasLimit: {
normalize: normalizeQuantity,
cliDescription: "Sets the transaction gas limit in WEI for `eth_call` and `eth_estimateGas` calls.",
default: () => utils_1.Quantity.from(50000000),
legacyName: "callGasLimit",
cliType: "string",
cliCoerce: toBigIntOrString
},
instamine: {
normalize: helpers_1.normalize,
cliDescription: `Set the instamine mode to either "eager" (default) or "strict".
* In "eager" mode a transaction will be included in a block before its hash is returned to the caller.
* In "strict" mode a transaction's hash is returned to the caller before the transaction is included in a block.
\`instamine\` has no effect if \`blockTime\` is *not* \`0\` (the default).`,
default: () => "eager",
legacyName: "instamine",
cliAliases: ["instamine"],
cliType: "string",
cliChoices: ["eager", "strict"]
},
coinbase: {
normalize: rawType => {
return typeof rawType === "number" ? rawType : ethereum_address_1.Address.from(rawType);
},
cliDescription: "Sets the address where mining rewards will go.",
cliType: "string",
cliCoerce: toNumberOrString,
default: () => ethereum_address_1.Address.from(utils_1.ACCOUNT_ZERO)
},
extraData: {
normalize: (extra) => {
const bytes = utils_1.Data.from(extra);
if (bytes.toBuffer().length > 32) {
throw new Error(`extra exceeds max length. ${bytes.toBuffer().length} > 32`);
}
return bytes;
},
cliDescription: "Set the extraData block header field a miner can include.",
default: () => utils_1.Data.Empty,
cliType: "string"
},
priceBump: {
normalize: BigInt,
cliDescription: "Minimum price bump percentage needed to replace a transaction that already exists in the transaction pool.",
default: () => 10n,
cliType: "string"
}
};
//# sourceMappingURL=miner-options.js.map