@@ -446,3 +446,57 @@ def client_version(self):
446446 def latency (self ):
447447 """Returns connection latency."""
448448 return self .interface .latest_query_latency
449+
450+
451+ class EvmHttpCollector ():
452+ """A collector to fetch information from EVM HTTPS endpoints."""
453+
454+ def __init__ (self , url , labels , chain_id , ** client_parameters ):
455+
456+ self .labels = labels
457+ self .chain_id = chain_id
458+ self .interface = HttpsInterface (url , client_parameters .get ('open_timeout' ),
459+ client_parameters .get ('ping_timeout' ))
460+
461+ self ._logger_metadata = {
462+ 'component' : 'EvmHttpCollector' ,
463+ 'url' : strip_url (url )
464+ }
465+ self .client_version_payload = {
466+ 'jsonrpc' : '2.0' ,
467+ 'method' : "web3_clientVersion" ,
468+ 'id' : 1
469+ }
470+ self .block_height_payload = {
471+ 'jsonrpc' : '2.0' ,
472+ 'method' : "eth_blockNumber" ,
473+ 'id' : 1
474+ }
475+
476+ def alive (self ):
477+ """Returns true if endpoint is alive, false if not."""
478+ # Run cached query because we can also fetch client version from this
479+ # later on. This will save us an RPC call per run.
480+ return self .interface .cached_json_rpc_post (
481+ self .client_version_payload ) is not None
482+
483+ def block_height (self ):
484+ """Cached query and returns blockheight after converting hex string value to an int"""
485+ result = self .interface .cached_json_rpc_post (self .block_height_payload )
486+
487+ if result and isinstance (result , str ) and result .startswith ('0x' ):
488+ return int (result , 16 )
489+ raise ValueError (f"Invalid block height result: { result } " )
490+
491+ def client_version (self ):
492+ """Runs a cached query to return client version."""
493+ version = self .interface .cached_json_rpc_post (
494+ self .client_version_payload )
495+ if version is None :
496+ return None
497+ client_version = {"client_version" : version }
498+ return client_version
499+
500+ def latency (self ):
501+ """Returns connection latency."""
502+ return self .interface .latest_query_latency
0 commit comments