diff --git a/src/packages/cli/src/initialize/ethereum.ts b/src/packages/cli/src/initialize/ethereum.ts index 7be89379fb..dd55d7ab25 100644 --- a/src/packages/cli/src/initialize/ethereum.ts +++ b/src/packages/cli/src/initialize/ethereum.ts @@ -17,16 +17,18 @@ export default function (provider: EthereumProvider, cliSettings: CliSettings) { const accounts = provider.getInitialAccounts(); const addresses = Object.entries(accounts); - const logs = []; - logs.push(""); - logs.push("Available Accounts"); - logs.push("=================="); + let log = "\n"; + const appendLog = line => (log += line + "\n"); + + appendLog("Available Accounts"); + appendLog("=================="); if (addresses.length > 0) { - addresses.forEach(([address, account], index) => { + let index = 0; + for (const [address, account] of addresses) { const balance = account.balance; const strBalance = balance / WEI; const about = balance % WEI === 0n ? "" : "~"; - let line = `(${index}) ${toChecksumAddress( + let line = `(${index++}) ${toChecksumAddress( address )} (${about}${strBalance} ETH)`; @@ -34,33 +36,34 @@ export default function (provider: EthereumProvider, cliSettings: CliSettings) { line += " 🔒"; } - logs.push(line); - }); + appendLog(line); + } - logs.push(""); - logs.push("Private Keys"); - logs.push("=================="); + appendLog(""); + appendLog("Private Keys"); + appendLog("=================="); - addresses.forEach(([_, account], index) => { - logs.push(`(${index}) ${account.secretKey}`); - }); + index = 0; + for (const [address, account] of addresses) { + appendLog(`(${index++}) ${account.secretKey}`); + } if (liveOptions.wallet.accountKeysPath != null) { - logs.push(""); - logs.push( + appendLog(""); + appendLog( `Accounts and keys saved to ${liveOptions.wallet.accountKeysPath}` ); } } else { - logs.push("(no accounts unlocked)"); + appendLog("(no accounts unlocked)"); } if (liveOptions.wallet.accounts == null) { - logs.push(""); - logs.push("HD Wallet"); - logs.push("=================="); - logs.push(`Mnemonic: ${color(liveOptions.wallet.mnemonic)}`); - logs.push( + appendLog(""); + appendLog("HD Wallet"); + appendLog("=================="); + appendLog(`Mnemonic: ${color(liveOptions.wallet.mnemonic)}`); + appendLog( `Base HD Path: ${color( liveOptions.wallet.hdPath.join("/") + "/{account_index}" )}` @@ -68,30 +71,30 @@ export default function (provider: EthereumProvider, cliSettings: CliSettings) { } if (liveOptions.miner.defaultGasPrice) { - logs.push(""); - logs.push("Default Gas Price"); - logs.push("=================="); - logs.push(color(liveOptions.miner.defaultGasPrice.toBigInt().toString())); + appendLog(""); + appendLog("Default Gas Price"); + appendLog("=================="); + appendLog(color(liveOptions.miner.defaultGasPrice.toBigInt().toString())); } if (liveOptions.miner.blockGasLimit) { - logs.push(""); - logs.push("BlockGas Limit"); - logs.push("=================="); - logs.push(color(liveOptions.miner.blockGasLimit.toBigInt().toString())); + appendLog(""); + appendLog("BlockGas Limit"); + appendLog("=================="); + appendLog(color(liveOptions.miner.blockGasLimit.toBigInt().toString())); } if (liveOptions.miner.callGasLimit) { - logs.push(""); - logs.push("Call Gas Limit"); - logs.push("=================="); - logs.push(color(liveOptions.miner.callGasLimit.toBigInt().toString())); + appendLog(""); + appendLog("Call Gas Limit"); + appendLog("=================="); + appendLog(color(liveOptions.miner.callGasLimit.toBigInt().toString())); } if (liveOptions.fork.network || liveOptions.fork.url) { - logs.push(""); - logs.push("Forked Chain"); - logs.push("=================="); + appendLog(""); + appendLog("Forked Chain"); + appendLog("=================="); let location: string; if (liveOptions.fork.network) { location = `Ethereum ${capitalizeFirstLetter( @@ -101,17 +104,17 @@ export default function (provider: EthereumProvider, cliSettings: CliSettings) { location = (liveOptions.fork.url as any).toString(); } - logs.push(`Location: ${color(location)}`); - logs.push( + appendLog(`Location: ${color(location)}`); + appendLog( `Block: ${color(liveOptions.fork.blockNumber.toString())}` ); - logs.push( + appendLog( `Network ID: ${color(liveOptions.chain.networkId.toString())}` ); - logs.push(`Time: ${color(liveOptions.chain.time.toString())}`); + appendLog(`Time: ${color(liveOptions.chain.time.toString())}`); if (liveOptions.fork.requestsPerSecond !== 0) { - logs.push( + appendLog( `Requests/Second: ${color( liveOptions.fork.requestsPerSecond.toString() )}` @@ -119,13 +122,13 @@ export default function (provider: EthereumProvider, cliSettings: CliSettings) { } } - logs.push(""); - logs.push("Chain"); - logs.push("=================="); - logs.push(`Hardfork: ${color(liveOptions.chain.hardfork)}`); - logs.push(`Id: ${color(liveOptions.chain.chainId.toString())}`); + appendLog(""); + appendLog("Chain"); + appendLog("=================="); + appendLog(`Hardfork: ${color(liveOptions.chain.hardfork)}`); + appendLog(`Id: ${color(liveOptions.chain.chainId.toString())}`); - logs.push(""); - logs.push("RPC Listening on " + cliSettings.host + ":" + cliSettings.port); - console.log(logs.join("\n")); + appendLog(""); + appendLog("RPC Listening on " + cliSettings.host + ":" + cliSettings.port); + console.log(log); }