-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmisc.ts
73 lines (61 loc) · 2.05 KB
/
misc.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { HardhatPluginError } from "hardhat/plugins";
import fs from "fs";
import _ from "lodash";
import child_process from "child_process";
export function PluginError(message: string, parent?: Error | undefined): Error {
return new HardhatPluginError("hardhat-utils", message, parent)
}
export async function sleep(msec: number) {
await new Promise(resolve => setTimeout(resolve, msec));
}
export function isFilePath(path: string): boolean {
try {
fs.accessSync(path, fs.constants.R_OK);
return true;
} catch {
return false;
}
}
let dockerComposePath: string | null = null;
// Find docker compose command, if not set.
// Prefers 'docker compose' (V2) over 'docker-compose' (V1)
// see https://docs.docker.com/compose/migrate/ for the difference.
function findDockerCompose(): string {
if (dockerComposePath) {
return dockerComposePath;
}
try {
child_process.execSync("docker compose version", {stdio: 'pipe'});
dockerComposePath = "docker compose";
return dockerComposePath;
} catch (e) {
}
try {
child_process.execSync("docker-compose --version", {stdio: 'pipe'});
dockerComposePath = "docker-compose";
return dockerComposePath;
} catch (e) {
}
throw new Error("docker compose not installed. Follow https://docs.docker.com/compose/install/");
}
export function runDockerCompose(args: string, opts: any = {}) {
let dockerCompose = findDockerCompose();
let cmd = `${dockerCompose} --ansi never ${args}`
opts.stdio = 'inherit';
child_process.execSync(cmd, opts);
}
export function isDevDependency(path: string): boolean {
return _.startsWith(path, "lib/forge-std/") ||
_.startsWith(path, "hardhat/");
}
export async function currentNetworkEIP3085(): Promise<any> {
const ethersNet = await hre.ethers.provider.getNetwork();
const chainId = ethersNet.chainId;
const url = hre.ethers.provider.connection.url;
const param = { // https://eips.ethereum.org/EIPS/eip-3085
chainId: '0x' + chainId.toString(16),
chainName: 'hardhat:' + hre.network.name,
rpcUrls: [url],
}
return param;
}