Last active
July 25, 2018 20:40
-
-
Save UnitylChaos/bd688892b369ef77edb3ad7255bb22d8 to your computer and use it in GitHub Desktop.
Gaia-7002 builder
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 | |
from hashlib import sha256 | |
from base64 import b64decode | |
j = json.loads(open("7001state.json","r").read()) | |
#validator addresses which hubble lists as being bonded validators but never signed a block | |
pks = ['28d64d33cd086452e491becfc15f3d31054db144', '26cf59b48aa6ff3a5126330782090b19bd3b0e87', '1e1a2486dce3b96e08f41d313908088ad33ed491', '1866433301a542afd800b971d6390551088a0903', '10ddf9c6aaf8e6f91f33a4fae3ebeab3c98136d2', '00122e5e691286ac03220fcee3ebec038067dded', '60229e2e273297fe00219e46dffb8f76844cdef9', 'd9e215abd1d680db4d60f3b347a07f949ea5242a', 'e33184c1eab6fb7c6ccb893963e8534c277fa842', 'd9bb73add5962326c5b8c36494dac1c3d7425db5', 'cc4c1d46ddba0912e9d6e4dd1f4a0897a945c68c', 'b3cec3cbafba428bf33fd2204e11ca2232426593', '9a03741063366e11ec0347f6c80a2891c799003f', '5a6b67f68591404c5079bebd7a6b7e046779d3b6', '4b75e0191ab777afb6787b94e256388e78d6a910', '3e504d10079dc278960c0f214235b840e23392b2', '52b590a0de161917dfa8215f990506c4df7a9d0d', '09f1395bfcdb45aa6f09cde85aa8b69246131962', 'ebcaa6886da3c8ac73cfdf8fea26e8d9b14b4e4e'] | |
#remove validators who never came online according to hubble | |
j['app_state']['stake']['validators'] = [vi for vi in j['app_state']['stake']['validators'] if sha256(b64decode(vi['pub_key']['value'])).digest().hex()[:40] not in pks] | |
#filter out bonds to no longer existing validators | |
j['app_state']['stake']['bonds'] = [b for b in j['app_state']['stake']['bonds'] if b['validator_addr'] in [v['owner'] for v in j['app_state']['stake']['validators']]] | |
#set bonded status and fix do-not-modify flag on validators | |
for v in j['app_state']['stake']['validators']: | |
desc = v["description"] | |
for k,dv in desc.items(): | |
if dv == "[do-not-modify]": | |
dv = "" | |
desc[k] = dv | |
v.update(status=2, description=desc) | |
#adding a validator for shapeshift | |
j['app_state']['stake']['validators'].append({ | |
"owner": "cosmosaccaddr1ztc70khr9aghgwmuxap5y9ufavpxutjtkvhpe7", | |
"pub_key": { | |
"type": "tendermint/PubKeyEd25519", | |
"value": "7vURd1EqPVfI/1viF/+LNm9lwaBAN/tSuoJ+Od972z0=" | |
}, | |
"revoked": False, | |
"status": 2, | |
"tokens": "100", | |
"delegator_shares": "100", | |
"description": { | |
"moniker": "Project Bohr", | |
"identity": "", | |
"website": "", | |
"details": "" | |
}, | |
"bond_height": "0", | |
"bond_intra_tx_counter": 0, | |
"proposer_reward_pool": None, | |
"commission": "0", | |
"commission_max": "0", | |
"commission_change_rate": "0", | |
"commission_change_today": "0", | |
"prev_bonded_tokens": "0" | |
}) | |
j['app_state']['stake']['bonds'].append({ | |
'height': '0', 'validator_addr': 'cosmosaccaddr1ztc70khr9aghgwmuxap5y9ufavpxutjtkvhpe7', 'delegator_addr': 'cosmosaccaddr1ztc70khr9aghgwmuxap5y9ufavpxutjtkvhpe7', 'shares': '100' | |
}) | |
#update main validator section to match validators from state machine | |
j["validators"] = [{"pub_key":v["pub_key"], "power":v["tokens"], "name":v["description"]["moniker"]} for v in j["app_state"]["stake"]["validators"]] | |
coinsToMap = lambda x: type(x)==list and {c["denom"]:c["amount"] for c in x} or {} | |
#update pool total values to be accurate | |
j["app_state"]["stake"]["pool"]["loose_tokens"] = str(sum([int(coinsToMap(a["coins"]).get("steak",0)) for a in j["app_state"]["accounts"]])) | |
j["app_state"]["stake"]["pool"]["bonded_tokens"] = str(sum([int(v["power"]) for v in j["validators"]])) | |
#set chain id and timestamp | |
j["chain_id"] = "gaia-7002" | |
j["genesis_time"] = "2018-07-24T08:00:00.123456789Z" | |
open("7002-genesis.json","w").write(json.dumps(j, indent=2, sort_keys=True)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment