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

Commit

Permalink
perf: optimize account init logging (#4318)
Browse files Browse the repository at this point in the history
Co-authored-by: jeffsmale90 <[email protected]>
  • Loading branch information
davidmurdoch and jeffsmale90 authored Jun 23, 2023
1 parent ac5deea commit fd5f05d
Showing 1 changed file with 56 additions and 53 deletions.
109 changes: 56 additions & 53 deletions src/packages/cli/src/initialize/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,82 +16,85 @@ export default function (provider: EthereumProvider, cliSettings: CliSettings) {
const liveOptions = provider.getOptions();
const accounts = provider.getInitialAccounts();

const addresses = Object.keys(accounts);
const logs = [];
logs.push("");
logs.push("Available Accounts");
logs.push("==================");
const addresses = Object.entries(accounts);
let log = "\n";
const appendLog = line => (log += line + "\n");

appendLog("Available Accounts");
appendLog("==================");
if (addresses.length > 0) {
addresses.forEach(function (address, index) {
const balance = accounts[address].balance;
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 (!accounts[address].unlocked) {
if (!account.unlocked) {
line += " 🔒";
}

logs.push(line);
});
appendLog(line);
}

logs.push("");
logs.push("Private Keys");
logs.push("==================");
appendLog("");
appendLog("Private Keys");
appendLog("==================");

addresses.forEach(function (address, index) {
logs.push(`(${index}) ${accounts[address].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);
}

0 comments on commit fd5f05d

Please sign in to comment.