-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: port the node task to hardhat v3
- Loading branch information
Showing
11 changed files
with
871 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
v-next/hardhat/src/internal/builtin-plugins/node/helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import type { | ||
EdrNetworkAccountConfig, | ||
EdrNetworkAccountsConfig, | ||
GenesisAccount, | ||
} from "../../../types/config.js"; | ||
|
||
import { | ||
bytesToHexString, | ||
hexStringToBytes, | ||
} from "@ignored/hardhat-vnext-utils/hex"; | ||
import chalk from "chalk"; | ||
import { addr } from "micro-eth-signer"; | ||
|
||
import { derivePrivateKeys } from "../network-manager/json-rpc-request-modifiers/accounts/derive-private-keys.js"; | ||
|
||
export function normalizeEdrNetworkConfigAccounts( | ||
accounts: EdrNetworkAccountsConfig, | ||
): EdrNetworkAccountConfig[] { | ||
const normalizedAccounts: EdrNetworkAccountConfig[] = []; | ||
|
||
if (accounts !== undefined) { | ||
if (Array.isArray(accounts)) { | ||
normalizedAccounts.push(...accounts); | ||
} else if (accounts !== undefined) { | ||
const privateKeys = derivePrivateKeys( | ||
accounts.mnemonic, | ||
accounts.path, | ||
accounts.initialIndex, | ||
accounts.count, | ||
accounts.passphrase, | ||
); | ||
for (const privateKey of privateKeys) { | ||
normalizedAccounts.push({ | ||
privateKey: bytesToHexString(privateKey), | ||
balance: accounts.accountsBalance, | ||
}); | ||
} | ||
} | ||
} | ||
|
||
return normalizedAccounts; | ||
} | ||
|
||
export function printEdrNetworkConfigAccounts( | ||
accounts: Array<EdrNetworkAccountConfig | GenesisAccount>, | ||
): void { | ||
if (accounts.length === 0) { | ||
return; | ||
} | ||
|
||
console.log("Accounts"); | ||
console.log("========"); | ||
|
||
// NOTE: In v2, we were printing the warning only if the default config was used. | ||
console.log(); | ||
printPublicPrivateKeysWarning(); | ||
console.log(); | ||
|
||
for (const [index, account] of accounts.entries()) { | ||
const address = addr | ||
.fromPrivateKey(hexStringToBytes(account.privateKey)) | ||
.toLowerCase(); | ||
const balance = (BigInt(account.balance) / 10n ** 18n).toString(10); | ||
|
||
console.log(`Account #${index}: ${address} (${balance} ETH)`); | ||
// TODO: Should we print the private key as well? | ||
// console.log(`Private Key: ${account.privateKey}`); | ||
|
||
console.log(); | ||
} | ||
|
||
// NOTE: In v2, we were printing the warning only if the default config was used. | ||
printPublicPrivateKeysWarning(); | ||
console.log(); | ||
} | ||
|
||
// NOTE: In v2, we were printing the warning only if the default config was used. | ||
// Because of that we were certain that the printed accounts were publicly known. | ||
function printPublicPrivateKeysWarning(): void { | ||
console.log( | ||
chalk.bold( | ||
"WARNING: Funds sent on live network to accounts with publicly known private keys WILL BE LOST.", | ||
), | ||
); | ||
} |
Oops, something went wrong.