-
Notifications
You must be signed in to change notification settings - Fork 5
/
node.sh
executable file
·85 lines (80 loc) · 3.58 KB
/
node.sh
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
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
trap "exit" INT TERM ERR
trap "kill 0" EXIT
nodeWaitTimeout=1200
RED='\033[0;31m'
NO_COLOR='\033[0m'
main()
{
# rm -rf deployments/localhost
if [[ $1 == "polygon" ]]
then
# Fetch env variables like PROVIDER_URL and BLOCK_NUMBER from .env file so they don't
# need to be separately set in terminal environment
ENV_FILE=.env
source .env
if [ ! -f "$ENV_FILE" ]; then
echo -e "${RED} File $ENV_FILE does not exist. Have you forgotten to rename the env.example to .env? ${NO_COLOR}"
exit 1
fi
if [ -z "$POLYGON_ARCHIVE_NODE" ]; then echo "Set POLYGON_ARCHIVE_NODE" && exit 1; fi
params=()
params+=(--fork ${POLYGON_ARCHIVE_NODE})
if [ -z "$POLYGON_START_BLOCK" ]; then
echo "It is recommended that POLYGON_START_BLOCK is set to a recent block to improve performance of the fork";
else
params+=(--fork-block-number ${POLYGON_START_BLOCK})
fi
# cp -r deployments/mainnet deployments/localhost
# nodeOutput=$(mktemp "${TMPDIR:-/tmp/}$(basename 0).XXX")
# the --no-install is here so npx doesn't download some package on its own if it can not find one in the repo
FORK=true npx --no-install hardhat node ${params[@]}
elif [[ $1 == "mainnet" ]]
then
# Fetch env variables like PROVIDER_URL and BLOCK_NUMBER from .env file so they don't
# need to be separately set in terminal environment
ENV_FILE=.env
source .env
if [ ! -f "$ENV_FILE" ]; then
echo -e "${RED} File $ENV_FILE does not exist. Have you forgotten to rename the dev.env to .env? ${NO_COLOR}"
exit 1
fi
if [ -z "$MAINNET_ARCHIVE_NODE" ]; then echo "Set MAINNET_ARCHIVE_NODE" && exit 1; fi
params=()
params+=(--fork ${MAINNET_ARCHIVE_NODE})
if [ -z "$MAINNET_START_BLOCK" ]; then
echo "It is recommended that MAINNET_START_BLOCK is set to a recent block to improve performance of the fork";
else
params+=(--fork-block-number ${MAINNET_START_BLOCK})
fi
# cp -r deployments/mainnet deployments/localhost
# nodeOutput=$(mktemp "${TMPDIR:-/tmp/}$(basename 0).XXX")
# the --no-install is here so npx doesn't download some package on its own if it can not find one in the repo
FORK=true npx --no-install hardhat node ${params[@]}
elif [[ $1 == "bsc" ]]
then
# Fetch env variables like PROVIDER_URL and BLOCK_NUMBER from .env file so they don't
# need to be separately set in terminal environment
ENV_FILE=.env
source .env
if [ ! -f "$ENV_FILE" ]; then
echo -e "${RED} File $ENV_FILE does not exist. Have you forgotten to rename the dev.env to .env? ${NO_COLOR}"
exit 1
fi
if [ -z "$BSC_ARCHIVE_NODE" ]; then echo "Set BSC_ARCHIVE_NODE" && exit 1; fi
params=()
params+=(--fork ${BSC_ARCHIVE_NODE})
if [ -z "$BSC_START_BLOCK" ]; then
echo "It is recommended that BSC_START_BLOCK is set to a recent block to improve performance of the fork";
else
params+=(--fork-block-number ${BSC_START_BLOCK})
fi
# cp -r deployments/mainnet deployments/localhost
# nodeOutput=$(mktemp "${TMPDIR:-/tmp/}$(basename 0).XXX")
# the --no-install is here so npx doesn't download some package on its own if it can not find one in the repo
FORK=true npx --no-install hardhat node ${params[@]}
else
npx --no-install hardhat node
fi
}
main "$@"