Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

perf: minor optimisations to account iteration #4446

Merged
merged 1 commit into from
Jun 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 53 additions & 50 deletions src/packages/cli/src/initialize/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,81 +17,84 @@ 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)`;

if (!account.unlocked) {
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}"
)}`
);
}

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(
Expand All @@ -101,31 +104,31 @@ 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()
)}`
);
}
}

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);
}