Skip to content

Commit

Permalink
Fix gentx scripts (sei-protocol#87)
Browse files Browse the repository at this point in the history
* Fix gentx scripts

* fixes

* rm send enabled deprecated

* more fixes - timestamp and create val

* Revert "rm send enabled deprecated"

This reverts commit 46a6adf.

* Revert "more fixes - timestamp and create val"

This reverts commit 85c07c8.

* set max gas
  • Loading branch information
philipsu522 authored Jul 8, 2022
1 parent c2ccc0a commit 6da073f
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 110 deletions.
63 changes: 63 additions & 0 deletions add-genesis-accounts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from operator import ge
import argparse
import os
import json
import shutil
from pathlib import Path

'''
Resets the genesis.json file to the default values & clears all balances / accounts
Then will generate all the commands to add balances for all gentxs
Assumes you've already run confirm-gen-txs.py
'''

EXP_SEND = [{"denom": "usei","enabled": True}]

def main(chain_id, home_dir, initial_balance):
reset_genesis_file(chain_id, home_dir)
create_genesis_account_cmds(initial_balance)
copy_gentx_folder(chain_id, home_dir)

def reset_genesis_file(chain_id, home_dir):
genesis_file = home_dir + "/config/genesis.json"
# load genesis.json & remove all values for accounts & supply
with open(genesis_file) as f:
genesis = json.load(f)
genesis["chain_id"] = str(chain_id)

genesis["app_state"]['auth']["accounts"] = []
genesis["app_state"]['bank']["balances"] = []
genesis["app_state"]['bank']["supply"] = []
genesis["app_state"]['bank']["params"]["send_enabled"] = EXP_SEND

genesis["app_state"]['genutil']["gen_txs"] = []

# save genesis.json
with open(genesis_file, 'w') as f:
json.dump(genesis, f, indent=4)
print(f"# RESET: {genesis_file}\n")


def create_genesis_account_cmds(initial_balance):
print("-- Run the following commands to create genesis accounts --")
with open('gentx-output.csv') as f:
for line in f:
validator_address = line.split(',')[0]
print(f"seid add-genesis-account {validator_address} {initial_balance}")

print("--- Run the following commands to create genesis accounts ---")

def copy_gentx_folder(chain_id, home_dir):
shutil.copytree(chain_id + "/gentx", home_dir + "/config/gentx")
print(f"gentx folder copied to {home_dir}/config/gentx")
print("--- Run the following command to create validators ---")
print("seid collect-gentxs")

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--chain-id', type=str)
parser.add_argument('--home-dir', type=str)
parser.add_argument('--initial-balance', type=str)
args = parser.parse_args()
assert (args.initial_balance[-4:] == 'usei')
main(args.chain_id, args.home_dir, args.initial_balance)
48 changes: 48 additions & 0 deletions confirm-gen-txs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import argparse
import os
import json

"""
Script to generate a CSV file of $wallet_address,$validator_address,$moniker
Assumes that the file structure of the gentx files is: $chain_id/gentx/...
"""
def main(chain_id):
# get all files within the gentx folder
gentx_files = os.listdir(chain_id + "/gentx")

invalids = ""

with open('gentx-output.csv', 'w') as outfile:
outfile.write("") # clean file

for file in gentx_files:
print(f'Extracting info from {file}')
f = open(chain_id + '/gentx/' + file, 'r')
data = json.load(f)

validatorData = data['body']['messages'][0]
moniker = validatorData['description']['moniker']
rate = float(validatorData['commission']['rate']) * 100
delegator_addr = validatorData['delegator_address']
validator_addr = validatorData['validator_address']
exp = validatorData['value']
### Basic validation ###
if exp['denom'] != 'usei':
invalids += f'[!] Invalid denomination for validator: {moniker} {exp["denom"]} \n'

if int(exp['amount'] ) /10000000 != 1.0:
invalids += f'[!] Invalid amount for validator: {moniker} {int(exp["amount"] ) /10000000}\n'

with open('gentx-output.csv', 'a') as outfile:
outfile.write(f"{delegator_addr},{validator_addr},{moniker}\n")

with open('gentx-output.csv', 'a') as outfile:
outfile.write(invalids)

print('Written to file gentx-output.csv')

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--chain-id', type=str)
args = parser.parse_args()
main(args.chain_id)
2 changes: 1 addition & 1 deletion sei-devnet-1/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"consensus_params": {
"block": {
"max_bytes": "22020096",
"max_gas": "-1",
"max_gas": "6000000",
"time_iota_ms": "1"
},
"evidence": {
Expand Down
Empty file.
1 change: 0 additions & 1 deletion sei-incentivized-testnet/gentx/sample-gentx.json

This file was deleted.

73 changes: 0 additions & 73 deletions sei-testnet-2/add-genesis-accounts.py

This file was deleted.

35 changes: 0 additions & 35 deletions sei-testnet-2/confirmGenTxs.py

This file was deleted.

0 comments on commit 6da073f

Please sign in to comment.