From 2c47795bb8e52e96930981753f85df6cbbc846b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Tue, 25 Oct 2022 13:32:11 +0200 Subject: [PATCH] ethereum/validator_check.py: for checking status MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Useful to sort out slashed validators on Prater. Signed-off-by: Jakub SokoĊ‚owski --- ethereum/validator_check.py | 62 +++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 ethereum/validator_check.py diff --git a/ethereum/validator_check.py b/ethereum/validator_check.py new file mode 100755 index 0000000..6ed9f5d --- /dev/null +++ b/ethereum/validator_check.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 +import os +import sys +import time +import json +import requests +from optparse import OptionParser + +HELP_DESCRIPTION='This is a simple utility for querying CloudFlare for DNS entries.' +HELP_EXAMPLE='Example: ./fqdns.py -d status.im -t CNAME' + +class BeaconChainAPI: + + def __init__(self, token, url='https://prater.beaconcha.in/api/'): + self.token = token + self.url = url + + def _req(self, method, path): + try: + rval = requests.request(method, self.url+path, headers={'apikey':self.token}) + rval.raise_for_status() + except Exception as ex: + print(rval.text) + raise ex + return rval + + def _get(self, path): + return self._req('GET', path) + + def health(self): + return self._get('healthz').text + + def validator(self, index): + return self._get('v1/validator/%s' % index).json() + +def parse_opts(): + parser = OptionParser(description=HELP_DESCRIPTION, epilog=HELP_EXAMPLE) + parser.add_option('-u', '--url', default='https://prater.beaconcha.in/api/', + help='format records as a csv file.') + parser.add_option('-t', '--token', default=os.environ['BEACON_CHAIN_TOKEN'], + help='Beaconcha.in API token, sourced from BEACON_CHAIN_TOKEN env var.') + + return parser.parse_args() + +def main(): + (opts, args) = parse_opts() + + api = BeaconChainAPI(opts.token, opts.url) + + for line in sys.stdin: + val_id = line.rstrip() + rval = api.validator(val_id) + print(json.dumps({ + 'id': val_id, + 'status': rval['data']['status'], + 'slashed': rval['data']['slashed'], + 'balance': rval['data']['balance'], + })) + time.sleep(6) + +if __name__ == '__main__': + main()