The script retrieves information about the latest span, prompts the user for a validator ID, and checks if that validator is currently participating in the span. These operations aid in monitoring the involvement of a validator.
import osimport requests# Check if the lock file already existsif os.path.exists("lockfile"):exit()# Create the lock filewith open("lockfile", "w") as file:file.write("")def get_current_span_id():try:url = "https://heimdall-api.polygon.technology/bor/latest-span"response = requests.get(url)if response.status_code == 200:data = response.json()span_id = data.get("result", {}).get("span_id")return span_idelse:return Noneexcept Exception as e:return Nonedef check_validator_in_current_span(span_id, validator_id):try:url = f"https://heimdall-api.polygon.technology/bor/span/{span_id}"response = requests.get(url)if response.status_code == 200:data = response.json()selected_producers = data.get("result", {}).get("validator_set", {}).get("validators", [])for validator in selected_producers:if validator["ID"] == validator_id:return "The validator is part of the current span."return "The validator is NOT part of the current span."else:return "Error fetching current span information."except Exception as e:return "Error checking validator in the current span."if __name__ == "__main__":validator_id = int(input("Enter the validator ID:")) current_span_id = get_current_span_id() if current_span_id is not None: response = check_validator_in_current_span(current_span_id, validator_id) print(response) # Remove the lock file after program execution os.remove("lockfile")
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 checks if the validator with the provided ID is among the validators of the current span.