Last active
December 23, 2020 08:31
-
-
Save yihuang/76c9fee0a43f3187f676427f508a6de4 to your computer and use it in GitHub Desktop.
testnet upgrade scripts
This file contains hidden or 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
import json | |
import sys | |
if len(sys.argv) < 3: | |
print( | |
"""add_genesis_accounts.py accounts.json path/to/genesis.json | |
new genesis file is print to stdout | |
""", | |
file=sys.stderr, | |
) | |
sys.exit(1) | |
accounts = json.load(open(sys.argv[1])) | |
genesis = json.load(open(sys.argv[2])) | |
state = genesis["app_state"] | |
for i, account in enumerate(accounts): | |
state["auth"]["accounts"].append( | |
{ | |
"@type": "/cosmos.auth.v1beta1.BaseAccount", | |
"address": account, | |
"pub_key": None, | |
"account_number": "0", | |
"sequence": "0", | |
} | |
) | |
state["bank"]["balances"].append( | |
{ | |
"address": account, | |
"coins": [{"denom": "basetcro", "amount": "50000000000000"}], | |
} | |
) | |
print(json.dumps(genesis, indent=4)) |
This file contains hidden or 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
import json | |
import sys | |
genesis = json.load(open(sys.argv[1])) | |
addresses = set( | |
acct["address"] | |
for acct in genesis["app_state"]["auth"]["accounts"] | |
if acct["@type"] == "/cosmos.auth.v1beta1.BaseAccount" | |
) | |
json.dump(list(sorted(addresses)), sys.stdout) |
This file contains hidden or 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
set -e | |
# export accounts from current testnet | |
./testnet/bin/chain-maind export --for-zero-height --home /tmp/testnet_data > exported.json | |
python export_accounts.py exported.json > accounts.json | |
# init new testnet | |
pystarport --cmd ./testnet/bin/chain-maind init | |
# import genesis accounts into genesis | |
python add_genesis_accounts.py accounts.json data/chainmaind/genesis.json > /tmp/genesis.json | |
# update genesis file and start | |
cp /tmp/genesis.json data/chainmaind/genesis.json | |
cp /tmp/genesis.json data/chainmaind/node0/config/genesis.json | |
cp /tmp/genesis.json data/chainmaind/node1/config/genesis.json | |
pystarport start | |
./testnet/bin/chain-maind q bank balances tcro1zy7jl6hmrmlweg2qlzwwuz85jz68fhvmaavpwp | |
# balances: | |
# - amount: "50000000000000" | |
# denom: basetcro | |
# pagination: | |
# next_key: null | |
# total: "0" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment