11#!/usr/bin/env python3
2- import csv
32import json
43import os
54import glob
65
76
87def read_validators (directory ):
9- """Read all validator JSON files from a directory and return dict mapping secp to name ."""
8+ """Read all validator JSON files from a directory and return dict mapping secp to full validator object ."""
109 validators_dict = {}
1110 json_files = glob .glob (os .path .join (directory , "*.json" ))
1211
@@ -15,16 +14,15 @@ def read_validators(directory):
1514 with open (json_file , "r" ) as f :
1615 data = json .load (f )
1716
18- # Extract fields
19- name = data .get ("name" , "" ).strip ()
17+ # Extract secp key
2018 secp = data .get ("secp" , "" )
2119
22- # Use secp as fallback if name is empty
23- if not name :
24- name = secp
20+ # Use secp as fallback for name if name is empty
21+ if not data . get ( " name" , "" ). strip () :
22+ data [ " name" ] = secp
2523
26- # Map secp key to validator name
27- validators_dict [secp ] = name
24+ # Map secp key to full validator object
25+ validators_dict [secp ] = data
2826
2927 except (json .JSONDecodeError , IOError ) as e :
3028 print (f"Warning: Failed to read { json_file } : { e } " )
@@ -34,25 +32,13 @@ def read_validators(directory):
3432
3533
3634def write_json (validators_dict , output_file ):
37- """Write validators to JSON file with secp as key and name as value."""
35+ """Write validators to JSON file with secp as key and full validator object as value."""
3836 with open (output_file , "w" ) as f :
3937 json .dump (validators_dict , f , indent = 2 )
4038
4139 print (f"✅ Generated { output_file } with { len (validators_dict )} validators" )
4240
4341
44- def write_csv (validators_dict , output_file ):
45- """Write validators to CSV file with secp_key and name columns."""
46- with open (output_file , "w" , newline = "" ) as f :
47- writer = csv .writer (f )
48- writer .writerow (["secp_key" , "name" ])
49-
50- for secp , name in validators_dict .items ():
51- writer .writerow ([secp , name ])
52-
53- print (f"✅ Generated { output_file } with { len (validators_dict )} validators" )
54-
55-
5642def main ():
5743 # Get the project root directory (parent of scripts/)
5844 script_dir = os .path .dirname (os .path .abspath (__file__ ))
@@ -61,16 +47,15 @@ def main():
6147 # Process mainnet validators
6248 mainnet_dir = os .path .join (project_root , "mainnet" )
6349 mainnet_validators = read_validators (mainnet_dir )
64- write_json ( mainnet_validators , "mainnet_validators.json" )
65- write_csv (mainnet_validators , "mainnet_validators.csv" )
50+ mainnet_json = os . path . join ( mainnet_dir , "mainnet_validators.json" )
51+ write_json (mainnet_validators , mainnet_json )
6652
6753 # Process testnet validators
6854 testnet_dir = os .path .join (project_root , "testnet" )
6955 testnet_validators = read_validators (testnet_dir )
70- write_json ( testnet_validators , "testnet_validators.json" )
71- write_csv (testnet_validators , "testnet_validators.csv" )
56+ testnet_json = os . path . join ( testnet_dir , "testnet_validators.json" )
57+ write_json (testnet_validators , testnet_json )
7258
7359
7460if __name__ == "__main__" :
7561 main ()
76-
0 commit comments