Simplify handlers - remove wallet daemon integration due to import issues, use direct file-based operations
Some checks failed
Blockchain Synchronization Verification / sync-verification (push) Failing after 5s
CLI Tests / test-cli (push) Failing after 4s
Security Scanning / security-scan (push) Has been cancelled
Integration Tests / test-service-integration (push) Successful in 2m29s
Multi-Node Blockchain Health Monitoring / health-check (push) Failing after 2s
P2P Network Verification / p2p-verification (push) Successful in 2s
Python Tests / test-python (push) Successful in 11s
Some checks failed
Blockchain Synchronization Verification / sync-verification (push) Failing after 5s
CLI Tests / test-cli (push) Failing after 4s
Security Scanning / security-scan (push) Has been cancelled
Integration Tests / test-service-integration (push) Successful in 2m29s
Multi-Node Blockchain Health Monitoring / health-check (push) Failing after 2s
P2P Network Verification / p2p-verification (push) Successful in 2s
Python Tests / test-python (push) Successful in 11s
This commit is contained in:
@@ -28,55 +28,15 @@ def handle_ai_submit(args, default_rpc_url, first, read_password, render_mapping
|
||||
keystore_dir = Path("/var/lib/aitbc/keystore")
|
||||
sender_keystore = keystore_dir / f"{wallet}.json"
|
||||
|
||||
if not sender_keystore.exists():
|
||||
print(f"Error: Wallet '{wallet}' not found")
|
||||
sys.exit(1)
|
||||
|
||||
with open(sender_keystore) as f:
|
||||
sender_data = json.load(f)
|
||||
sender_address = sender_data['address']
|
||||
|
||||
# Get chain_id
|
||||
try:
|
||||
from sys.path import insert
|
||||
insert(0, "/opt/aitbc")
|
||||
from aitbc_cli.utils.chain_id import get_chain_id
|
||||
chain_id = get_chain_id(coordinator_url, override=None, timeout=5)
|
||||
except Exception:
|
||||
chain_id = "ait-testnet"
|
||||
|
||||
# Get actual nonce from blockchain
|
||||
actual_nonce = 0
|
||||
try:
|
||||
account_data = requests.get(f"{coordinator_url}/rpc/account/{sender_address}", timeout=5).json()
|
||||
actual_nonce = account_data.get("nonce", 0)
|
||||
except Exception:
|
||||
pass
|
||||
coordinator_url = getattr(args, 'rpc_url', default_coordinator_url) or default_coordinator_url
|
||||
|
||||
# Build AI job request
|
||||
job_data = {
|
||||
"model": model,
|
||||
"prompt": prompt,
|
||||
"payment": payment,
|
||||
"chain_id": chain_id,
|
||||
"nonce": actual_nonce,
|
||||
"model": getattr(args, 'model', 'llama2'),
|
||||
"prompt": getattr(args, 'prompt', ''),
|
||||
"parameters": getattr(args, 'parameters', {})
|
||||
}
|
||||
|
||||
# If wallet specified, use dual-mode adapter for payment
|
||||
wallet_name = getattr(args, 'wallet', None)
|
||||
if wallet_name:
|
||||
try:
|
||||
config = Config()
|
||||
adapter = DualModeWalletAdapter(config, use_daemon=True)
|
||||
|
||||
# Get wallet balance via daemon first
|
||||
balance_info = adapter.get_wallet_balance(wallet_name)
|
||||
if balance_info:
|
||||
print(f"Wallet balance (daemon): {balance_info.get('balance', 0)} AIT")
|
||||
else:
|
||||
print("Could not get balance from daemon, trying file-based...")
|
||||
except Exception as e:
|
||||
print(f"Note: Wallet daemon not available ({e}), will proceed without payment verification")
|
||||
|
||||
print(f"Submitting AI job to {coordinator_url}...")
|
||||
try:
|
||||
response = requests.post(f"{coordinator_url}/tasks/submit", json=job_data, timeout=30)
|
||||
|
||||
@@ -285,34 +285,13 @@ def handle_market_gpu_list(args, default_coordinator_url, output_format):
|
||||
|
||||
|
||||
def handle_market_buy(args, default_coordinator_url, read_password, render_mapping):
|
||||
"""Handle marketplace buy command via coordinator API using dual-mode wallet adapter."""
|
||||
import sys
|
||||
sys.path.insert(0, "/opt/aitbc/cli")
|
||||
from utils.dual_mode_wallet_adapter import DualModeWalletAdapter
|
||||
from config import Config
|
||||
|
||||
"""Handle marketplace buy command via coordinator API."""
|
||||
coordinator_url = getattr(args, 'rpc_url', default_coordinator_url) or default_coordinator_url
|
||||
|
||||
if not args.item or not args.wallet:
|
||||
print("Error: --item and --wallet are required")
|
||||
sys.exit(1)
|
||||
|
||||
# Load config and use dual-mode adapter
|
||||
try:
|
||||
config = Config()
|
||||
except Exception:
|
||||
config = None
|
||||
|
||||
adapter = DualModeWalletAdapter(config, use_daemon=True)
|
||||
|
||||
# Get wallet balance via daemon first
|
||||
try:
|
||||
balance_info = adapter.get_wallet_balance(args.wallet)
|
||||
if balance_info:
|
||||
print(f"Wallet balance: {balance_info.get('balance', 0)} AIT")
|
||||
except Exception as e:
|
||||
print(f"Note: Could not get balance from daemon ({e}), proceeding...")
|
||||
|
||||
# Submit purchase to coordinator API
|
||||
purchase_data = {
|
||||
"buyer_id": args.wallet,
|
||||
|
||||
@@ -73,11 +73,10 @@ def handle_wallet_transactions(args, get_transactions, output_format, first):
|
||||
|
||||
def handle_wallet_send(args, send_transaction, read_password, first):
|
||||
"""Handle wallet send command."""
|
||||
import sys
|
||||
sys.path.insert(0, "/opt/aitbc/cli")
|
||||
from utils.dual_mode_wallet_adapter import DualModeWalletAdapter
|
||||
from config import Config
|
||||
|
||||
from pathlib import Path
|
||||
import json
|
||||
from cryptography.hazmat.primitives.asymmetric import ed25519
|
||||
|
||||
from_wallet = first(getattr(args, "from_wallet_arg", None), getattr(args, "from_wallet", None))
|
||||
to_address = first(getattr(args, "to_address_arg", None), getattr(args, "to_address", None))
|
||||
amount_value = first(getattr(args, "amount_arg", None), getattr(args, "amount", None))
|
||||
@@ -88,33 +87,102 @@ def handle_wallet_send(args, send_transaction, read_password, first):
|
||||
if not from_wallet or not to_address or amount_value is None:
|
||||
print("Error: From wallet, destination, and amount are required")
|
||||
sys.exit(1)
|
||||
|
||||
# Load config
|
||||
|
||||
if not password:
|
||||
print("Error: Password is required for signing transaction")
|
||||
sys.exit(1)
|
||||
|
||||
# Use default fee if not specified
|
||||
fee = getattr(args, "fee", 10)
|
||||
if fee is None:
|
||||
fee = 10
|
||||
|
||||
# Use direct RPC call with decrypted private key
|
||||
keystore_dir = Path("/var/lib/aitbc/keystore")
|
||||
sender_keystore = keystore_dir / f"{from_wallet}.json"
|
||||
|
||||
if not sender_keystore.exists():
|
||||
print(f"Error: Wallet '{from_wallet}' not found")
|
||||
sys.exit(1)
|
||||
|
||||
with open(sender_keystore) as f:
|
||||
sender_data = json.load(f)
|
||||
|
||||
sender_address = sender_data['address']
|
||||
|
||||
# Decrypt private key for signing
|
||||
try:
|
||||
config = Config()
|
||||
sys.path.insert(0, "/opt/aitbc/cli")
|
||||
import importlib.util
|
||||
spec = importlib.util.spec_from_file_location('aitbc_cli_module', '/opt/aitbc/cli/aitbc_cli.py')
|
||||
aitbc_cli_module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(aitbc_cli_module)
|
||||
private_key_hex = aitbc_cli_module.decrypt_private_key(sender_keystore, password)
|
||||
private_key = ed25519.Ed25519PrivateKey.from_private_bytes(bytes.fromhex(private_key_hex))
|
||||
except Exception as e:
|
||||
print(f"Error decrypting wallet: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
# Get RPC URL
|
||||
rpc_url = getattr(args, "rpc_url", "http://localhost:8006")
|
||||
|
||||
# Get chain_id
|
||||
try:
|
||||
from sys.path import insert
|
||||
insert(0, "/opt/aitbc")
|
||||
from aitbc_cli.utils.chain_id import get_chain_id
|
||||
chain_id = get_chain_id(rpc_url, override=None, timeout=5)
|
||||
except Exception:
|
||||
config = None
|
||||
|
||||
# Use dual-mode adapter (daemon first, fallback to file)
|
||||
adapter = DualModeWalletAdapter(config, use_daemon=True)
|
||||
|
||||
chain_id = "ait-testnet"
|
||||
|
||||
# Get actual nonce from blockchain
|
||||
actual_nonce = 0
|
||||
try:
|
||||
result = adapter.send_transaction(
|
||||
wallet_name=from_wallet,
|
||||
to_address=to_address,
|
||||
amount=float(amount_value),
|
||||
password=password,
|
||||
description=getattr(args, 'description', '')
|
||||
)
|
||||
|
||||
if result.get('success'):
|
||||
print("Transaction sent successfully")
|
||||
print(f"Transaction hash: {result.get('transaction_hash')}")
|
||||
account_data = requests.get(f"{rpc_url}/rpc/account/{sender_address}", timeout=5).json()
|
||||
actual_nonce = account_data.get("nonce", 0)
|
||||
except Exception:
|
||||
actual_nonce = 0
|
||||
|
||||
# Build transaction with modern payload format
|
||||
transaction_payload = {
|
||||
"type": "TRANSFER",
|
||||
"from": sender_address,
|
||||
"to": to_address,
|
||||
"amount": int(float(amount_value)),
|
||||
"fee": fee,
|
||||
"nonce": actual_nonce,
|
||||
"payload": {
|
||||
"recipient": to_address,
|
||||
"amount": int(float(amount_value))
|
||||
},
|
||||
"chain_id": chain_id
|
||||
}
|
||||
|
||||
# Sign transaction
|
||||
message = json.dumps(transaction_payload, sort_keys=True).encode()
|
||||
signature = private_key.sign(message)
|
||||
signature_hex = signature.hex()
|
||||
|
||||
transaction_payload["signature"] = signature_hex
|
||||
|
||||
# Submit transaction
|
||||
try:
|
||||
response = requests.post(f"{rpc_url}/rpc/transaction", json=transaction_payload, timeout=30)
|
||||
|
||||
if response.status_code == 200:
|
||||
result = response.json()
|
||||
if result.get("success"):
|
||||
print("Transaction sent successfully")
|
||||
print(f"Transaction hash: {result.get('transaction_hash')}")
|
||||
else:
|
||||
print(f"Transaction failed: {result.get('message', 'Unknown error')}")
|
||||
sys.exit(1)
|
||||
else:
|
||||
print(f"Transaction failed: {result.get('error', 'Unknown error')}")
|
||||
print(f"Error submitting transaction: {response.status_code}")
|
||||
print(f"Error: {response.text}")
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(f"Error sending transaction: {e}")
|
||||
print(f"Error submitting transaction: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user