feat: migrate wallet daemon and CLI to use centralized aitbc package utilities
Some checks failed
API Endpoint Tests / test-api-endpoints (push) Successful in 9s
CLI Tests / test-cli (push) Failing after 3s
Integration Tests / test-service-integration (push) Successful in 41s
Python Tests / test-python (push) Failing after 18s
Security Scanning / security-scan (push) Failing after 2m0s
Some checks failed
API Endpoint Tests / test-api-endpoints (push) Successful in 9s
CLI Tests / test-cli (push) Failing after 3s
Integration Tests / test-service-integration (push) Successful in 41s
Python Tests / test-python (push) Failing after 18s
Security Scanning / security-scan (push) Failing after 2m0s
- Migrate simple_daemon.py from mock data to real keystore and blockchain RPC integration - Add httpx for async HTTP client in wallet daemon - Implement real wallet listing from keystore directory - Implement blockchain balance queries via RPC - Update CLI to use aitbc.AITBCHTTPClient instead of requests - Add aitbc imports: constants, http_client, exceptions, logging, paths, validation - Add address and amount validation in
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
import json
|
||||
import sys
|
||||
|
||||
import requests
|
||||
from aitbc.http_client import AITBCHTTPClient
|
||||
from aitbc.exceptions import NetworkError
|
||||
|
||||
|
||||
def handle_account_get(args, default_rpc_url, output_format):
|
||||
@@ -21,17 +22,15 @@ def handle_account_get(args, default_rpc_url, output_format):
|
||||
if chain_id:
|
||||
params["chain_id"] = chain_id
|
||||
|
||||
response = requests.get(f"{rpc_url}/rpc/account/{args.address}", params=params, timeout=10)
|
||||
if response.status_code == 200:
|
||||
account = response.json()
|
||||
if output_format(args) == "json":
|
||||
print(json.dumps(account, indent=2))
|
||||
else:
|
||||
render_mapping(f"Account {args.address}:", account)
|
||||
http_client = AITBCHTTPClient(base_url=rpc_url, timeout=10)
|
||||
account = http_client.get(f"/rpc/account/{args.address}", params=params)
|
||||
if output_format(args) == "json":
|
||||
print(json.dumps(account, indent=2))
|
||||
else:
|
||||
print(f"Query failed: {response.status_code}")
|
||||
print(f"Error: {response.text}")
|
||||
sys.exit(1)
|
||||
render_mapping(f"Account {args.address}:", account)
|
||||
except NetworkError as e:
|
||||
print(f"Error getting account: {e}")
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(f"Error getting account: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
import subprocess
|
||||
|
||||
import requests
|
||||
from aitbc.http_client import AITBCHTTPClient
|
||||
from aitbc.exceptions import NetworkError
|
||||
|
||||
|
||||
def handle_bridge_health(args):
|
||||
@@ -18,15 +19,14 @@ def handle_bridge_health(args):
|
||||
return
|
||||
|
||||
bridge_url = getattr(config, "bridge_url", "http://localhost:8204")
|
||||
response = requests.get(f"{bridge_url}/health", timeout=10)
|
||||
http_client = AITBCHTTPClient(base_url=bridge_url, timeout=10)
|
||||
health = http_client.get("/health")
|
||||
|
||||
if response.status_code == 200:
|
||||
health = response.json()
|
||||
print("🏥 Blockchain Event Bridge Health:")
|
||||
for key, value in health.items():
|
||||
print(f" {key}: {value}")
|
||||
else:
|
||||
print(f"❌ Health check failed: {response.text}")
|
||||
print("🏥 Blockchain Event Bridge Health:")
|
||||
for key, value in health.items():
|
||||
print(f" {key}: {value}")
|
||||
except NetworkError as e:
|
||||
print(f"❌ Health check failed: {e}")
|
||||
except Exception as e:
|
||||
print(f"❌ Error checking health: {e}")
|
||||
|
||||
@@ -44,14 +44,13 @@ def handle_bridge_metrics(args):
|
||||
return
|
||||
|
||||
bridge_url = getattr(config, "bridge_url", "http://localhost:8204")
|
||||
response = requests.get(f"{bridge_url}/metrics", timeout=10)
|
||||
http_client = AITBCHTTPClient(base_url=bridge_url, timeout=10)
|
||||
metrics = http_client.get("/metrics", return_response=True)
|
||||
|
||||
if response.status_code == 200:
|
||||
metrics = response.text
|
||||
print("📊 Prometheus Metrics:")
|
||||
print(metrics)
|
||||
else:
|
||||
print(f"❌ Failed to get metrics: {response.text}")
|
||||
print("📊 Prometheus Metrics:")
|
||||
print(metrics.text)
|
||||
except NetworkError as e:
|
||||
print(f"❌ Failed to get metrics: {e}")
|
||||
except Exception as e:
|
||||
print(f"❌ Error getting metrics: {e}")
|
||||
|
||||
@@ -69,15 +68,14 @@ def handle_bridge_status(args):
|
||||
return
|
||||
|
||||
bridge_url = getattr(config, "bridge_url", "http://localhost:8204")
|
||||
response = requests.get(f"{bridge_url}/", timeout=10)
|
||||
http_client = AITBCHTTPClient(base_url=bridge_url, timeout=10)
|
||||
status = http_client.get("/")
|
||||
|
||||
if response.status_code == 200:
|
||||
status = response.json()
|
||||
print("📊 Blockchain Event Bridge Status:")
|
||||
for key, value in status.items():
|
||||
print(f" {key}: {value}")
|
||||
else:
|
||||
print(f"❌ Failed to get status: {response.text}")
|
||||
print("📊 Blockchain Event Bridge Status:")
|
||||
for key, value in status.items():
|
||||
print(f" {key}: {value}")
|
||||
except NetworkError as e:
|
||||
print(f"❌ Failed to get status: {e}")
|
||||
except Exception as e:
|
||||
print(f"❌ Error getting status: {e}")
|
||||
|
||||
@@ -95,15 +93,14 @@ def handle_bridge_config(args):
|
||||
return
|
||||
|
||||
bridge_url = getattr(config, "bridge_url", "http://localhost:8204")
|
||||
response = requests.get(f"{bridge_url}/config", timeout=10)
|
||||
http_client = AITBCHTTPClient(base_url=bridge_url, timeout=10)
|
||||
service_config = http_client.get("/config")
|
||||
|
||||
if response.status_code == 200:
|
||||
service_config = response.json()
|
||||
print("⚙️ Blockchain Event Bridge Configuration:")
|
||||
for key, value in service_config.items():
|
||||
print(f" {key}: {value}")
|
||||
else:
|
||||
print(f"❌ Failed to get config: {response.text}")
|
||||
print("⚙️ Blockchain Event Bridge Configuration:")
|
||||
for key, value in service_config.items():
|
||||
print(f" {key}: {value}")
|
||||
except NetworkError as e:
|
||||
print(f"❌ Failed to get config: {e}")
|
||||
except Exception as e:
|
||||
print(f"❌ Error getting config: {e}")
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""Pool hub SLA and capacity management handlers."""
|
||||
|
||||
import requests
|
||||
from aitbc.http_client import AITBCHTTPClient
|
||||
from aitbc.exceptions import NetworkError
|
||||
|
||||
|
||||
def handle_pool_hub_sla_metrics(args):
|
||||
@@ -10,27 +11,26 @@ def handle_pool_hub_sla_metrics(args):
|
||||
config = get_pool_hub_config()
|
||||
|
||||
if args.test_mode:
|
||||
print("📊 SLA Metrics (test mode):")
|
||||
print("⏱️ Uptime: 97.5%")
|
||||
print("⚡ Response Time: 850ms")
|
||||
print("✅ Job Completion Rate: 92.3%")
|
||||
print(" SLA Metrics (test mode):")
|
||||
print(" Uptime: 97.5%")
|
||||
print(" Response Time: 850ms")
|
||||
print(" Job Completion Rate: 92.3%")
|
||||
return
|
||||
|
||||
pool_hub_url = getattr(config, "pool_hub_url", "http://localhost:8012")
|
||||
miner_id = getattr(args, "miner_id", None)
|
||||
|
||||
http_client = AITBCHTTPClient(base_url=pool_hub_url, timeout=30)
|
||||
if miner_id:
|
||||
response = requests.get(f"{pool_hub_url}/sla/metrics/{miner_id}", timeout=30)
|
||||
metrics = http_client.get(f"/sla/metrics/{miner_id}")
|
||||
else:
|
||||
response = requests.get(f"{pool_hub_url}/sla/metrics", timeout=30)
|
||||
metrics = http_client.get("/sla/metrics")
|
||||
|
||||
if response.status_code == 200:
|
||||
metrics = response.json()
|
||||
print("📊 SLA Metrics:")
|
||||
for key, value in metrics.items():
|
||||
print(f" {key}: {value}")
|
||||
else:
|
||||
print(f"❌ Failed to get SLA metrics: {response.text}")
|
||||
print(" SLA Metrics:")
|
||||
for key, value in metrics.items():
|
||||
print(f" {key}: {value}")
|
||||
except NetworkError as e:
|
||||
print(f"❌ Failed to get SLA metrics: {e}")
|
||||
except Exception as e:
|
||||
print(f"❌ Error getting SLA metrics: {e}")
|
||||
|
||||
@@ -47,15 +47,14 @@ def handle_pool_hub_sla_violations(args):
|
||||
return
|
||||
|
||||
pool_hub_url = getattr(config, "pool_hub_url", "http://localhost:8012")
|
||||
response = requests.get(f"{pool_hub_url}/sla/violations", timeout=30)
|
||||
http_client = AITBCHTTPClient(base_url=pool_hub_url, timeout=30)
|
||||
violations = http_client.get("/sla/violations")
|
||||
|
||||
if response.status_code == 200:
|
||||
violations = response.json()
|
||||
print("⚠️ SLA Violations:")
|
||||
for v in violations:
|
||||
print(f" {v}")
|
||||
else:
|
||||
print(f"❌ Failed to get violations: {response.text}")
|
||||
print("⚠️ SLA Violations:")
|
||||
for v in violations:
|
||||
print(f" {v}")
|
||||
except NetworkError as e:
|
||||
print(f"❌ Failed to get violations: {e}")
|
||||
except Exception as e:
|
||||
print(f"❌ Error getting violations: {e}")
|
||||
|
||||
@@ -73,15 +72,14 @@ def handle_pool_hub_capacity_snapshots(args):
|
||||
return
|
||||
|
||||
pool_hub_url = getattr(config, "pool_hub_url", "http://localhost:8012")
|
||||
response = requests.get(f"{pool_hub_url}/sla/capacity/snapshots", timeout=30)
|
||||
http_client = AITBCHTTPClient(base_url=pool_hub_url, timeout=30)
|
||||
snapshots = http_client.get("/sla/capacity/snapshots")
|
||||
|
||||
if response.status_code == 200:
|
||||
snapshots = response.json()
|
||||
print("📊 Capacity Snapshots:")
|
||||
for s in snapshots:
|
||||
print(f" {s}")
|
||||
else:
|
||||
print(f"❌ Failed to get snapshots: {response.text}")
|
||||
print("📊 Capacity Snapshots:")
|
||||
for s in snapshots:
|
||||
print(f" {s}")
|
||||
except NetworkError as e:
|
||||
print(f"❌ Failed to get snapshots: {e}")
|
||||
except Exception as e:
|
||||
print(f"❌ Error getting snapshots: {e}")
|
||||
|
||||
@@ -99,15 +97,14 @@ def handle_pool_hub_capacity_forecast(args):
|
||||
return
|
||||
|
||||
pool_hub_url = getattr(config, "pool_hub_url", "http://localhost:8012")
|
||||
response = requests.get(f"{pool_hub_url}/sla/capacity/forecast", timeout=30)
|
||||
http_client = AITBCHTTPClient(base_url=pool_hub_url, timeout=30)
|
||||
forecast = http_client.get("/sla/capacity/forecast")
|
||||
|
||||
if response.status_code == 200:
|
||||
forecast = response.json()
|
||||
print("🔮 Capacity Forecast:")
|
||||
for key, value in forecast.items():
|
||||
print(f" {key}: {value}")
|
||||
else:
|
||||
print(f"❌ Failed to get forecast: {response.text}")
|
||||
print("🔮 Capacity Forecast:")
|
||||
for key, value in forecast.items():
|
||||
print(f" {key}: {value}")
|
||||
except NetworkError as e:
|
||||
print(f"❌ Failed to get forecast: {e}")
|
||||
except Exception as e:
|
||||
print(f"❌ Error getting forecast: {e}")
|
||||
|
||||
@@ -125,15 +122,14 @@ def handle_pool_hub_capacity_recommendations(args):
|
||||
return
|
||||
|
||||
pool_hub_url = getattr(config, "pool_hub_url", "http://localhost:8012")
|
||||
response = requests.get(f"{pool_hub_url}/sla/capacity/recommendations", timeout=30)
|
||||
http_client = AITBCHTTPClient(base_url=pool_hub_url, timeout=30)
|
||||
recommendations = http_client.get("/sla/capacity/recommendations")
|
||||
|
||||
if response.status_code == 200:
|
||||
recommendations = response.json()
|
||||
print("💡 Capacity Recommendations:")
|
||||
for r in recommendations:
|
||||
print(f" {r}")
|
||||
else:
|
||||
print(f"❌ Failed to get recommendations: {response.text}")
|
||||
print("💡 Capacity Recommendations:")
|
||||
for r in recommendations:
|
||||
print(f" {r}")
|
||||
except NetworkError as e:
|
||||
print(f"❌ Failed to get recommendations: {e}")
|
||||
except Exception as e:
|
||||
print(f"❌ Error getting recommendations: {e}")
|
||||
|
||||
@@ -151,15 +147,14 @@ def handle_pool_hub_billing_usage(args):
|
||||
return
|
||||
|
||||
pool_hub_url = getattr(config, "pool_hub_url", "http://localhost:8012")
|
||||
response = requests.get(f"{pool_hub_url}/sla/billing/usage", timeout=30)
|
||||
http_client = AITBCHTTPClient(base_url=pool_hub_url, timeout=30)
|
||||
usage = http_client.get("/sla/billing/usage")
|
||||
|
||||
if response.status_code == 200:
|
||||
usage = response.json()
|
||||
print("💰 Billing Usage:")
|
||||
for key, value in usage.items():
|
||||
print(f" {key}: {value}")
|
||||
else:
|
||||
print(f"❌ Failed to get billing usage: {response.text}")
|
||||
print("💰 Billing Usage:")
|
||||
for key, value in usage.items():
|
||||
print(f" {key}: {value}")
|
||||
except NetworkError as e:
|
||||
print(f"❌ Failed to get billing usage: {e}")
|
||||
except Exception as e:
|
||||
print(f"❌ Error getting billing usage: {e}")
|
||||
|
||||
@@ -176,14 +171,13 @@ def handle_pool_hub_billing_sync(args):
|
||||
return
|
||||
|
||||
pool_hub_url = getattr(config, "pool_hub_url", "http://localhost:8012")
|
||||
response = requests.post(f"{pool_hub_url}/sla/billing/sync", timeout=60)
|
||||
http_client = AITBCHTTPClient(base_url=pool_hub_url, timeout=60)
|
||||
result = http_client.post("/sla/billing/sync")
|
||||
|
||||
if response.status_code == 200:
|
||||
result = response.json()
|
||||
print("🔄 Billing sync triggered")
|
||||
print(f"✅ {result.get('message', 'Success')}")
|
||||
else:
|
||||
print(f"❌ Billing sync failed: {response.text}")
|
||||
print("🔄 Billing sync triggered")
|
||||
print(f"✅ {result.get('message', 'Success')}")
|
||||
except NetworkError as e:
|
||||
print(f"❌ Billing sync failed: {e}")
|
||||
except Exception as e:
|
||||
print(f"❌ Error triggering billing sync: {e}")
|
||||
|
||||
@@ -200,13 +194,12 @@ def handle_pool_hub_collect_metrics(args):
|
||||
return
|
||||
|
||||
pool_hub_url = getattr(config, "pool_hub_url", "http://localhost:8012")
|
||||
response = requests.post(f"{pool_hub_url}/sla/metrics/collect", timeout=60)
|
||||
http_client = AITBCHTTPClient(base_url=pool_hub_url, timeout=60)
|
||||
result = http_client.post("/sla/metrics/collect")
|
||||
|
||||
if response.status_code == 200:
|
||||
result = response.json()
|
||||
print("📊 SLA metrics collection triggered")
|
||||
print(f"✅ {result.get('message', 'Success')}")
|
||||
else:
|
||||
print(f"❌ Metrics collection failed: {response.text}")
|
||||
print("📊 SLA metrics collection triggered")
|
||||
print(f"✅ {result.get('message', 'Success')}")
|
||||
except NetworkError as e:
|
||||
print(f"❌ Metrics collection failed: {e}")
|
||||
except Exception as e:
|
||||
print(f"❌ Error triggering metrics collection: {e}")
|
||||
|
||||
Reference in New Issue
Block a user