json_modify.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/python
  2. import argparse
  3. import json
  4. def main(chain_path, prefix, number_of_validators):
  5. chain_spec_path = f"{chain_path}/chainspec.json"
  6. print(f"Updating chain spec file {chain_spec_path}")
  7. number_of_validators = int(number_of_validators)
  8. with open(chain_spec_path) as f:
  9. data = json.load(f)
  10. response = {
  11. "name": f'{data["name"]} {prefix}',
  12. "id": f'{data["id"]}_{prefix}',
  13. "protocolId": f'{data["protocolId"]}{prefix}'
  14. }
  15. boot_node_list = data["bootNodes"]
  16. for i in range(1, number_of_validators + 1):
  17. public_key = open(f"{chain_path}/publickey{i}").read().replace('\n', '')
  18. boot_node = f"/dns4/node-{i}/tcp/30333/p2p/{public_key}"
  19. boot_node_list.append(boot_node)
  20. telemetry_endpoints = data["telemetryEndpoints"]
  21. telemetry_endpoints.append([
  22. "/dns/telemetry.joystream.org/tcp/443/x-parity-wss/%2Fsubmit%2F", 0])
  23. response["bootNodes"] = boot_node_list
  24. response["telemetryEndpoints"] = telemetry_endpoints
  25. data.update(response)
  26. with open(chain_spec_path, 'w') as outfile:
  27. json.dump(data, outfile, indent=4)
  28. print("Chain spec file updated")
  29. if __name__ == '__main__':
  30. parser = argparse.ArgumentParser(description='Modify Chain Spec file')
  31. parser.add_argument('--path', required=True, help="Path to chain data")
  32. parser.add_argument('--prefix', required=True, help="Network prefix")
  33. parser.add_argument('--validators', required=True, help="Number of Validators")
  34. args = parser.parse_args()
  35. print(args.path)
  36. main(chain_path=args.path, prefix=args.prefix, number_of_validators=args.validators)