Integrate CLIContractClient into AgentContractIntegration
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
Node Failover Simulation / failover-test (push) Has been cancelled
Package Tests / Python package - aitbc-agent-sdk (push) Has been cancelled
Package Tests / Python package - aitbc-core (push) Has been cancelled
Package Tests / Python package - aitbc-crypto (push) Has been cancelled
Package Tests / Python package - aitbc-sdk (push) Has been cancelled
Package Tests / JavaScript package - aitbc-sdk-js (push) Has been cancelled
Package Tests / JavaScript package - aitbc-token (push) Has been cancelled
Python Tests / test-python (push) Has been cancelled
Security Scanning / security-scan (push) Has been cancelled
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
Node Failover Simulation / failover-test (push) Has been cancelled
Package Tests / Python package - aitbc-agent-sdk (push) Has been cancelled
Package Tests / Python package - aitbc-core (push) Has been cancelled
Package Tests / Python package - aitbc-crypto (push) Has been cancelled
Package Tests / Python package - aitbc-sdk (push) Has been cancelled
Package Tests / JavaScript package - aitbc-sdk-js (push) Has been cancelled
Package Tests / JavaScript package - aitbc-token (push) Has been cancelled
Python Tests / test-python (push) Has been cancelled
Security Scanning / security-scan (push) Has been cancelled
- Added factory function create_agent_contract_integration() - Updated agent.py to use factory instead of manual client creation - CLIContractClient used when config.use_cli=True
This commit is contained in:
@@ -17,7 +17,12 @@ from cryptography.hazmat.primitives.asymmetric import padding
|
||||
from aitbc.aitbc_logging import get_logger
|
||||
from aitbc.exceptions import NetworkError
|
||||
from aitbc.http_client import AITBCHTTPClient
|
||||
from aitbc_agent.contract_integration import AgentContractIntegration, ContractClient, ContractConfig
|
||||
from aitbc_agent.contract_integration import (
|
||||
AgentContractIntegration,
|
||||
ContractClient,
|
||||
ContractConfig,
|
||||
create_agent_contract_integration
|
||||
)
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
@@ -110,16 +115,15 @@ class Agent:
|
||||
self.http_client = AITBCHTTPClient(base_url=self.coordinator_url)
|
||||
|
||||
# Contract integration
|
||||
self.contract_client: Optional[ContractClient] = None
|
||||
self.contract_integration: Optional[AgentContractIntegration] = None
|
||||
|
||||
if contract_config:
|
||||
try:
|
||||
self.contract_client = ContractClient(
|
||||
# Use factory function to create appropriate client
|
||||
self.contract_integration = create_agent_contract_integration(
|
||||
config=contract_config,
|
||||
private_key=identity.private_key
|
||||
)
|
||||
self.contract_integration = AgentContractIntegration(self.contract_client)
|
||||
self.contract_integration.set_agent_address(identity.address)
|
||||
logger.info("Contract integration initialized for agent")
|
||||
except Exception as e:
|
||||
|
||||
@@ -13,6 +13,14 @@ from web3.contract import Contract
|
||||
from aitbc.aitbc_logging import get_logger
|
||||
from aitbc.exceptions import NetworkError
|
||||
|
||||
# Import CLI client for AITBC (no Web3 needed)
|
||||
try:
|
||||
from .cli_contract_client import CLIContractClient
|
||||
CLI_AVAILABLE = True
|
||||
except ImportError:
|
||||
CLI_AVAILABLE = False
|
||||
CLIContractClient = None
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
||||
@@ -24,6 +32,7 @@ class ContractConfig:
|
||||
staking_contract: str
|
||||
treasury_manager: str
|
||||
cross_chain_atomic_swap: str = "" # CrossChainAtomicSwap contract
|
||||
use_cli: bool = False # Use CLI-based client (for AITBC)
|
||||
network: str = "mainnet"
|
||||
rpc_url: Optional[str] = None
|
||||
|
||||
@@ -576,3 +585,23 @@ def getenv(key: str, default: str = "") -> str:
|
||||
"""Get environment variable with default"""
|
||||
import os
|
||||
return os.getenv(key, default)
|
||||
|
||||
|
||||
def create_agent_contract_integration(
|
||||
config: ContractConfig,
|
||||
private_key: Optional[str] = None
|
||||
) -> AgentContractIntegration:
|
||||
"""
|
||||
Factory function to create AgentContractIntegration with appropriate client.
|
||||
|
||||
Uses CLIContractClient if config.use_cli=True and CLI is available,
|
||||
otherwise uses standard ContractClient (Web3-based).
|
||||
"""
|
||||
if config.use_cli and CLI_AVAILABLE and CLIContractClient is not None:
|
||||
logger.info("Using CLI-based contract client (no Web3 needed)")
|
||||
contract_client = CLIContractClient(config, private_key)
|
||||
else:
|
||||
logger.info("Using Web3-based contract client")
|
||||
contract_client = ContractClient(config, private_key)
|
||||
|
||||
return AgentContractIntegration(contract_client)
|
||||
|
||||
Reference in New Issue
Block a user