|
11 | 11 | from pathlib import Path
|
12 | 12 |
|
13 | 13 | import pandas as pd
|
| 14 | +from tenacity import retry, stop_after_attempt, wait_exponential |
14 | 15 | from web3 import Web3
|
15 | 16 | from web3.contract import Contract
|
16 |
| -from tenacity import retry, stop_after_attempt, wait_exponential |
17 | 17 |
|
18 | 18 | # Import data providers
|
19 | 19 | from src.models.bigquery_data_access_provider import BigQueryProvider
|
20 | 20 | from src.models.subgraph_data_access_provider import SubgraphProvider
|
21 | 21 |
|
22 | 22 | # Import configuration and key validation
|
23 | 23 | from src.utils.config_loader import ConfigLoader, ConfigurationError
|
24 |
| -from src.utils.key_validator import validate_and_format_private_key, KeyValidationError |
| 24 | +from src.utils.key_validator import KeyValidationError, validate_and_format_private_key |
25 | 25 |
|
26 | 26 | logger = logging.getLogger(__name__)
|
27 | 27 |
|
|
34 | 34 | def _validate_required_fields(data: dict, required_fields: list[str], context: str) -> None:
|
35 | 35 | """
|
36 | 36 | Helper function to validate required fields are present in a dictionary.
|
37 |
| - |
| 37 | +
|
38 | 38 | Args:
|
39 | 39 | data: Dictionary to validate
|
40 | 40 | required_fields: List of required fields
|
@@ -96,7 +96,13 @@ def _load_config_and_return_validated() -> dict[str, str | int | list]:
|
96 | 96 | ) from e
|
97 | 97 |
|
98 | 98 | # Validate blockchain configuration contains all required fields
|
99 |
| - required_fields = ["private_key", "contract_address", "contract_function", "chain_id", "scheduled_run_time"] |
| 99 | + required_fields = [ |
| 100 | + "private_key", |
| 101 | + "contract_address", |
| 102 | + "contract_function", |
| 103 | + "chain_id", |
| 104 | + "scheduled_run_time", |
| 105 | + ] |
100 | 106 | _validate_required_fields(config, required_fields, "Missing required blockchain configuration")
|
101 | 107 |
|
102 | 108 | # Validate RPC providers
|
@@ -133,9 +139,7 @@ def _get_path_to_project_root() -> Path:
|
133 | 139 | current_path = current_path.parent
|
134 | 140 |
|
135 | 141 | # If we got here, something is wrong
|
136 |
| - raise FileNotFoundError( |
137 |
| - "Could not find project root directory. Investigate." |
138 |
| - ) |
| 142 | + raise FileNotFoundError("Could not find project root directory. Investigate.") |
139 | 143 |
|
140 | 144 |
|
141 | 145 | def _parse_and_validate_credentials_json(creds_env: str) -> dict:
|
@@ -265,7 +269,7 @@ def _setup_google_credentials_in_memory_from_env_var():
|
265 | 269 | if creds_data is not None:
|
266 | 270 | creds_data.clear()
|
267 | 271 | del creds_data
|
268 |
| - |
| 272 | + |
269 | 273 | else:
|
270 | 274 | logger.warning(
|
271 | 275 | "GOOGLE_APPLICATION_CREDENTIALS is not set or not in the correct format. "
|
@@ -339,7 +343,7 @@ def _clean_old_date_directories(data_output_dir: Path, max_age_before_deletion:
|
339 | 343 | if age_days > max_age_before_deletion:
|
340 | 344 | logger.info(f"Removing old data directory: {item} ({age_days} days old)")
|
341 | 345 | shutil.rmtree(item)
|
342 |
| - |
| 346 | + |
343 | 347 | # Skip directories that don't match date format
|
344 | 348 | except ValueError:
|
345 | 349 | continue
|
@@ -423,7 +427,7 @@ def _setup_transaction_account(private_key: str, w3) -> tuple[str, object]:
|
423 | 427 | account = w3.eth.account.from_key(private_key)
|
424 | 428 | logger.info(f"Using account: {account.address}")
|
425 | 429 | return account.address
|
426 |
| - |
| 430 | + |
427 | 431 | # If the account cannot be retrieved, log the error and raise an exception
|
428 | 432 | except Exception as e:
|
429 | 433 | logger.error(f"Failed to retrieve account from private key: {str(e)}")
|
|
0 commit comments