-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnode.sh
executable file
·73 lines (63 loc) · 2.22 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
#!/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 == "fork" ]]
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 "$PROVIDER_URL" ]; then echo "Set PROVIDER_URL" && exit 1; fi
params=()
params+=(--fork ${PROVIDER_URL})
if [ -z "$BLOCK_NUMBER" ]; then
echo "It is recommended that BLOCK_NUMBER is set to a recent block to improve performance of the fork";
else
params+=(--fork-block-number ${BLOCK_NUMBER})
fi
nodeOutput=$(mktemp "${TMPDIR:-/tmp/}$(basename 0).XXX")
echo -e "Node logs stored in $nodeOutput"
# 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 --port 8545 --emoji --show-stack-traces ${params[@]} > $nodeOutput 2>&1 &
tail -f $nodeOutput &
i=0
until grep -q -i 'Started HTTP and WebSocket JSON-RPC server at' $nodeOutput
do
let i++
sleep 1
if (( i > nodeWaitTimeout )); then
printf "\n"
echo "$newLine Node failed to initialize in $nodeWaitTimeout seconds"
exit 1
fi
done
printf "\n"
echo "🟢 Node initialized"
# generate merkle tree
npm run generate-merkle-tree:dev
# deploy the contracts
if [ -z "$ACCOUNT_TO_FUND" ]; then
npm run deploy:contracts:dev
else
ACCOUNT_TO_FUND=${ACCOUNT_TO_FUND} npm run deploy:contracts:dev
fi
# wait for subprocesses to finish
for job in `jobs -p`
do
wait $job || let "FAIL+=1"
done
else
npx --no-install hardhat node --export '../dapp/network.json'
fi
}
main "$@"