import json from web3 import Web3 # Сonnect to the Moonbeam node web3 = Web3(Web3.HTTPProvider('NODE_URL')) # The address of the conviction voting contract contract_address = '0x0000000000000000000000000000000000000812' # Load the ABI from the file for both functions with open('ConvictionVoting.abi', 'r') as abi_file: abi = json.load(abi_file) # Create the contract instance contract = web3.eth.contract(address=contract_address, abi=abi) # Specify the starting block number start_block = BLOCK_NUMBER # Get the latest block number latest_block = web3.eth.block_number # Filter transactions to the Conviction Voting contract for block_number in range(start_block, latest_block + 1): block = web3.eth.get_block(block_number, full_transactions=True) for tx in block.transactions: if tx.to and (tx.to.lower() == contract_address.lower()): print(f"Transaction from account {tx['from']} in block {block_number}:") print(f" Transaction Hash: {tx.hash.hex()}") # Decode the transaction input if tx.input != '0x': func_obj, func_params = contract.decode_function_input(tx.input) print(f" Function called: {func_obj.fn_name}") for name, value in func_params.items(): print(f" {name}: {value}") # Call the classLocksFor function class_locks = contract.functions.classLocksFor(tx['from']).call() for lock in class_locks: track_id, amount = lock amount_in_glmr = web3.from_wei(amount, 'ether') print(f" Track ID: {track_id}, Locked Amount: {amount_in_glmr} GLMR") # Call the votingFor function voting_info = contract.functions.votingFor(tx['from'], track_id).call() is_casting, is_delegating, casting_details, delegating_details = voting_info print(" Voting Information:") print(f" Is Casting: {'Yes' if is_casting else 'No'}") print(f" Is Delegating: {'Yes' if is_delegating else 'No'}") # Convert and print voteAmount in GLMR if is_casting: for vote in casting_details[0]: poll_index, vote_details = vote is_standard, is_split, is_split_abstain, standard_vote, split_vote, split_abstain_vote = vote_details if is_standard: aye, conviction = standard_vote[0] balance = standard_vote[1] balance_in_glmr = web3.from_wei(balance, 'ether') print(f" Vote in Favor: {'Yes' if aye else 'No'}, Conviction Level: {conviction}") print(f" Balance: {balance_in_glmr} GLMR") # Call the classLocksFor function class_locks = contract.functions.classLocksFor(tx['from']).call() for lock in class_locks: track_id, amount = lock print(f" Track ID: {track_id}, Locked Amount: {amount_in_glmr}") # Call the votingFor function voting_info = contract.functions.votingFor(tx['from'], track_id).call() is_casting, is_delegating, casting_details, delegating_details = voting_info print(" Voting Information:") print(f" Is Casting: {'Yes' if is_casting else 'No'}") print(f" Is Delegating: {'Yes' if is_delegating else 'No'}")