Remove debug logging from router.py and poa.py
Some checks failed
Blockchain Synchronization Verification / sync-verification (push) Successful in 3s
Integration Tests / test-service-integration (push) Failing after 10s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 2s
P2P Network Verification / p2p-verification (push) Successful in 2s
Python Tests / test-python (push) Successful in 14s
Security Scanning / security-scan (push) Successful in 24s
Some checks failed
Blockchain Synchronization Verification / sync-verification (push) Successful in 3s
Integration Tests / test-service-integration (push) Failing after 10s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 2s
P2P Network Verification / p2p-verification (push) Successful in 2s
Python Tests / test-python (push) Successful in 14s
Security Scanning / security-scan (push) Successful in 24s
This commit is contained in:
@@ -1,8 +1,78 @@
|
|||||||
"""
|
"""
|
||||||
AITBC Package
|
AITBC Package
|
||||||
|
Centralized utilities for AITBC applications
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from .aitbc_logging import get_logger, setup_logger
|
from .aitbc_logging import get_logger, setup_logger
|
||||||
|
from .constants import (
|
||||||
|
DATA_DIR,
|
||||||
|
CONFIG_DIR,
|
||||||
|
LOG_DIR,
|
||||||
|
REPO_DIR,
|
||||||
|
KEYSTORE_DIR,
|
||||||
|
BLOCKCHAIN_DATA_DIR,
|
||||||
|
MARKETPLACE_DATA_DIR,
|
||||||
|
ENV_FILE,
|
||||||
|
NODE_ENV_FILE,
|
||||||
|
BLOCKCHAIN_RPC_PORT,
|
||||||
|
BLOCKCHAIN_P2P_PORT,
|
||||||
|
AGENT_COORDINATOR_PORT,
|
||||||
|
MARKETPLACE_PORT,
|
||||||
|
PACKAGE_VERSION,
|
||||||
|
)
|
||||||
|
from .exceptions import (
|
||||||
|
AITBCError,
|
||||||
|
ConfigurationError,
|
||||||
|
NetworkError,
|
||||||
|
AuthenticationError,
|
||||||
|
EncryptionError,
|
||||||
|
DatabaseError,
|
||||||
|
ValidationError,
|
||||||
|
BridgeError,
|
||||||
|
)
|
||||||
|
from .env import (
|
||||||
|
get_env_var,
|
||||||
|
get_required_env_var,
|
||||||
|
get_bool_env_var,
|
||||||
|
get_int_env_var,
|
||||||
|
get_float_env_var,
|
||||||
|
get_list_env_var,
|
||||||
|
)
|
||||||
|
|
||||||
__version__ = "0.2.0"
|
__version__ = "0.3.0"
|
||||||
__all__ = ["get_logger", "setup_logger"]
|
__all__ = [
|
||||||
|
# Logging
|
||||||
|
"get_logger",
|
||||||
|
"setup_logger",
|
||||||
|
# Constants
|
||||||
|
"DATA_DIR",
|
||||||
|
"CONFIG_DIR",
|
||||||
|
"LOG_DIR",
|
||||||
|
"REPO_DIR",
|
||||||
|
"KEYSTORE_DIR",
|
||||||
|
"BLOCKCHAIN_DATA_DIR",
|
||||||
|
"MARKETPLACE_DATA_DIR",
|
||||||
|
"ENV_FILE",
|
||||||
|
"NODE_ENV_FILE",
|
||||||
|
"BLOCKCHAIN_RPC_PORT",
|
||||||
|
"BLOCKCHAIN_P2P_PORT",
|
||||||
|
"AGENT_COORDINATOR_PORT",
|
||||||
|
"MARKETPLACE_PORT",
|
||||||
|
"PACKAGE_VERSION",
|
||||||
|
# Exceptions
|
||||||
|
"AITBCError",
|
||||||
|
"ConfigurationError",
|
||||||
|
"NetworkError",
|
||||||
|
"AuthenticationError",
|
||||||
|
"EncryptionError",
|
||||||
|
"DatabaseError",
|
||||||
|
"ValidationError",
|
||||||
|
"BridgeError",
|
||||||
|
# Environment helpers
|
||||||
|
"get_env_var",
|
||||||
|
"get_required_env_var",
|
||||||
|
"get_bool_env_var",
|
||||||
|
"get_int_env_var",
|
||||||
|
"get_float_env_var",
|
||||||
|
"get_list_env_var",
|
||||||
|
]
|
||||||
|
|||||||
114
aitbc/env.py
Normal file
114
aitbc/env.py
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
"""
|
||||||
|
AITBC Environment Variable Helpers
|
||||||
|
Centralized utilities for loading and managing environment variables
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
from typing import Optional
|
||||||
|
from .exceptions import ConfigurationError
|
||||||
|
|
||||||
|
|
||||||
|
def get_env_var(key: str, default: str = "") -> str:
|
||||||
|
"""
|
||||||
|
Get an environment variable with a default value.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
key: Environment variable name
|
||||||
|
default: Default value if not set
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Environment variable value or default
|
||||||
|
"""
|
||||||
|
return os.getenv(key, default)
|
||||||
|
|
||||||
|
|
||||||
|
def get_required_env_var(key: str) -> str:
|
||||||
|
"""
|
||||||
|
Get a required environment variable, raise error if not set.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
key: Environment variable name
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Environment variable value
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
ConfigurationError: If environment variable is not set
|
||||||
|
"""
|
||||||
|
value = os.getenv(key)
|
||||||
|
if value is None:
|
||||||
|
raise ConfigurationError(f"Required environment variable '{key}' is not set")
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
def get_bool_env_var(key: str, default: bool = False) -> bool:
|
||||||
|
"""
|
||||||
|
Get a boolean environment variable.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
key: Environment variable name
|
||||||
|
default: Default value if not set
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True if variable is set to 'true', '1', 'yes', or 'on' (case-insensitive)
|
||||||
|
False if variable is set to 'false', '0', 'no', or 'off' (case-insensitive)
|
||||||
|
Default value if not set
|
||||||
|
"""
|
||||||
|
value = os.getenv(key, "").lower()
|
||||||
|
if not value:
|
||||||
|
return default
|
||||||
|
return value in ("true", "1", "yes", "on")
|
||||||
|
|
||||||
|
|
||||||
|
def get_int_env_var(key: str, default: int = 0) -> int:
|
||||||
|
"""
|
||||||
|
Get an integer environment variable.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
key: Environment variable name
|
||||||
|
default: Default value if not set or invalid
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Integer value or default
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
return int(os.getenv(key, str(default)))
|
||||||
|
except ValueError:
|
||||||
|
return default
|
||||||
|
|
||||||
|
|
||||||
|
def get_float_env_var(key: str, default: float = 0.0) -> float:
|
||||||
|
"""
|
||||||
|
Get a float environment variable.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
key: Environment variable name
|
||||||
|
default: Default value if not set or invalid
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Float value or default
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
return float(os.getenv(key, str(default)))
|
||||||
|
except ValueError:
|
||||||
|
return default
|
||||||
|
|
||||||
|
|
||||||
|
def get_list_env_var(key: str, separator: str = ",", default: Optional[list] = None) -> list:
|
||||||
|
"""
|
||||||
|
Get a list environment variable.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
key: Environment variable name
|
||||||
|
separator: Separator for list items
|
||||||
|
default: Default value if not set
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
List of values or default
|
||||||
|
"""
|
||||||
|
if default is None:
|
||||||
|
default = []
|
||||||
|
value = os.getenv(key, "")
|
||||||
|
if not value:
|
||||||
|
return default
|
||||||
|
return [item.strip() for item in value.split(separator) if item.strip()]
|
||||||
@@ -255,7 +255,6 @@ class PoAProposer:
|
|||||||
# Create transaction record
|
# Create transaction record
|
||||||
# Extract type from normalized tx_data (which should have the type field)
|
# Extract type from normalized tx_data (which should have the type field)
|
||||||
tx_type = tx.content.get("type", "TRANSFER")
|
tx_type = tx.content.get("type", "TRANSFER")
|
||||||
self._logger.info(f"[PROPOSE] Transaction {tx.tx_hash} content type: {tx_type}, full content: {tx.content}")
|
|
||||||
if tx_type:
|
if tx_type:
|
||||||
tx_type = tx_type.upper()
|
tx_type = tx_type.upper()
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -308,12 +308,7 @@ async def submit_transaction(tx_data: TransactionRequest) -> Dict[str, Any]:
|
|||||||
"signature": tx_data.sig
|
"signature": tx_data.sig
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.info(f"[ROUTER] Before normalization: type={tx_data.type}, full dict keys={list(tx_data_dict.keys())}")
|
|
||||||
|
|
||||||
tx_data_dict = _normalize_transaction_data(tx_data_dict, chain_id)
|
tx_data_dict = _normalize_transaction_data(tx_data_dict, chain_id)
|
||||||
|
|
||||||
_logger.info(f"[ROUTER] After normalization: type={tx_data_dict.get('type')}, full dict keys={list(tx_data_dict.keys())}")
|
|
||||||
|
|
||||||
_validate_transaction_admission(tx_data_dict, mempool)
|
_validate_transaction_admission(tx_data_dict, mempool)
|
||||||
|
|
||||||
tx_hash = mempool.add(tx_data_dict, chain_id=chain_id)
|
tx_hash = mempool.add(tx_data_dict, chain_id=chain_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user