forked from bitshares/bitshares1-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
new_testnet.py
85 lines (66 loc) · 2.79 KB
/
new_testnet.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import os
import sys
import subprocess
import json
import datetime
import re #regex
ip = "127.0.0.1"
if len(sys.argv) > 1:
ip = sys.argv[1]
print "This will create a new genesis block and make changes to your config files."
n = raw_input("Overwrite config files? [Y/n]")
if n == "n":
sys.exit(0)
input_log = []
input_log.append(">>> wallet_create default password")
input_log.append(">>> wallet_set_automatic_backups false ")
new_genesis = {}
with open("libraries/blockchain/genesis.json") as genesis:
new_genesis = json.load(genesis)
new_genesis["timestamp"] = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S")
new_genesis["delegates"] = []
#try:
# with open("libraries/blockchain/bts-sharedrop.json") as snapshot:
# items = json.loads(snapshot.read())
# for item in items:
# new_genesis["bts_sharedrop"].append(item)
#except Exception:
# pass
for i in range(101):
keys = json.loads(subprocess.check_output(["./programs/utils/bts_create_key"]))
input_log.append(">>> wallet_import_private_key " + keys["wif_private_key"])
acct = {
"name": "init" + str(i),
"owner": keys["public_key"]
}
new_genesis["delegates"].append(acct)
input_log.append(">>> wallet_delegate_set_block_production ALL true")
input_log.append(">>> wallet_set_transaction_scanning true")
with open("libraries/blockchain/include/bts/blockchain/config.hpp") as config:
with open("tmp_config", "w") as tmp:
for line in config:
if line.startswith("#define BTS_TEST_NETWORK_VERSION"):
n = int(re.findall(r'\d+', line)[0])
tmp.write("#define BTS_TEST_NETWORK_VERSION " + str(n+1) + " // autogenerated\n")
else:
tmp.write(line)
os.rename("tmp_config", "libraries/blockchain/include/bts/blockchain/config.hpp")
#with open("libraries/net/include/bts/net/config.hpp") as config:
# with open("tmp_config", "w") as tmp:
# for line in config:
# if line.startswith("#define BTS_NET_TEST_SEED_IP"):
# n = int(re.findall(r'\d+', line)[0])
# tmp.write("#define BTS_NET_TEST_SEED_IP \"" + ip + "\" // autogenerated\n")
# else:
# tmp.write(line)
#os.rename("tmp_config", "libraries/net/include/bts/net/config.hpp")
old_balances = []
with open("libraries/blockchain/genesis.json", "w") as genesis:
genesis.write(json.dumps(new_genesis, indent=4))
with open("testnet_setup_log.txt", "w") as log:
for line in input_log:
log.write(line + "\n")
n = raw_input("Start build? [Y/n]")
if n != "n":
subprocess.call(["make", "-j2"])
subprocess.call(["./programs/client/bitsharestestnet_client", "--input-log", "testnet_setup_log.txt", "--min-delegate-connection-count", "0"])