The script checks the involvement of specific validator addresses on the Polygon network, identifying the blocks in which these addresses did not sign and keeping track of how many times each address acted as the proposer. The results are saved in a file named "results.txt."
importrequestsdefextract_validator_addresses(block,address):url=f"https://heimdall-api.polygon.technology/blocks/{block}"response=requests.get(url)ifresponse.status_code==200:data=response.json()if'last_commit'indata['block']:proposer_address=data['block']['header'].get('proposer_address')precommits=data['block']['last_commit'].get('precommits', [])validator_addresses= [commit.get('validator_address') for commit inprecommitsifcommit]ifaddressinvalidator_addressesoraddress==proposer_address:returnaddress,True,proposer_address else:returnaddress,False,proposer_address else:print(f"No commit data in Block {block}.")returnaddress,False,None else:print(f"Failed request for Block {block}. Response code: {response.status_code}")returnaddress,False,Noneinitial_block=16378652final_block=16379652withopen("addresses.txt","r") asfile:addresses_file= [line.strip() for line in file]addresses_not_signing= []addresses_proposer_count={}for block inrange(initial_block,final_block+1):for address inaddresses_file:_,signed,proposer_address=extract_validator_addresses(block,address)ifnotsigned:addresses_not_signing.append({"address": address, "block": block, "proposer_address": proposer_address}) if proposer_address in addresses_proposer_count: addresses_proposer_count[proposer_address] += 1 else: addresses_proposer_count[proposer_address] = 1addresses_not_signing = sorted(addresses_not_signing, key=lambda x: x['block'])with open("results.txt", "w") as result_file: result_file.write("Addressesnotsigningblocks,sortedbyblock:\n") for item in addresses_not_signing: result_file.write(f"Address:{item['address']},Block:{item['block']},ProposerAddress:{item['proposer_address']ifitem['proposer_address']isnotNoneelse'None'}\n") result_file.write("\nTotaltimeseachaddressproposed:\n") for address, count in addresses_proposer_count.items(): result_file.write(f"Address:{address},TotalProposals:{count}\n")print("Resultssavedinresults.txt")
addresses.txt
Python and Requests Installation:
Make sure you have Python installed on your system. Open the terminal or command prompt. Execute the following command to install the requests library:
pipinstallrequests
Script Execution:
Save the Python script (Your_script.py) in the directory of your choice. Place a file named "addresses.txt" in the same directory as the script, containing the addresses of the validators.
Run the Script:
In the terminal or command prompt, navigate to the directory where the script is located. Execute the script using the following command:
python3your_script.py
Results:
The script will process the blocks and generate a file named "results.txt" in the same directory as the script. Ensure that the "addresses.txt" file is present in the same directory as the script to ensure proper script functionality.