Skip to content

Instantly share code, notes, and snippets.

@romac
Created April 18, 2024 08:15
Show Gist options
  • Save romac/80eddfd304ec03562badf23d9b43f892 to your computer and use it in GitHub Desktop.
Save romac/80eddfd304ec03562badf23d9b43f892 to your computer and use it in GitHub Desktop.
import json
import toml
import sys
import os
def modify_genesis_json(genesis_path):
# Load the genesis.json file
with open(genesis_path, 'r') as file:
genesis_data = json.load(file)
# Modify the file according to the requirements
genesis_data['app_state']['gov']['params']['max_deposit_period'] = "10s"
genesis_data['app_state']['gov']['params']['voting_period'] = "10s"
if "08-wasm" not in genesis_data['app_state']['ibc']['client_genesis']['params']['allowed_clients']:
genesis_data['app_state']['ibc']['client_genesis']['params']['allowed_clients'].append("08-wasm")
# Save the modified genesis.json file
with open(genesis_path, 'w') as file:
json.dump(genesis_data, file, indent=4)
def modify_config_toml(config_path):
# Load the config.toml file
with open(config_path, 'r') as file:
config_data = toml.load(file)
# Modify the file according to the requirements
config_data['rpc']['max_body_bytes'] = 10001048576
# Save the modified config.toml file
with open(config_path, 'w') as file:
toml.dump(config_data, file)
def main(chain_home):
genesis_path = os.path.join(chain_home, 'config', 'genesis.json')
config_path = os.path.join(chain_home, 'config', 'config.toml')
if not os.path.exists(genesis_path) or not os.path.exists(config_path):
print("Error: The specified paths do not exist.")
sys.exit(1)
modify_genesis_json(genesis_path)
modify_config_toml(config_path)
print("Modification completed successfully.")
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python script.py <path_to_chain_home>")
sys.exit(1)
chain_home = sys.argv[1]
main(chain_home)
import subprocess
import json
import sys
import time
def run_command(command):
result = subprocess.run(command, shell=True, capture_output=True, text=True)
if result.returncode != 0:
return {}
return json.loads(result.stdout)
def get_last_proposal_id(chain_home, node):
while True:
command = f"simd query gov proposals --home {chain_home} --node {node} --output json"
output = run_command(command)
proposals = output.get("proposals")
if not proposals:
print("No proposals found. Waiting...")
time.sleep(2)
continue
deposit_period_proposals = [proposal for proposal in proposals if proposal.get("status") == "PROPOSAL_STATUS_DEPOSIT_PERIOD"]
if deposit_period_proposals:
last_proposal_id = max(int(proposal["id"]) for proposal in deposit_period_proposals)
return str(last_proposal_id)
else:
print("No proposals in DEPOSIT_PERIOD found. Waiting...")
time.sleep(2)
def check_proposal_status(chain_home, node, proposal_id, expected_status, max_tries=10):
tries = 0
while tries < max_tries:
command = f"simd query gov proposal {proposal_id} --home {chain_home} --node {node} --output json"
output = run_command(command)
proposal_status = output.get("status")
if proposal_status == expected_status:
print(f"Proposal status is now {proposal_status}. Exiting loop.")
return
else:
print(f"Proposal status is {proposal_status}. Continuing to check...")
tries += 1
time.sleep(2)
print("[ERROR] Failed due to an issue with the proposal")
sys.exit(1)
def main(chain_id, node, signer, contract):
chain_home = f"$HOME/.gm/{chain_id}"
# Store code
print('Storing the IBC Wasm client contract on the chain...')
store_code_command = (f"simd tx ibc-wasm store-code {contract} --title tmp --summary tmp --fees 1000016stake "
f"--deposit 200000stake --home {chain_home} --node {node} --from {signer} --chain-id {chain_id} "
f"--keyring-backend test --gas auto -y --output json")
run_command(store_code_command)
print('=> Code stored successfully')
# Fetch the last proposal ID
print('Fetching the proposal ID...')
proposal_id = get_last_proposal_id(chain_home, node)
print(f"=> Proposal ID: {proposal_id}")
# Check for PROPOSAL_STATUS_DEPOSIT_PERIOD
check_proposal_status(chain_home, node, proposal_id, "PROPOSAL_STATUS_DEPOSIT_PERIOD")
# Deposit
print('Depositing 100000000stake on the proposal...')
deposit_command = (f"simd tx gov deposit {proposal_id} 100000000stake --home {chain_home} --node {node} "
f"--from {signer} --chain-id {chain_id} --keyring-backend test --gas auto -y --output json")
run_command(deposit_command)
print('=> Deposit successful')
# Check for PROPOSAL_STATUS_VOTING_PERIOD
check_proposal_status(chain_home, node, proposal_id, "PROPOSAL_STATUS_VOTING_PERIOD")
# Vote
print('Voting YES on the proposal...')
vote_command = (f"simd tx gov vote {proposal_id} yes --home {chain_home} --node {node} "
f"--from {signer} --chain-id {chain_id} --keyring-backend test --gas auto -y --output json")
run_command(vote_command)
print('=> Vote successful')
# Check for PROPOSAL_STATUS_PASSED
check_proposal_status(chain_home, node, proposal_id, "PROPOSAL_STATUS_PASSED")
print('[SUCCESS] Contract installed successfully')
if __name__ == "__main__":
if len(sys.argv) != 5:
print("Usage: python script.py <CHAIN_ID> <NODE_RPC_URL> <SIGNER> <CONTRACT_FILE>")
sys.exit(1)
chain_id, node, signer, contract = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4]
main(chain_id, node, signer, contract)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment