-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoa-generate-yaml.py
67 lines (62 loc) · 3.22 KB
/
poa-generate-yaml.py
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
import json
import yaml
import sys
import os
from collections import OrderedDict
# python poa-generate-yaml.py number_node config_file local_path
number_node = int(sys.argv[1])
config_file = sys.argv[2]
if len(sys.argv) > 3:
local_path = sys.argv[3]
else:
local_path = os.path.dirname(os.path.abspath(__file__)) + '/seed_data'
with open(config_file, "r") as f:
config = json.load(f)
chain_id = config.get("chain_id", 42)
block_time = config.get("block_time", 12)
gas_limit = hex(config.get("gas_limit", 30000000))
yaml_file = {'version':'3'}
nodes = {}
for i in range(1,number_node+1):
node={}
http_port=str(30312+i)
port=str(8502+i)
ws_port = str(33444+i)
node['hostname']='node_'+str(i)
node['image']='ethereum/client-go:release-1.10'
command = (
"cp -r /root/data /root/data2 ; "
"geth account import --datadir /root/data2 --password /root/files/password /root/files/priv.key ; "
"geth --datadir /root/data2 init /root/files/genesis.json ; "
"geth --datadir /root/data2 --nodiscover --syncmode full --nodekey /root/files/priv.key --port " + str(http_port) + " "
"--http --http.addr \"0.0.0.0\" --http.vhosts=\"*\" --http.corsdomain=\"*\" --http.port " + str(port) + " "
"--http.api db,eth,net,web3,admin,personal,miner,signer:insecure_unlock_protect --networkid " + str(chain_id) + " "
"--unlock 0 --password /root/files/password --mine --allow-insecure-unlock --ws --ws.port " + str(ws_port) + " "
"--ws.addr \"0.0.0.0\" --ws.origins=\"*\" --ws.api eth,net,web3"
)
node['command']= [command]
node['entrypoint'] = '/bin/sh -c'
volumes=[]
volumes.append("${DATA_PATH_PREFIX}/seed_data/node_" + str(i)+'/keys/password:/root/files/password:ro')
volumes.append("${DATA_PATH_PREFIX}/seed_data/node_" + str(i)+'/keys/priv.key:/root/files/priv.key:ro')
volumes.append("${DATA_PATH_PREFIX}/seed_data/genesis.json:/root/files/genesis.json:ro")
volumes.append("${DATA_PATH_PREFIX}/seed_data/node_" + str(i)+'/data:/root/data:ro')
ports=[]
ports.append(http_port+':'+http_port)
ports.append(port+':'+port)
ports.append(ws_port+':'+ws_port)
node['volumes']=volumes
node['ports']=ports
nodes.update({ 'node'+str(i) : node })
yaml_file['services']= nodes
stream = open('docker-compose.yaml', 'w')
yaml.dump(yaml_file, stream)
# node['command']= ("/bin/sh -c '"
# "cp -r /root/data /root/data2;
# 'geth account import --datadir /root/data2 --password /root/files/password /root/files/priv.key; '
# 'geth --datadir /root/data2 init /root/files/genesis.json; ' +
# 'geth --datadir /root/data2 --nodiscover --syncmode full --nodekey /root/files/priv.key --port '+ str(http_port)+
# ' --http --http.addr "0.0.0.0" --http.vhosts="*" --http.corsdomain="*" --http.port '+str(port)+
# ' --http.api db,eth,net,web3,admin,personal,miner,signer:insecure_unlock_protect --networkid '+str(chain_id)+
# ' --unlock 0 --password /root/files/password --mine --allow-insecure-unlock --ws --ws.port '+str(ws_port)+
# ' --ws.addr "0.0.0.0" --ws.origins="*" --ws.api eth,net,web3')