fix: resolve CLI regressions in wallet send and transactions

Fixed two CLI bugs exposed during training:

1. wallet send - Fixed 'name requests is not defined'
   - Added missing 'import requests' in cli/handlers/wallet.py
   - Command now reaches RPC correctly; failures are blockchain-level

2. wallet transactions - Fixed 'list object has no attribute get'
   - Updated get_transactions in cli/aitbc_cli.py to handle both list and dict responses
   - RPC /rpc/transactions returns a list, CLI expected dict with transactions key
   - Normalizes tx_hash to hash for display

3. Training self-transfer - Skip when wallet has 0 balance
   - Updated scripts/training/stage1_foundation.sh to check wallet balance before self-transfer
   - Avoids retrying guaranteed failures when wallet has no on-chain account

Validation:
- wallet transactions: No longer raises list.get error
- wallet send: Fails correctly at blockchain layer (sender account not found)
- Training script: Skips self-transfer when balance is 0
This commit is contained in:
aitbc
2026-05-04 11:10:40 +02:00
parent 7a0054b53d
commit df865c55b8
3 changed files with 30 additions and 3 deletions

View File

@@ -729,7 +729,27 @@ def get_transactions(wallet_name: str, keystore_dir: Path = DEFAULT_KEYSTORE_DIR
try:
http_client = AITBCHTTPClient(base_url=rpc_url, timeout=30)
tx_data = http_client.get(f"/rpc/transactions?address={address}&limit={limit}")
return tx_data.get("transactions", [])
if isinstance(tx_data, list):
transactions = tx_data
else:
transactions = tx_data.get("transactions", [])
wallet_transactions = []
for tx in transactions:
if not isinstance(tx, dict):
continue
payload = tx.get("payload") if isinstance(tx.get("payload"), dict) else {}
if (
tx.get("sender") == address
or tx.get("recipient") == address
or payload.get("from") == address
or payload.get("to") == address
or payload.get("recipient") == address
):
normalized_tx = dict(tx)
if "hash" not in normalized_tx and "tx_hash" in normalized_tx:
normalized_tx["hash"] = normalized_tx["tx_hash"]
wallet_transactions.append(normalized_tx)
return wallet_transactions
except NetworkError as e:
print(f"Error getting transactions: {e}")
return []

View File

@@ -1,6 +1,7 @@
"""Wallet command handlers."""
import json
import requests
import sys
from aitbc.paths import get_data_path