Skip to content

Instantly share code, notes, and snippets.

@kaisbaccour
Created September 18, 2023 09:08
Show Gist options
  • Save kaisbaccour/bb9451a46086b62f33b77da9d8563961 to your computer and use it in GitHub Desktop.
Save kaisbaccour/bb9451a46086b62f33b77da9d8563961 to your computer and use it in GitHub Desktop.
Get the list of all proxies with their respecticve chain address prefix and their usage
import subprocess
import yaml
import json
def query_data(config):
# Run the command and parse its output as YAML
command1 = f'noisd query wasm contract-state smart {config["wasm_contract_address"]} \'{{"customers":{{}}}}\' --chain-id={config["chain_id"]} --node={config["node_url"]}'
output1 = subprocess.check_output(command1, shell=True)
data1 = yaml.safe_load(output1)
# Run the second command and parse its output as YAML
command2 = f'noisd query ibc channel channels --chain-id={config["chain_id"]} --node={config["node_url"]}'
output2 = subprocess.check_output(command2, shell=True)
data2 = yaml.safe_load(output2)
# Create a dictionary to store the combined data
combined_data = {}
# Process the first command's data and add it to the combined_data dictionary
for item in data1['data']['customers']:
channel_id = item['channel_id']
combined_data[channel_id] = {
'requested_beacons': item['requested_beacons']
}
# Process the second command's data and add it to the combined_data dictionary
for item in data2['channels']:
channel_id = item['channel_id']
if channel_id in combined_data:
combined_data[channel_id]['proxy'] = item['counterparty']['port_id'][5:]
return combined_data
# Configuration for testnet
testnet_config = {
'wasm_contract_address': 'nois1xwde9rzqk5u36fke0r9ddmtwvh43n4fv53c5vc462wz8xlnqjhls6d90xc',
'chain_id': 'nois-testnet-005',
'node_url': 'https://nois-testnet-rpc.polkachu.com:443'
}
# Configuration for mainnet
mainnet_config = {
'wasm_contract_address': 'nois1acyc05v6fgcdgj88nmz2t40aex9nlnptqpwp5hf8hwg7rhce9uuqgqz5wp',
'chain_id': 'nois-1',
'node_url': 'https://rpc.cosmos.directory:443/nois'
}
# Query data for testnet
testnet_data = query_data(testnet_config)
# Query data for mainnet
mainnet_data = query_data(mainnet_config)
# Combine both sets of data
combined_data = {
'testnet': testnet_data,
'mainnet': mainnet_data
}
# Print the combined data as JSON
print(json.dumps(combined_data, indent=4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment