1+ # This Makefile is meant to be used by people that do not usually work
2+ # with Go source code. If you know what GOPATH is then you probably
3+ # don't need to bother with make.
4+
5+ .PHONY : geth android ios evm all test clean privnet_init privnet_nodes_stop privnet_bootnode_stop privnet_stop privnet_clean privnet_start privnet_start_four privnet_start_seven
6+
7+ GETHBIN = ./build/bin
8+ GO ?= latest
9+ GORUN = go run
10+
11+ MAIN_DIR = ./privnet
12+ SINGLE_DIR = $(MAIN_DIR ) /single
13+ FOUR_DIR = $(MAIN_DIR ) /four
14+ SEVEN_DIR = $(MAIN_DIR ) /seven
15+
16+ NODE1 = node1
17+ NODE1_PORT = 30306
18+ NODE1_RPC_PORT = 8552
19+
20+ NODE2 = node2
21+ NODE2_PORT = 30307
22+ NODE2_RPC_PORT = 8553
23+
24+ NODE3 = node3
25+ NODE3_PORT = 30308
26+ NODE3_RPC_PORT = 8554
27+
28+ NODE4 = node4
29+ NODE4_PORT = 30309
30+ NODE4_RPC_PORT = 8555
31+
32+ NODE5 = node5
33+ NODE5_PORT = 30310
34+ NODE5_RPC_PORT = 8556
35+
36+ NODE6 = node6
37+ NODE6_PORT = 30311
38+ NODE6_RPC_PORT = 8557
39+
40+ NODE7 = node7
41+ NODE7_PORT = 30312
42+ NODE7_RPC_PORT = 8558
43+
44+ NODE8 = node8
45+ NODE8_PORT = 30313
46+ NODE8_RPC_PORT = 8559
47+
48+ PASSWORD_LEN = 32
49+ GENESIS_WORK_JSON = genesis_privnet.json
50+
51+ BOOTNODE = bootnode
52+ BOOTNODE_PORT = 30305
53+ BOOTNODE_LOGLEVEL = 5
54+
55+ RESTRICTED_NETWORK = 127.0.0.0/24
56+ NAT_POLICY = none
57+
58+ define generate_bootnode
59+ @mkdir -p $(1 ) /$(BOOTNODE )
60+ @$(GETHBIN ) /bootnode -genkey $(1 ) /$(BOOTNODE ) /bootnode.key
61+ @echo $$($(GETHBIN ) /bootnode --writeaddress -nodekey $(1 ) /$(BOOTNODE ) /bootnode.key) > $(1 ) /$(BOOTNODE ) /bootnode_address.txt
62+ endef
63+
64+ define generate_password
65+ $$(</dev/urandom tr -dc '12345qwertQWERTasdfgASDFGzxcvbZXCVB' | head -c$(PASSWORD_LEN ) ; echo "" )
66+ endef
67+
68+ define replace_chainid
69+ @sed -i "s/_chain_id_/$$(cat $(1 ) /networkid.txt ) /gI" $(1 ) /$(GENESIS_WORK_JSON )
70+ endef
71+
72+ define replace_node_address
73+ @echo $$(cat $(1 ) /$(2 ) /keystore/* | sed -En 's/.*"address":"([^"]* ) .*/\1/p') > $(1 ) /$(2 ) /node_address.txt
74+ @sed -i "s/$(2 ) /$$(cat $(1 ) /$(2 ) /node_address.txt ) /gI" $(1 ) /$(GENESIS_WORK_JSON )
75+ endef
76+
77+ define create_account
78+ @mkdir -p $(1 ) /$(2 )
79+ @echo $(call generate_password) > $(1 ) /$(2 ) /password.txt
80+ @$(GETHBIN ) /geth --datadir $(1 ) /$(2 ) account new --password $(1 ) /$(2 ) /password.txt
81+ $(call replace_node_address,$(1 ) ,$(2 ) )
82+ @echo "Account $(1 ) : "$$(cat $(1 ) /$(2 ) /node_address.txt )
83+ endef
84+
85+ define run_bootnode
86+ @$(GETHBIN ) /bootnode -nodekey $(1 ) /$(BOOTNODE ) /bootnode.key \
87+ -addr :$(BOOTNODE_PORT ) \
88+ -verbosity $(BOOTNODE_LOGLEVEL ) > $(1 ) /$(BOOTNODE ) /bootnode.log 2>&1 &
89+ endef
90+
91+ define run_miner_node
92+ $(call run_node,$(1 ) ,$(2 ) ,$(3 ) ,$(4 ) ,--mine --miner.etherbase="0x$$(cat $(1 ) /$(5 ) /node_address.txt ) ")
93+ endef
94+
95+ define run_node
96+ @$(GETHBIN ) /geth --datadir $(1 ) /$(2 ) \
97+ --port $(3 ) \
98+ --bootnodes "enode://$$(cat $(1 ) /$(BOOTNODE ) /bootnode_address.txt ) @127.0.0.1:0?discport=$(BOOTNODE_PORT ) " \
99+ --networkid "$$(cat $(1 ) /networkid.txt ) " \
100+ --unlock 0x"$$(cat $(1 ) /$(2 ) /node_address.txt ) " \
101+ --authrpc.port $(4 ) \
102+ --password $(1 ) /$(2 ) /password.txt \
103+ --metrics \
104+ --nat $(NAT_POLICY ) \
105+ --netrestrict $(RESTRICTED_NETWORK ) \
106+ $(5 ) > $(1 ) /$(2 ) /geth_node.log 2>&1 &
107+ endef
108+
109+ define copy_genesis
110+ @cp $(1 ) /$(GENESIS_WORK_JSON ) $(1 ) /$(2 ) /$(GENESIS_WORK_JSON )
111+ endef
112+
113+ define init_node
114+ @$(GETHBIN ) /geth init --datadir $(1 ) /$(2 ) $(1 ) /$(2 ) /$(GENESIS_WORK_JSON ) > $(1 ) /$(2 ) /geth_init.log 2>&1
115+ endef
116+
117+ geth :
118+ $(GORUN ) build/ci.go install ./cmd/geth
119+ @echo " Done building."
120+ @echo " Run \" $( GETHBIN) /geth\" to launch geth."
121+
122+ all :
123+ $(GORUN ) build/ci.go install
124+
125+ test : all
126+ $(GORUN ) build/ci.go test
127+
128+ lint : # # Run linters.
129+ $(GORUN ) build/ci.go lint
130+
131+ clean :
132+ go clean -cache
133+ rm -fr build/_workspace/pkg/ $(GETHBIN ) /*
134+
135+ # The devtools target installs tools required for 'go generate'.
136+ # You need to put $GOBIN (or $GOPATH/bin) in your PATH to use 'go generate'.
137+
138+ devtools :
139+ env GOBIN= go install golang.org/x/tools/cmd/stringer@latest
140+ env GOBIN= go install github.com/fjl/gencodec@latest
141+ env GOBIN= go install github.com/golang/protobuf/protoc-gen-go@latest
142+ env GOBIN= go install ./cmd/abigen
143+ @type " solc" 2> /dev/null || echo ' Please install solc'
144+ @type " protoc" 2> /dev/null || echo ' Please install protoc'
145+
146+ # Privnet targets
147+
148+ privnet_init : privnet_clean
149+ @find $(SINGLE_DIR ) /* -type d -name ' keystore' -exec rm -rf {} +
150+ @mkdir -p $(SINGLE_DIR )
151+ @echo " Generate $( GENESIS_WORK_JSON) file"
152+ @cp $(SINGLE_DIR ) /genesis_template.json $(SINGLE_DIR ) /$(GENESIS_WORK_JSON )
153+ @echo $$(date +'%y%m%d%H%M' ) > $(SINGLE_DIR ) /networkid.txt
154+ @echo " Network ID is " $$(cat $(SINGLE_DIR ) /networkid.txt )
155+ @echo " Generate bootnode"
156+ $(call generate_bootnode,$(SINGLE_DIR ) )
157+ $(call replace_chainid,$(SINGLE_DIR ) )
158+ @echo " Create accounts"
159+ $(call create_account,$(SINGLE_DIR ) ,$(NODE1 ) )
160+ $(call create_account,$(SINGLE_DIR ) ,$(NODE2 ) )
161+ @echo " Copy genesis_privnet.json into nodes"
162+ $(call copy_genesis,$(SINGLE_DIR ) ,$(NODE1 ) )
163+ $(call copy_genesis,$(SINGLE_DIR ) ,$(NODE2 ) )
164+ @rm $(SINGLE_DIR ) /$(GENESIS_WORK_JSON )
165+ @echo " OK! For starting use 'make privnet_start'"
166+
167+ privnet_init_four : privnet_clean
168+ @find $(FOUR_DIR ) /* -type d -name ' keystore' -exec rm -rf {} +
169+ @mkdir -p $(FOUR_DIR )
170+ @echo " Generate $( GENESIS_WORK_JSON) file"
171+ @cp $(FOUR_DIR ) /genesis_template.json $(FOUR_DIR ) /$(GENESIS_WORK_JSON )
172+ @echo $$(date +'%y%m%d%H%M' ) > $(FOUR_DIR ) /networkid.txt
173+ @echo " Network ID is " $$(cat $(FOUR_DIR ) /networkid.txt )
174+ @echo " Generate bootnode"
175+ $(call generate_bootnode,$(FOUR_DIR ) )
176+ $(call replace_chainid,$(FOUR_DIR ) )
177+ @echo " Create accounts"
178+ $(call create_account,$(FOUR_DIR ) ,$(NODE1 ) )
179+ $(call create_account,$(FOUR_DIR ) ,$(NODE2 ) )
180+ $(call create_account,$(FOUR_DIR ) ,$(NODE3 ) )
181+ $(call create_account,$(FOUR_DIR ) ,$(NODE4 ) )
182+ $(call create_account,$(FOUR_DIR ) ,$(NODE5 ) )
183+ @echo " Copy genesis_privnet.json into nodes"
184+ $(call copy_genesis,$(FOUR_DIR ) ,$(NODE1 ) )
185+ $(call copy_genesis,$(FOUR_DIR ) ,$(NODE2 ) )
186+ $(call copy_genesis,$(FOUR_DIR ) ,$(NODE3 ) )
187+ $(call copy_genesis,$(FOUR_DIR ) ,$(NODE4 ) )
188+ $(call copy_genesis,$(FOUR_DIR ) ,$(NODE5 ) )
189+ @rm $(FOUR_DIR ) /$(GENESIS_WORK_JSON )
190+ @echo " OK! For starting use 'make privnet_start_four'"
191+
192+ privnet_init_seven : privnet_clean
193+ @find $(SEVEN_DIR ) /* -type d -name ' keystore' -exec rm -rf {} +
194+ @mkdir -p $(SEVEN_DIR )
195+ @echo " Generate $( GENESIS_WORK_JSON) file"
196+ @cp $(SEVEN_DIR ) /genesis_template.json $(SEVEN_DIR ) /$(GENESIS_WORK_JSON )
197+ @echo $$(date +'%y%m%d%H%M' ) > $(SEVEN_DIR ) /networkid.txt
198+ @echo " Network ID is " $$(cat $(SEVEN_DIR ) /networkid.txt )
199+ @echo " Generate bootnode"
200+ $(call generate_bootnode,$(SEVEN_DIR ) )
201+ $(call replace_chainid,$(SEVEN_DIR ) )
202+ @echo " Create accounts"
203+ $(call create_account,$(SEVEN_DIR ) ,$(NODE1 ) )
204+ $(call create_account,$(SEVEN_DIR ) ,$(NODE2 ) )
205+ $(call create_account,$(SEVEN_DIR ) ,$(NODE3 ) )
206+ $(call create_account,$(SEVEN_DIR ) ,$(NODE4 ) )
207+ $(call create_account,$(SEVEN_DIR ) ,$(NODE5 ) )
208+ $(call create_account,$(SEVEN_DIR ) ,$(NODE6 ) )
209+ $(call create_account,$(SEVEN_DIR ) ,$(NODE7 ) )
210+ $(call create_account,$(SEVEN_DIR ) ,$(NODE8 ) )
211+ @echo " Copy genesis_privnet.json into nodes"
212+ $(call copy_genesis,$(SEVEN_DIR ) ,$(NODE1 ) )
213+ $(call copy_genesis,$(SEVEN_DIR ) ,$(NODE2 ) )
214+ $(call copy_genesis,$(SEVEN_DIR ) ,$(NODE3 ) )
215+ $(call copy_genesis,$(SEVEN_DIR ) ,$(NODE4 ) )
216+ $(call copy_genesis,$(SEVEN_DIR ) ,$(NODE5 ) )
217+ $(call copy_genesis,$(SEVEN_DIR ) ,$(NODE6 ) )
218+ $(call copy_genesis,$(SEVEN_DIR ) ,$(NODE7 ) )
219+ $(call copy_genesis,$(SEVEN_DIR ) ,$(NODE8 ) )
220+ @rm $(SEVEN_DIR ) /$(GENESIS_WORK_JSON )
221+ @echo " OK! For starting use 'make privnet_start_seven'"
222+
223+ privnet_nodes_stop :
224+ @echo " Killing nodes processes"
225+ @killall -w -v -INT geth || :
226+
227+ privnet_bootnode_stop :
228+ @echo " Killing bootnode processes"
229+ @killall -w -v -9 bootnode || :
230+
231+ privnet_stop : privnet_bootnode_stop privnet_nodes_stop
232+
233+ privnet_clean : privnet_stop
234+ @echo " Cleaning the nodes database files from $( MAIN_DIR) "
235+ @find $(MAIN_DIR ) /* -type d -name ' geth' -print -exec rm -rf {} +
236+ @find $(MAIN_DIR ) /* -type s,f -not \( -path ' */keystore/*' -or -name ' *.json' -or -name ' *.txt' -or -name ' *.key' -or -name ' *.md' \) -print -exec rm -f {} +
237+
238+ $(SINGLE_DIR ) /$(NODE1 ) /geth :
239+ @echo " Initializing $( NODE1) from genesis"
240+ $(call init_node,$(SINGLE_DIR ) ,$(NODE1 ) )
241+
242+ $(SINGLE_DIR ) /$(NODE2 ) /geth :
243+ @echo " Initializing $( NODE2) from genesis"
244+ $(call init_node,$(SINGLE_DIR ) ,$(NODE2 ) )
245+
246+ $(FOUR_DIR ) /$(NODE1 ) /geth :
247+ @echo " Initializing $( NODE1) from genesis"
248+ $(call init_node,$(FOUR_DIR ) ,$(NODE1 ) )
249+
250+ $(FOUR_DIR ) /$(NODE2 ) /geth :
251+ @echo " Initializing $( NODE2) from genesis"
252+ $(call init_node,$(FOUR_DIR ) ,$(NODE2 ) )
253+
254+ $(FOUR_DIR ) /$(NODE3 ) /geth :
255+ @echo " Initializing $( NODE3) from genesis"
256+ $(call init_node,$(FOUR_DIR ) ,$(NODE3 ) )
257+
258+ $(FOUR_DIR ) /$(NODE4 ) /geth :
259+ @echo " Initializing $( NODE4) from genesis"
260+ $(call init_node,$(FOUR_DIR ) ,$(NODE4 ) )
261+
262+ $(FOUR_DIR ) /$(NODE5 ) /geth :
263+ @echo " Initializing $( NODE5) from genesis"
264+ $(call init_node,$(FOUR_DIR ) ,$(NODE5 ) )
265+
266+ $(SEVEN_DIR ) /$(NODE1 ) /geth :
267+ @echo " Initializing $( NODE1) from genesis"
268+ $(call init_node,$(SEVEN_DIR ) ,$(NODE1 ) )
269+
270+ $(SEVEN_DIR ) /$(NODE2 ) /geth :
271+ @echo " Initializing $( NODE2) from genesis"
272+ $(call init_node,$(SEVEN_DIR ) ,$(NODE2 ) )
273+
274+ $(SEVEN_DIR ) /$(NODE3 ) /geth :
275+ @echo " Initializing $( NODE3) from genesis"
276+ $(call init_node,$(SEVEN_DIR ) ,$(NODE3 ) )
277+
278+ $(SEVEN_DIR ) /$(NODE4 ) /geth :
279+ @echo " Initializing $( NODE4) from genesis"
280+ $(call init_node,$(SEVEN_DIR ) ,$(NODE4 ) )
281+
282+ $(SEVEN_DIR ) /$(NODE5 ) /geth :
283+ @echo " Initializing $( NODE5) from genesis"
284+ $(call init_node,$(SEVEN_DIR ) ,$(NODE5 ) )
285+
286+ $(SEVEN_DIR ) /$(NODE6 ) /geth :
287+ @echo " Initializing $( NODE6) from genesis"
288+ $(call init_node,$(SEVEN_DIR ) ,$(NODE6 ) )
289+
290+ $(SEVEN_DIR ) /$(NODE7 ) /geth :
291+ @echo " Initializing $( NODE7) from genesis"
292+ $(call init_node,$(SEVEN_DIR ) ,$(NODE7 ) )
293+
294+ $(SEVEN_DIR ) /$(NODE8 ) /geth :
295+ @echo " Initializing $( NODE8) from genesis"
296+ $(call init_node,$(SEVEN_DIR ) ,$(NODE8 ) )
297+
298+ privnet_start : $(SINGLE_DIR ) /$(NODE1 ) /geth $(SINGLE_DIR ) /$(NODE2 ) /geth
299+ @echo " Starting nodes..."
300+ $(call run_bootnode,$(SINGLE_DIR ) )
301+ $(call run_miner_node,$(SINGLE_DIR ) ,$(NODE1 ) ,$(NODE1_PORT ) ,$(NODE1_RPC_PORT ) ,$(NODE1 ) )
302+ $(call run_node,$(SINGLE_DIR ) ,$(NODE2 ) ,$(NODE2_PORT ) ,$(NODE2_RPC_PORT ) )
303+ @echo " OK! Check logs in $( SINGLE_DIR) /<node_dir>/geth_node.log"
304+
305+ privnet_start_four : $(FOUR_DIR ) /$(NODE1 ) /geth $(FOUR_DIR ) /$(NODE2 ) /geth $(FOUR_DIR ) /$(NODE3 ) /geth $(FOUR_DIR ) /$(NODE4 ) /geth $(FOUR_DIR ) /$(NODE5 ) /geth
306+ @echo " Starting nodes..."
307+ $(call run_bootnode,$(FOUR_DIR ) )
308+ $(call run_miner_node,$(FOUR_DIR ) ,$(NODE1 ) ,$(NODE1_PORT ) ,$(NODE1_RPC_PORT ) ,$(NODE1 ) )
309+ $(call run_miner_node,$(FOUR_DIR ) ,$(NODE2 ) ,$(NODE2_PORT ) ,$(NODE2_RPC_PORT ) ,$(NODE2 ) )
310+ $(call run_miner_node,$(FOUR_DIR ) ,$(NODE3 ) ,$(NODE3_PORT ) ,$(NODE3_RPC_PORT ) ,$(NODE3 ) )
311+ $(call run_miner_node,$(FOUR_DIR ) ,$(NODE4 ) ,$(NODE4_PORT ) ,$(NODE4_RPC_PORT ) ,$(NODE4 ) )
312+ $(call run_node,$(FOUR_DIR ) ,$(NODE5 ) ,$(NODE5_PORT ) ,$(NODE5_RPC_PORT ) )
313+ @echo " OK! Check logs in $( FOUR_DIR) /<node_dir>/geth_node.log"
314+
315+ privnet_start_seven : $(SEVEN_DIR ) /$(NODE1 ) /geth $(SEVEN_DIR ) /$(NODE2 ) /geth $(SEVEN_DIR ) /$(NODE3 ) /geth $(SEVEN_DIR ) /$(NODE4 ) /geth $(SEVEN_DIR ) /$(NODE5 ) /geth $(SEVEN_DIR ) /$(NODE6 ) /geth $(SEVEN_DIR ) /$(NODE7 ) /geth $(SEVEN_DIR ) /$(NODE8 ) /geth
316+ @echo " Starting nodes..."
317+ $(call run_bootnode,$(SEVEN_DIR ) )
318+ $(call run_miner_node,$(SEVEN_DIR ) ,$(NODE1 ) ,$(NODE1_PORT ) ,$(NODE1_RPC_PORT ) ,$(NODE1 ) )
319+ $(call run_miner_node,$(SEVEN_DIR ) ,$(NODE2 ) ,$(NODE2_PORT ) ,$(NODE2_RPC_PORT ) ,$(NODE2 ) )
320+ $(call run_miner_node,$(SEVEN_DIR ) ,$(NODE3 ) ,$(NODE3_PORT ) ,$(NODE3_RPC_PORT ) ,$(NODE3 ) )
321+ $(call run_miner_node,$(SEVEN_DIR ) ,$(NODE4 ) ,$(NODE4_PORT ) ,$(NODE4_RPC_PORT ) ,$(NODE4 ) )
322+ $(call run_miner_node,$(SEVEN_DIR ) ,$(NODE5 ) ,$(NODE5_PORT ) ,$(NODE5_RPC_PORT ) ,$(NODE5 ) )
323+ $(call run_miner_node,$(SEVEN_DIR ) ,$(NODE6 ) ,$(NODE6_PORT ) ,$(NODE6_RPC_PORT ) ,$(NODE6 ) )
324+ $(call run_miner_node,$(SEVEN_DIR ) ,$(NODE7 ) ,$(NODE7_PORT ) ,$(NODE7_RPC_PORT ) ,$(NODE7 ) )
325+ $(call run_node,$(SEVEN_DIR ) ,$(NODE8 ) ,$(NODE8_PORT ) ,$(NODE8_RPC_PORT ) )
326+ @echo " OK! Check logs in $( SEVEN_DIR) /<node_dir>/geth_node.log"
0 commit comments