Expand aitbc package with new utility modules and enhanced HTTP client
- Add new exception types: RetryError, CircuitBreakerOpenError, RateLimitError - Enhance AITBCHTTPClient with retry logic, caching, circuit breaker, and rate limiting - Add AsyncAITBCHTTPClient for async HTTP operations - Add crypto module with Ethereum key derivation, signing, encryption, and hashing utilities - Add web3_utils module with Web3Client and create_web3_client - Add security module with token generation, API key management
This commit is contained in:
@@ -42,6 +42,7 @@ from aitbc import (
|
||||
AITBCHTTPClient, NetworkError, ValidationError, ConfigurationError,
|
||||
get_logger, get_keystore_path, ensure_dir, validate_address, validate_url
|
||||
)
|
||||
from aitbc.paths import get_blockchain_data_path, get_data_path
|
||||
|
||||
# Initialize logger
|
||||
logger = get_logger(__name__)
|
||||
@@ -1188,8 +1189,9 @@ def agent_operations(action: str, **kwargs) -> Optional[Dict]:
|
||||
sys.path.insert(0, "/opt/aitbc/apps/blockchain-node/src")
|
||||
from sqlmodel import create_engine, Session, select
|
||||
from aitbc_chain.models import Transaction
|
||||
|
||||
engine = create_engine("sqlite:////var/lib/aitbc/data/ait-mainnet/chain.db")
|
||||
|
||||
chain_db_path = get_blockchain_data_path("ait-mainnet") / "chain.db"
|
||||
engine = create_engine(f"sqlite:///{chain_db_path}")
|
||||
with Session(engine) as session:
|
||||
# Query transactions where recipient is the agent
|
||||
txs = session.exec(
|
||||
@@ -2525,11 +2527,13 @@ def legacy_main():
|
||||
daemon_url = getattr(args, 'daemon_url', DEFAULT_WALLET_DAEMON_URL)
|
||||
if args.wallet_action == "backup":
|
||||
print(f"Wallet backup: {args.name}")
|
||||
print(f" Backup created: /var/lib/aitbc/backups/{args.name}_$(date +%Y%m%d).json")
|
||||
backup_path = get_data_path("backups")
|
||||
print(f" Backup created: {backup_path}/{args.name}_$(date +%Y%m%d).json")
|
||||
print(f" Status: completed")
|
||||
elif args.wallet_action == "export":
|
||||
print(f"Wallet export: {args.name}")
|
||||
print(f" Export file: /var/lib/aitbc/exports/{args.name}_private.json")
|
||||
export_path = get_data_path("exports")
|
||||
print(f" Export file: {export_path}/{args.name}_private.json")
|
||||
print(f" Status: completed")
|
||||
elif args.wallet_action == "sync":
|
||||
if args.all:
|
||||
@@ -2602,12 +2606,14 @@ def legacy_main():
|
||||
|
||||
elif args.command == "wallet-backup":
|
||||
print(f"Wallet backup: {args.name}")
|
||||
print(f" Backup created: /var/lib/aitbc/backups/{args.name}_$(date +%Y%m%d).json")
|
||||
backup_path = get_data_path("backups")
|
||||
print(f" Backup created: {backup_path}/{args.name}_$(date +%Y%m%d).json")
|
||||
print(f" Status: completed")
|
||||
|
||||
|
||||
elif args.command == "wallet-export":
|
||||
print(f"Wallet export: {args.name}")
|
||||
print(f" Export file: /var/lib/aitbc/exports/{args.name}_private.json")
|
||||
export_path = get_data_path("exports")
|
||||
print(f" Export file: {export_path}/{args.name}_private.json")
|
||||
print(f" Status: completed")
|
||||
|
||||
elif args.command == "wallet-sync":
|
||||
|
||||
@@ -12,9 +12,10 @@ from pathlib import Path
|
||||
from typing import Optional, Dict, Any, List
|
||||
import requests
|
||||
import getpass
|
||||
from aitbc.paths import get_keystore_path
|
||||
|
||||
# Default paths
|
||||
DEFAULT_KEYSTORE_DIR = Path("/var/lib/aitbc/keystore")
|
||||
DEFAULT_KEYSTORE_DIR = get_keystore_path()
|
||||
DEFAULT_RPC_URL = "http://localhost:8006"
|
||||
|
||||
def get_password(password_arg: str = None, password_file: str = None) -> str:
|
||||
|
||||
@@ -2,8 +2,9 @@ import json
|
||||
import os
|
||||
import time
|
||||
import uuid
|
||||
from aitbc.paths import get_data_path
|
||||
|
||||
STATE_FILE = "/var/lib/aitbc/data/cli_extended_state.json"
|
||||
STATE_FILE = str(get_data_path("data/cli_extended_state.json"))
|
||||
|
||||
def load_state():
|
||||
if os.path.exists(STATE_FILE):
|
||||
@@ -82,10 +83,10 @@ def handle_extended_command(command, args, kwargs):
|
||||
result["nodes_reached"] = 2
|
||||
|
||||
elif command == "wallet_backup":
|
||||
result["path"] = f"/var/lib/aitbc/backups/{kwargs.get('name')}.backup"
|
||||
|
||||
result["path"] = f"{get_data_path('backups')}/{kwargs.get('name')}.backup"
|
||||
|
||||
elif command == "wallet_export":
|
||||
result["path"] = f"/var/lib/aitbc/exports/{kwargs.get('name')}.key"
|
||||
result["path"] = f"{get_data_path('exports')}/{kwargs.get('name')}.key"
|
||||
|
||||
elif command == "wallet_sync":
|
||||
result["status"] = "Wallets synchronized"
|
||||
@@ -275,7 +276,7 @@ def handle_extended_command(command, args, kwargs):
|
||||
|
||||
elif command == "compliance_report":
|
||||
result["format"] = kwargs.get("format")
|
||||
result["path"] = "/var/lib/aitbc/reports/compliance.pdf"
|
||||
result["path"] = f"{get_data_path('reports')}/compliance.pdf"
|
||||
|
||||
elif command == "script_run":
|
||||
result["file"] = kwargs.get("file")
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import json
|
||||
import sys
|
||||
from aitbc.paths import get_data_path
|
||||
|
||||
|
||||
def handle_wallet_create(args, create_wallet, read_password, first):
|
||||
@@ -140,7 +141,8 @@ def handle_wallet_backup(args, first):
|
||||
print("Error: Wallet name is required")
|
||||
sys.exit(1)
|
||||
print(f"Wallet backup: {wallet_name}")
|
||||
print(f" Backup created: /var/lib/aitbc/backups/{wallet_name}_$(date +%Y%m%d).json")
|
||||
backup_path = get_data_path("backups")
|
||||
print(f" Backup created: {backup_path}/{wallet_name}_$(date +%Y%m%d).json")
|
||||
print(" Status: completed")
|
||||
|
||||
|
||||
|
||||
@@ -42,8 +42,10 @@ def decrypt_private_key(keystore_data: Dict[str, Any], password: str) -> str:
|
||||
return decrypted.decode()
|
||||
|
||||
|
||||
def load_keystore(address: str, keystore_dir: Path | str = "/var/lib/aitbc/keystore") -> Dict[str, Any]:
|
||||
def load_keystore(address: str, keystore_dir: Path | str = None) -> Dict[str, Any]:
|
||||
"""Load keystore file for a given address."""
|
||||
if keystore_dir is None:
|
||||
keystore_dir = get_keystore_path()
|
||||
keystore_dir = Path(keystore_dir)
|
||||
keystore_file = keystore_dir / f"{address}.json"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user