Skip to content

Instantly share code, notes, and snippets.

@yihuang
Created December 9, 2020 01:56
Show Gist options
  • Save yihuang/5e62f7d9e75dd159bbb85ece6f11c76e to your computer and use it in GitHub Desktop.
Save yihuang/5e62f7d9e75dd159bbb85ece6f11c76e to your computer and use it in GitHub Desktop.
migrate tendermint genesis file
import base64
import json
# import hashlib
import sys
import bech32
def clear_staking(genesis):
del genesis["validators"]
staking = genesis["app_state"]["staking"]
staking.update(
{
"validators": [],
"exported": False,
"last_validator_powers": [],
"last_total_power": "0",
"delegations": [],
"redelegations": [],
"unbonding_delegations": [],
}
)
def add_defaults(genesis):
genesis["app_state"].update(
{
"capability": {"index": "1", "owners": []},
"ibc": {
"channel_genesis": {
"ack_sequences": [],
"acknowledgements": [],
"channels": [],
"commitments": [],
"receipts": [],
"recv_sequences": [],
"send_sequences": [],
},
"client_genesis": {
"clients": [],
"clients_consensus": [],
"create_localhost": False,
},
"connection_genesis": {
"client_connection_paths": [],
"connections": [],
},
},
"supply": {},
"transfer": {
"denom_traces": [],
"params": {"receive_enabled": False, "send_enabled": False},
"port_id": "transfer",
},
"upgrade": {},
"vesting": {},
}
)
def convert_pubkey(genesis):
for val in genesis["app_state"]["staking"]["validators"]:
prefix, data = bech32.bech32_decode(val["consensus_pubkey"])
data = bech32.convertbits(data, 5, 8, False)
data = bytes(data[5:]) # skip amino encoding overhead
val["consensus_pubkey"] = {
"@type": "/cosmos.crypto.ed25519.PubKey",
"key": base64.b64encode(data).decode(),
}
genesis = json.load(sys.stdin)
add_defaults(genesis)
# clear_staking(genesis)
convert_pubkey(genesis)
json.dump(genesis, sys.stdout, indent=4)
sys.stdout.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment