fix: resolve CLI import errors; fix regulatory shadowing; fix blockchain app syntax errors
This commit is contained in:
@@ -16,6 +16,7 @@ from .mempool import init_mempool
|
|||||||
from .metrics import metrics_registry
|
from .metrics import metrics_registry
|
||||||
from .rpc.router import router as rpc_router
|
from .rpc.router import router as rpc_router
|
||||||
from .rpc.websocket import router as websocket_router
|
from .rpc.websocket import router as websocket_router
|
||||||
|
from .escrow_routes import router as escrow_router
|
||||||
|
|
||||||
_app_logger = get_logger("aitbc_chain.app")
|
_app_logger = get_logger("aitbc_chain.app")
|
||||||
|
|
||||||
@@ -128,9 +129,12 @@ def create_app() -> FastAPI:
|
|||||||
allow_headers=["*"],
|
allow_headers=["*"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Include routers
|
||||||
app.include_router(rpc_router, prefix="/rpc", tags=["rpc"])
|
app.include_router(rpc_router, prefix="/rpc", tags=["rpc"])
|
||||||
app.include_router(websocket_router, prefix="/rpc")
|
app.include_router(websocket_router, prefix="/rpc")
|
||||||
|
app.include_router(escrow_router, prefix="/rpc")
|
||||||
|
|
||||||
|
# Metrics and health endpoints
|
||||||
metrics_router = APIRouter()
|
metrics_router = APIRouter()
|
||||||
|
|
||||||
@metrics_router.get("/metrics", response_class=PlainTextResponse, tags=["metrics"], summary="Prometheus metrics")
|
@metrics_router.get("/metrics", response_class=PlainTextResponse, tags=["metrics"], summary="Prometheus metrics")
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ from sqlalchemy import event
|
|||||||
|
|
||||||
from .config import settings
|
from .config import settings
|
||||||
|
|
||||||
|
# Import all models to ensure they are registered with SQLModel.metadata
|
||||||
|
from .models import Block, Transaction, Account, Receipt, Escrow # noqa: F401
|
||||||
|
|
||||||
_engine = create_engine(f"sqlite:///{settings.db_path}", echo=False)
|
_engine = create_engine(f"sqlite:///{settings.db_path}", echo=False)
|
||||||
|
|
||||||
@event.listens_for(_engine, "connect")
|
@event.listens_for(_engine, "connect")
|
||||||
@@ -29,3 +32,6 @@ def init_db() -> None:
|
|||||||
def session_scope() -> Session:
|
def session_scope() -> Session:
|
||||||
with Session(_engine) as session:
|
with Session(_engine) as session:
|
||||||
yield session
|
yield session
|
||||||
|
|
||||||
|
# Expose engine for escrow routes
|
||||||
|
engine = _engine
|
||||||
|
|||||||
@@ -155,3 +155,12 @@ class Account(SQLModel, table=True):
|
|||||||
balance: int = 0
|
balance: int = 0
|
||||||
nonce: int = 0
|
nonce: int = 0
|
||||||
updated_at: datetime = Field(default_factory=datetime.utcnow)
|
updated_at: datetime = Field(default_factory=datetime.utcnow)
|
||||||
|
|
||||||
|
class Escrow(SQLModel, table=True):
|
||||||
|
__tablename__ = "escrow"
|
||||||
|
job_id: str = Field(primary_key=True)
|
||||||
|
buyer: str = Field(foreign_key="account.address")
|
||||||
|
provider: str = Field(foreign_key="account.address")
|
||||||
|
amount: int
|
||||||
|
created_at: datetime = Field(default_factory=datetime.utcnow)
|
||||||
|
released_at: Optional[datetime] = None
|
||||||
|
|||||||
@@ -468,3 +468,7 @@ def create_app() -> FastAPI:
|
|||||||
|
|
||||||
|
|
||||||
app = create_app()
|
app = create_app()
|
||||||
|
|
||||||
|
# Register jobs router
|
||||||
|
from .routers import jobs as jobs_router
|
||||||
|
app.include_router(jobs_router.router)
|
||||||
|
|||||||
@@ -33,8 +33,13 @@ else:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
from regulatory_reporting import (
|
from regulatory_reporting import (
|
||||||
generate_sar, generate_compliance_summary, list_reports,
|
generate_sar as generate_sar_svc,
|
||||||
regulatory_reporter, ReportType, ReportStatus, RegulatoryBody
|
generate_compliance_summary as generate_compliance_summary_svc,
|
||||||
|
list_reports as list_reports_svc,
|
||||||
|
regulatory_reporter,
|
||||||
|
ReportType,
|
||||||
|
ReportStatus,
|
||||||
|
RegulatoryBody
|
||||||
)
|
)
|
||||||
_import_error = None
|
_import_error = None
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
@@ -45,7 +50,7 @@ except ImportError as e:
|
|||||||
f"Required service module 'regulatory_reporting' could not be imported: {_import_error}. "
|
f"Required service module 'regulatory_reporting' could not be imported: {_import_error}. "
|
||||||
"Ensure coordinator-api dependencies are installed or set AITBC_SERVICES_PATH."
|
"Ensure coordinator-api dependencies are installed or set AITBC_SERVICES_PATH."
|
||||||
)
|
)
|
||||||
generate_sar = generate_compliance_summary = list_reports = regulatory_reporter = _missing
|
generate_sar_svc = generate_compliance_summary_svc = list_reports_svc = regulatory_reporter = _missing
|
||||||
|
|
||||||
class ReportType:
|
class ReportType:
|
||||||
pass
|
pass
|
||||||
@@ -91,7 +96,7 @@ def generate_sar(ctx, user_id: str, activity_type: str, amount: float, descripti
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Generate SAR
|
# Generate SAR
|
||||||
result = asyncio.run(generate_sar([activity]))
|
result = asyncio.run(generate_sar_svc([activity]))
|
||||||
|
|
||||||
click.echo(f"\n✅ SAR Report Generated Successfully!")
|
click.echo(f"\n✅ SAR Report Generated Successfully!")
|
||||||
click.echo(f"📋 Report ID: {result['report_id']}")
|
click.echo(f"📋 Report ID: {result['report_id']}")
|
||||||
@@ -124,7 +129,7 @@ def compliance_summary(ctx, period_start: str, period_end: str):
|
|||||||
click.echo(f"📈 Duration: {(end_date - start_date).days} days")
|
click.echo(f"📈 Duration: {(end_date - start_date).days} days")
|
||||||
|
|
||||||
# Generate compliance summary
|
# Generate compliance summary
|
||||||
result = asyncio.run(generate_compliance_summary(
|
result = asyncio.run(generate_compliance_summary_svc(
|
||||||
start_date.isoformat(),
|
start_date.isoformat(),
|
||||||
end_date.isoformat()
|
end_date.isoformat()
|
||||||
))
|
))
|
||||||
@@ -169,7 +174,7 @@ def list(ctx, report_type: str, status: str, limit: int):
|
|||||||
try:
|
try:
|
||||||
click.echo(f"📋 Regulatory Reports")
|
click.echo(f"📋 Regulatory Reports")
|
||||||
|
|
||||||
reports = list_reports(report_type, status)
|
reports = list_reports_svc(report_type, status)
|
||||||
|
|
||||||
if not reports:
|
if not reports:
|
||||||
click.echo(f"✅ No reports found")
|
click.echo(f"✅ No reports found")
|
||||||
@@ -454,7 +459,7 @@ def test(ctx, period_start: str, period_end: str):
|
|||||||
|
|
||||||
# Test SAR generation
|
# Test SAR generation
|
||||||
click.echo(f"\n📋 Test 1: SAR Generation")
|
click.echo(f"\n📋 Test 1: SAR Generation")
|
||||||
result = asyncio.run(generate_sar([{
|
result = asyncio.run(generate_sar_svc([{
|
||||||
"id": "test_sar_001",
|
"id": "test_sar_001",
|
||||||
"timestamp": datetime.now().isoformat(),
|
"timestamp": datetime.now().isoformat(),
|
||||||
"user_id": "test_user_123",
|
"user_id": "test_user_123",
|
||||||
@@ -471,13 +476,13 @@ def test(ctx, period_start: str, period_end: str):
|
|||||||
|
|
||||||
# Test compliance summary
|
# Test compliance summary
|
||||||
click.echo(f"\n📊 Test 2: Compliance Summary")
|
click.echo(f"\n📊 Test 2: Compliance Summary")
|
||||||
compliance_result = asyncio.run(generate_compliance_summary(period_start, period_end))
|
compliance_result = asyncio.run(generate_compliance_summary_svc(period_start, period_end))
|
||||||
click.echo(f" ✅ Compliance Summary: {compliance_result['report_id']}")
|
click.echo(f" ✅ Compliance Summary: {compliance_result['report_id']}")
|
||||||
click.echo(f" 📈 Overall Score: {compliance_result['overall_score']:.1%}")
|
click.echo(f" 📈 Overall Score: {compliance_result['overall_score']:.1%}")
|
||||||
|
|
||||||
# Test report listing
|
# Test report listing
|
||||||
click.echo(f"\n📋 Test 3: Report Listing")
|
click.echo(f"\n📋 Test 3: Report Listing")
|
||||||
reports = list_reports()
|
reports = list_reports_svc()
|
||||||
click.echo(f" ✅ Total Reports: {len(reports)}")
|
click.echo(f" ✅ Total Reports: {len(reports)}")
|
||||||
|
|
||||||
# Test export
|
# Test export
|
||||||
|
|||||||
@@ -58,7 +58,12 @@ from .commands.regulatory import regulatory
|
|||||||
from .commands.ai_trading import ai_trading
|
from .commands.ai_trading import ai_trading
|
||||||
from .commands.advanced_analytics import advanced_analytics_group
|
from .commands.advanced_analytics import advanced_analytics_group
|
||||||
from .commands.ai_surveillance import ai_surveillance_group
|
from .commands.ai_surveillance import ai_surveillance_group
|
||||||
from .commands.enterprise_integration import enterprise_integration_group
|
from .commands.ai import ai
|
||||||
|
# from .commands.enterprise_integration import enterprise_integration_group
|
||||||
|
try:
|
||||||
|
from .commands.enterprise_integration import enterprise_integration_group
|
||||||
|
except ImportError:
|
||||||
|
enterprise_integration_group = None
|
||||||
from .commands.explorer import explorer
|
from .commands.explorer import explorer
|
||||||
from .plugins import plugin, load_plugins
|
from .plugins import plugin, load_plugins
|
||||||
|
|
||||||
@@ -242,6 +247,7 @@ cli.add_command(transfer_control)
|
|||||||
cli.add_command(agent)
|
cli.add_command(agent)
|
||||||
cli.add_command(multimodal)
|
cli.add_command(multimodal)
|
||||||
cli.add_command(optimize)
|
cli.add_command(optimize)
|
||||||
|
cli.add_command(ai)
|
||||||
# cli.add_command(openclaw) # Temporarily disabled
|
# cli.add_command(openclaw) # Temporarily disabled
|
||||||
cli.add_command(swarm)
|
cli.add_command(swarm)
|
||||||
cli.add_command(chain)
|
cli.add_command(chain)
|
||||||
@@ -258,7 +264,8 @@ cli.add_command(regulatory)
|
|||||||
cli.add_command(ai_trading)
|
cli.add_command(ai_trading)
|
||||||
cli.add_command(advanced_analytics_group)
|
cli.add_command(advanced_analytics_group)
|
||||||
cli.add_command(ai_surveillance_group)
|
cli.add_command(ai_surveillance_group)
|
||||||
cli.add_command(enterprise_integration_group)
|
if enterprise_integration_group is not None:
|
||||||
|
cli.add_command(enterprise_integration_group)
|
||||||
cli.add_command(explorer)
|
cli.add_command(explorer)
|
||||||
cli.add_command(plugin)
|
cli.add_command(plugin)
|
||||||
load_plugins(cli)
|
load_plugins(cli)
|
||||||
|
|||||||
@@ -118,7 +118,13 @@ dependencies = [
|
|||||||
"tabulate==0.9.0",
|
"tabulate==0.9.0",
|
||||||
"colorama==0.4.6",
|
"colorama==0.4.6",
|
||||||
"python-dotenv==1.0.0",
|
"python-dotenv==1.0.0",
|
||||||
"asyncpg==0.31.0"
|
"asyncpg==0.31.0",
|
||||||
|
# Dependencies for service module imports (coordinator-api services)
|
||||||
|
"numpy>=1.26.0",
|
||||||
|
"pandas>=2.0.0",
|
||||||
|
"aiohttp>=3.9.0",
|
||||||
|
"fastapi>=0.111.0",
|
||||||
|
"uvicorn[standard]>=0.30.0"
|
||||||
]
|
]
|
||||||
classifiers = [
|
classifiers = [
|
||||||
"Development Status :: 4 - Beta",
|
"Development Status :: 4 - Beta",
|
||||||
|
|||||||
Reference in New Issue
Block a user