Fix cross-chain bridge web3 import and RPC URL configuration
Some checks failed
Cross-Node Transaction Testing / transaction-test (push) Has been cancelled
Deploy to Testnet / deploy-testnet (push) Has been cancelled
Integration Tests / test-service-integration (push) Has been cancelled
Multi-Node Stress Testing / stress-test (push) Has been cancelled
Python Tests / test-python (push) Has been cancelled
Security Scanning / security-scan (push) Has been cancelled

- Move web3 import to top of web3_utils.py to resolve import context issue
- Add direct Web3Client import to aitbc/__init__.py for early loading
- Replace all mock RPC URLs with actual AITBC blockchain RPC endpoint (http://localhost:8006)
- Note: Bridge service still has fundamental incompatibility - uses Ethereum web3 but AITBC is not Ethereum-compatible
- This blocks Scenario 27 cross-chain trading test until AITBC-specific adapter is implemented
This commit is contained in:
aitbc
2026-05-14 12:07:11 +02:00
parent 58376a3aec
commit fd7a04cc27
5 changed files with 28 additions and 14 deletions

View File

@@ -65,6 +65,11 @@ from .utils.paths import (
get_repo_path,
resolve_path,
)
try:
from .network.web3_utils import Web3Client, create_web3_client
_WEB3_AVAILABLE = True
except ImportError:
_WEB3_AVAILABLE = False
_LAZY_EXPORTS: dict[str, tuple[str, str]] = {
"load_json": ("utils.json_utils", "load_json"),

View File

@@ -6,16 +6,23 @@ Provides Ethereum blockchain interaction utilities using web3.py
from typing import Any, Optional
from decimal import Decimal
try:
from web3 import Web3
from web3.middleware import geth_poa_middleware
WEB3_AVAILABLE = True
except ImportError:
WEB3_AVAILABLE = False
class Web3Client:
"""Web3 client wrapper for blockchain operations"""
def __init__(self, rpc_url: str, timeout: int = 30):
"""Initialize Web3 client with RPC URL"""
try:
from web3 import Web3
from web3.middleware import geth_poa_middleware
if not WEB3_AVAILABLE:
raise ImportError("web3 is required for blockchain operations. Install with: pip install web3")
try:
self.w3 = Web3(Web3.HTTPProvider(rpc_url, request_kwargs={'timeout': timeout}))
# Add POA middleware for chains like Polygon, BSC, etc.
@@ -23,8 +30,6 @@ class Web3Client:
if not self.w3.is_connected():
raise ConnectionError(f"Failed to connect to RPC URL: {rpc_url}")
except ImportError:
raise ImportError("web3 is required for blockchain operations. Install with: pip install web3")
except Exception as e:
raise ConnectionError(f"Failed to initialize Web3 client: {e}")

View File

@@ -66,7 +66,7 @@ async def create_enhanced_wallet(
raise HTTPException(status_code=404, detail="Identity not found for address")
# Create wallet adapter
adapter = WalletAdapterFactory.create_adapter(chain_id, "mock_rpc_url", security_level)
adapter = WalletAdapterFactory.create_adapter(chain_id, "http://localhost:8006", security_level)
# Create wallet
wallet_data = await adapter.create_wallet(owner_address, security_config)
@@ -261,7 +261,11 @@ async def create_bridge_request(
bridge_service = CrossChainBridgeService(session)
# Initialize bridge if not already done
chain_configs = {source_chain_id: {"rpc_url": "mock_rpc_url"}, target_chain_id: {"rpc_url": "mock_rpc_url"}}
# Use actual RPC URLs for AITBC blockchain nodes
chain_configs = {
source_chain_id: {"rpc_url": "http://localhost:8006"},
target_chain_id: {"rpc_url": "http://localhost:8006"}
}
await bridge_service.initialize_bridge(chain_configs)
# Create bridge request
@@ -390,7 +394,7 @@ async def submit_transaction(
tx_manager = MultiChainTransactionManager(session)
# Initialize with mock configs
chain_configs = {chain_id: {"rpc_url": "mock_rpc_url"}}
chain_configs = {chain_id: {"rpc_url": "http://localhost:8006"}}
await tx_manager.initialize(chain_configs)
# Submit transaction
@@ -428,7 +432,7 @@ async def get_transaction_status(request: Request, transaction_id: str, session:
tx_manager = MultiChainTransactionManager(session)
# Initialize with mock configs
chain_configs = {1: {"rpc_url": "mock_rpc_url"}, 137: {"rpc_url": "mock_rpc_url"}}
chain_configs = {1: {"rpc_url": "http://localhost:8006"}, 137: {"rpc_url": "http://localhost:8006"}}
await tx_manager.initialize(chain_configs)
# Get transaction status
@@ -450,7 +454,7 @@ async def cancel_transaction(request: Request, transaction_id: str, reason: str,
tx_manager = MultiChainTransactionManager(session)
# Initialize with mock configs
chain_configs = {1: {"rpc_url": "mock_rpc_url"}, 137: {"rpc_url": "mock_rpc_url"}}
chain_configs = {1: {"rpc_url": "http://localhost:8006"}, 137: {"rpc_url": "http://localhost:8006"}}
await tx_manager.initialize(chain_configs)
# Cancel transaction
@@ -484,7 +488,7 @@ async def get_transaction_history(
tx_manager = MultiChainTransactionManager(session)
# Initialize with mock configs
chain_configs = {1: {"rpc_url": "mock_rpc_url"}, 137: {"rpc_url": "mock_rpc_url"}}
chain_configs = {1: {"rpc_url": "http://localhost:8006"}, 137: {"rpc_url": "http://localhost:8006"}}
await tx_manager.initialize(chain_configs)
# Get transaction history
@@ -521,7 +525,7 @@ async def get_transaction_statistics(
tx_manager = MultiChainTransactionManager(session)
# Initialize with mock configs
chain_configs = {1: {"rpc_url": "mock_rpc_url"}, 137: {"rpc_url": "mock_rpc_url"}}
chain_configs = {1: {"rpc_url": "http://localhost:8006"}, 137: {"rpc_url": "http://localhost:8006"}}
await tx_manager.initialize(chain_configs)
# Get statistics
@@ -551,7 +555,7 @@ async def optimize_transaction_routing(
tx_manager = MultiChainTransactionManager(session)
# Initialize with mock configs
chain_configs = {1: {"rpc_url": "mock_rpc_url"}, 137: {"rpc_url": "mock_rpc_url"}}
chain_configs = {1: {"rpc_url": "http://localhost:8006"}, 137: {"rpc_url": "http://localhost:8006"}}
await tx_manager.initialize(chain_configs)
# Optimize routing
@@ -623,7 +627,7 @@ async def get_cross_chain_health(request: Request, session: Session = Depends(ge
tx_manager = MultiChainTransactionManager(session)
# Initialize with mock configs
chain_configs = {chain_id: {"rpc_url": "mock_rpc_url"} for chain_id in supported_chains}
chain_configs = {chain_id: {"rpc_url": "http://localhost:8006"} for chain_id in supported_chains}
await bridge_service.initialize_bridge(chain_configs)
await tx_manager.initialize(chain_configs)