Skip to content

Commit

Permalink
Initial Changes to Enable Tron collector for Exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
rodgerjohnson committed Aug 30, 2024
1 parent 62b68f9 commit 28e8237
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
54 changes: 54 additions & 0 deletions src/collectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,57 @@ def client_version(self):
def latency(self):
"""Returns connection latency."""
return self.interface.latest_query_latency

class TronCollector():
"""A collector to fetch information about Aptos endpoints."""

def __init__(self, url, labels, chain_id, **client_parameters):

self.labels = labels
self.chain_id = chain_id
self.interface = HttpsInterface(url, client_parameters.get('open_timeout'),
client_parameters.get('ping_timeout'))

self._logger_metadata = {
'component': 'TronCollector',
'url': strip_url(url)
}
self.client_version_payload = {
'jsonrpc': '2.0',
'method': "web3_clientVersion",
'id': 1
}
self.block_height_payload = {
'jsonrpc': '2.0',
'method': "eth_blockNumber",
'id': 1
}

def alive(self):
"""Returns true if endpoint is alive, false if not."""
# Run cached query because we can also fetch client version from this
# later on. This will save us an RPC call per run.
return self.interface.cached_json_rpc_post(
self.client_version_payload) is not None

def block_height(self):
"""Returns blockheight after converting string hexadecimal value to an int"""
result = self.interface.cached_json_rpc_post(self.block_height_payload)

if result and isinstance(result, str) and result.startswith('0x'):
return int(result, 16)
else:
raise ValueError(f"Invalid block height result: {result}")

def client_version(self):
"""Runs a cached query to return client version."""
version = self.interface.cached_json_rpc_post(
self.client_version_payload)
if version is None:
return None
client_version = {"client_version": version}
return client_version

def latency(self):
"""Returns connection latency."""
return self.interface.latest_query_latency
3 changes: 2 additions & 1 deletion src/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def endpoints(self):
def _load_configuration(self):
allowed_providers = self._load_validation_file()
supported_collectors = ('evm', 'cardano', 'conflux', 'solana',
'bitcoin', 'doge', 'filecoin', 'starknet', 'aptos')
'bitcoin', 'doge', 'filecoin', 'starknet', 'aptos',
'tron')

configuration_schema = Schema({
'blockchain':
Expand Down
2 changes: 2 additions & 0 deletions src/registries.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def get_collector_registry(self) -> list:
collector = collectors.StarknetCollector
case "aptos", "aptos":
collector = collectors.AptosCollector
case "tron", "tron":
collector = collectors.TronCollector
case "evm", other: # pylint: disable=unused-variable
collector = collectors.EvmCollector
if collector is None:
Expand Down

0 comments on commit 28e8237

Please sign in to comment.