-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy patheth-private-net
executable file
·104 lines (81 loc) · 2.43 KB
/
eth-private-net
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
#!/bin/bash
IDENTITIES=(alice bob lily)
FLAGS='--networkid=8888 --preload=identities.js'
DEV_FLAGS='--nodiscover --verbosity=4'
BASE_PORT=40300
BASE_RPC_PORT=8100
SCRIPT=$(basename "$0")
USAGE="Name:
$SCRIPT - Command line utility for creating and running a three node Ethereum private net
Network comes with three identities at the following addresses:
alice: 0xdda6ef2ff259928c561b2d30f0cad2c2736ce8b6 (initialized with 1 Ether)
bob: 0x8691bf25ce4a56b15c1f99c944dc948269031801 (initialized with 1 Ether)
lily: 0xb1b6a66a410edc72473d92decb3772bad863e243
Usage:
$SCRIPT command [command options]
Commands:
init Initialize private network from genesis block in genesis.json
clean Destroy all blockchain history, resetting to pristine state
start Start a running ethereum node on the network (example: 'start alice')
connect Connect two running nodes as peers (example: 'connect alice bob')
help Print this help message
Author:
Vincent Chu (@vincentchu), Initialized Capital
https://github.com/vincentchu/eth-private-net
"
function exec_on_node() {
geth --exec="$2" attach ./$1/geth.ipc
}
CMD=$1
case $CMD in
init)
for IDENTITY in ${IDENTITIES[@]}; do
echo "Initializing genesis block for $IDENTITY"
geth --datadir=./$IDENTITY $FLAGS init genesis.json
done
;;
clean)
for IDENTITY in ${IDENTITIES[@]}; do
echo "Cleaning geth/ directory from $IDENTITY"
rm -r ./$IDENTITY/geth
done
;;
start)
IDENTITY=$2
if [ -z $IDENTITY ]
then
echo "No identity specified. Identity must be one of: ${IDENTITIES[*]}"
exit -1
fi
case $IDENTITY in
alice)
OFFSET=1
;;
bob)
OFFSET=2
;;
lily)
OFFSET=3
;;
esac
PORT=$((BASE_PORT + OFFSET))
RPC_PORT=$((BASE_RPC_PORT + OFFSET))
echo "Starting node for $IDENTITY on port: $PORT, RPC port: $RPC_PORT. Console logs sent to ./$IDENTITY/console.log"
geth --datadir=./$IDENTITY --port=$PORT --rpcport=$RPC_PORT $FLAGS $DEV_FLAGS console 2>> ./$IDENTITY/console.log
;;
connect)
IDENTITY1=$2
IDENTITY2=$3
ENODE=$(exec_on_node $IDENTITY1 'admin.nodeInfo.enode')
CONNECT_JS="admin.addPeer($ENODE)"
exec_on_node $IDENTITY2 $CONNECT_JS
;;
help)
echo "$USAGE"
;;
*)
echo "Command '$CMD' not recognized!"
echo "$USAGE"
exit -1
;;
esac