forked from dapphub/dapptools
-
Notifications
You must be signed in to change notification settings - Fork 3
/
dapp---testnet-launch
executable file
·167 lines (150 loc) · 5.73 KB
/
dapp---testnet-launch
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env bash
set -e
OPTS="dapp testnet [<options>] <args>...
dapp testnet --help
--
db-user=name database user
db-password=password database password
db-name=name database name
db-host=address database host
db-port=port database port
rpc-port=port change RPC port (default: 8545)
rpc-addr=address change RPC address (default: 127.0.0.1)
chain-id=number change chain ID (default: 99)
period=seconds use a block time instead of instamine
accounts=number create multiple accounts (default: 1)
address=address eth address to add to genesis
save=name after finishing, save snapshot
load=name start from a previously saved snapshot
dir=directory testnet directory
"
eval "$(
git rev-parse --parseopt -- "$@" <<<"$OPTS" || echo exit $?
)"
DB_USER=vdbm
DB_PASSWORD=password
DB_NAME=vulcanize_public
DB_HOST=127.0.0.1
DB_PORT=5432
RPC_PORT=8545
RPC_ADDRESS=127.0.0.1
PERIOD=0
CHAINID=99
ACCOUNTS=0
ADDRESS=
gethdir=$HOME/.dapp/testnet
while [[ $1 ]]; do
case $1 in
--) shift; break;;
--db-user) shift; DB_USER=$1;;
--db-password) shift; DB_PASSWORD=$1;;
--db-name) shift; DB_NAME=$1;;
--db-host) shift; DB_HOST=$1;;
--db-port) shift; DB_PORT=$1;;
--rpc-port) shift; RPC_PORT=$1;;
--rpc-addr) shift; RPC_ADDRESS=$1;;
--chain-id) shift; CHAINID=$1;;
--period) shift; PERIOD=$1;;
--accounts) shift; ACCOUNTS=$(($1 - 1));;
--save) shift; SAVE=$1;;
--address) shift; ADDRESS=$1;;
--load) shift; LOAD=$1;;
--dir) shift; gethdir=$1;;
*) printf "${0##*/}: internal error: %q\\n" "$1"; exit 1
esac; shift
done
chaindir=$gethdir/$RPC_PORT
if [[ $LOAD ]]; then
mkdir -p "$chaindir"
cp -r "$gethdir/snapshots/$LOAD"/{keystore,config} "$chaindir"
geth >/dev/null 2>&1 --datadir "$chaindir" init "$chaindir/config/genesis.json"
geth >/dev/null 2>&1 --datadir "$chaindir" import "$gethdir/snapshots/$LOAD/backup"
keys=$(jq <"$chaindir/config/genesis.json" -r '.alloc | keys | join(" ")')
IFS=" " read -r -a address <<< "$keys"
CHAINID=$(jq <"$chaindir/config/genesis.json" -r ".config.chainId")
else
while true; do
if [[ ! -d "$gethdir/$CHAINID" ]]; then break; fi
CHAINID=$((CHAINID + 1))
done
mkdir -p "$chaindir/config"
if [ -n "$ADDRESS" ]; then
balance+=(-n {} -s "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" -i balance \
-i "$ADDRESS")
fi
for i in $(seq 0 "$ACCOUNTS"); do
address+=( "$(
geth 2>/dev/null account new --datadir "$chaindir" --password=<(exit) 2>/dev/null \
| grep -o -E "0x[A-Fa-f0-9]*" )" )
balance+=(-n {} -s "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" -i balance \
-i "${address[i]}")
done
jshon >"$chaindir/config/genesis.json" \
-n {} \
-n {} \
-n "$CHAINID" -i chainId \
-n 0 -i homesteadBlock \
-n 0 -i eip150Block \
-n 0 -i eip155Block \
-n 0 -i eip158Block \
-n 0 -i byzantiumBlock \
-n 0 -i constantinopleBlock \
-n 0 -i petersburgBlock \
-n 0 -i istanbulBlock \
-n {} -n "$PERIOD" -i period -n 3000 -i epoch -i clique \
-i config \
-s 0x1 -i difficulty \
-s 0xffffffffffff -i gaslimit \
-s "0x3132333400000000000000000000000000000000000000000000000000000000""${address[0]#0x}""0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" -i extraData \
-n {} \
"${balance[@]}" \
-i alloc
geth 2>/dev/null --datadir "$chaindir" init "$chaindir/config/genesis.json"
fi
export ETH_RPC_URL=http://$RPC_ADDRESS:$RPC_PORT
port=$((RPC_PORT + 30000))
geth version
echo >&2 "dapp-testnet: RPC URL: $ETH_RPC_URL"
echo >&2 "dapp-testnet: TCP port: $port"
echo >&2 "dapp-testnet: Chain ID: $CHAINID"
echo >&2 "dapp-testnet: Database: $chaindir"
echo >&2 "dapp-testnet: Geth log: $chaindir/geth.log"
printf "%s\n" "${address[@]}" > "$chaindir/config/account"
echo "$ETH_RPC_URL" > "$chaindir/config/rpc-url"
echo "$port" > "$chaindir/config/node-port"
set +m
geth \
2> >(tee "$chaindir/geth.log" | grep --line-buffered Success | sed 's/^/geth: /' >&2) \
--datadir "$chaindir" --networkid "$CHAINID" --port="$port" \
--mine --miner.threads=1 --allow-insecure-unlock \
--http --http.api "web3,eth,net,debug,personal,statediff" --http.corsdomain '*' --http.vhosts '*' --nodiscover \
--http.addr="$RPC_ADDRESS" --http.port="$RPC_PORT" --syncmode=full --gcmode=archive \
--statediff --statediff.db="host=$DB_HOST port=$DB_PORT user=$DB_USER password=$DB_PASSWORD dbname=$DB_NAME sslmode=disable" \
--statediff.dbnodeid 1 --statediff.dbclientname test1 --statediff.writing=true \
--ws --ws.addr="0.0.0.0" --unlock="$(IFS=,; echo "${address[*]}")" --password=<(exit) &
gethpid=$!
clean() {
( set -x; kill -INT $gethpid; wait )
if [[ $SAVE ]]; then
echo >&2 "dapp-testnet: saving $gethdir/snapshots/$SAVE"
mkdir -p "$gethdir/snapshots/$SAVE"
cp -r "$chaindir/keystore" "$gethdir/snapshots/$SAVE"
cp -r "$chaindir/config" "$gethdir/snapshots/$SAVE"
geth >/dev/null 2>&1 --datadir "$chaindir" \
export "$gethdir/snapshots/$SAVE/backup"
fi
( set -x; rm -rf "$chaindir" )
}
trap clean EXIT
until curl -s "$ETH_RPC_URL"; do sleep 1; done
ETH_FROM=$(seth --rpc-url="$ETH_RPC_URL" rpc eth_coinbase)
export ETH_FROM
export ETH_KEYSTORE=$chaindir/keystore
export ETH_PASSWORD=/dev/null
printf 'dapp-testnet: Account: %s (default)\n' "${address[0]}" >&2
[[ "${#address[@]}" -gt 1 ]] && printf 'dapp-testnet: Account: %s\n' "${address[@]:1}" >&2
if [[ $1 ]]; then
"$@"
else
while true; do sleep 3600; done
fi