forked from osmosis-labs/osmosis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add validator csv creator scriotp (osmosis-labs#5823)
- Loading branch information
1 parent
bf34c09
commit 414e57f
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import subprocess, json, csv | ||
|
||
pagination_limit = 1000 | ||
num_validators = 150 | ||
command = "osmosisd q staking validators --output=json --limit=1000" | ||
|
||
# Execute the shell command and capture the response | ||
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) | ||
output, _ = process.communicate() | ||
|
||
# Parse the response as JSON | ||
response = json.loads(output) | ||
|
||
# Extract desired fields from each entry | ||
data = [] | ||
for validator in response["validators"]: | ||
moniker = validator["description"]["moniker"] | ||
operator_address = validator["operator_address"] | ||
tokens = validator["tokens"] | ||
data.append([moniker, operator_address, tokens]) | ||
|
||
data.sort(key=lambda x: float(x[2]), reverse=True) | ||
data = data[:num_validators] | ||
total_stake = sum([float(x[2]) for x in data]) | ||
|
||
# add new column for percent of total stake | ||
for i in range(len(data)): | ||
data[i].append(float(data[i][2]) / total_stake) | ||
|
||
# Export data to CSV | ||
csv_filename = "validator_data.csv" | ||
with open(csv_filename, "w", newline="") as csvfile: | ||
writer = csv.writer(csvfile) | ||
writer.writerow(["Moniker", "Operator Address", "Tokens", "Percent vp"]) # Header row | ||
writer.writerows(data) | ||
|
||
print(f"CSV file '{csv_filename}' has been created successfully.") |