如下图所示,我有三个节点各自的genesis.json文件,如何将它们自己的validator信息统一到一起呢?
通过编写一个简单的Python脚本来实现:
linesArr = []
for i in range(1, 4):
f = open("genesis%d.json" % i, 'r')
linesArr.append(f.readlines())
f.close()
f = open("genesis.json", 'w')
for i in range(len(linesArr)):
lines = linesArr[i]
if i == 0:
for j in range(23):
f.write(lines[j])
for j in range(23, 32):
if i == len(linesArr) - 1:
f.write(lines[j])
else:
if j < 31:
f.write(lines[j])
else:
f.write(lines[j][:len(lines[j]) - 1])
f.write(",\n")
for i in range(32, len(linesArr[0])):
f.write(linesArr[0][i])
f.close()
生成统一的创世文件:
{
"genesis_time": "2023-02-02T05:31:49.854969533Z",
"chain_id": "test-chain",
"initial_height": "0",
"consensus_params": {
"block": {
"max_bytes": "22020096",
"max_gas": "-1",
"time_iota_ms": "1000"
},
"evidence": {
"max_age_num_blocks": "100000",
"max_age_duration": "172800000000000",
"max_bytes": "1048576"
},
"validator": {
"pub_key_types": [
"ed25519"
]
},
"version": {}
},
"validators": [
{
"address": "12C438913EE8FC869278D746FE583B10A1D31CDE",
"pub_key": {
"type": "tendermint/PubKeyEd25519",
"value": "Vt+1LGHE0XfJ0dYaaTFXWXizbD0FwPN0utTpiYm7qxk="
},
"power": "10",
"name": ""
},
{
"address": "7C5F2603A1E2BC54374CEEA7CE13C43B93FEAD30",
"pub_key": {
"type": "tendermint/PubKeyEd25519",
"value": "yk8pct6vI4XeF23KegGSfZtDrCqcXynpXbKBNjCNeyU="
},
"power": "10",
"name": ""
},
{
"address": "D199EF159907F7B19638448A2D766370CEB9EB80",
"pub_key": {
"type": "tendermint/PubKeyEd25519",
"value": "3BXWTneTU5S8vq1O//DKdrt1VkbiK0gPycWoDO10efM="
},
"power": "10",
"name": ""
}
],
"app_hash": ""
}