feat: migrate exchange_island CLI buy command to use centralized aitbc package HTTP client
Some checks failed
CLI Tests / test-cli (push) Failing after 2s
Security Scanning / security-scan (push) Failing after 14m33s
Blockchain Synchronization Verification / sync-verification (push) Failing after 9s
P2P Network Verification / p2p-verification (push) Successful in 4s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 6s
Some checks failed
CLI Tests / test-cli (push) Failing after 2s
Security Scanning / security-scan (push) Failing after 14m33s
Blockchain Synchronization Verification / sync-verification (push) Failing after 9s
P2P Network Verification / p2p-verification (push) Successful in 4s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 6s
- Replace httpx.Client with aitbc.AITBCHTTPClient in buy command - Remove async context manager in favor of direct AITBCHTTPClient usage - Replace status code checks with NetworkError exception handling - Remove httpx import (no longer needed) - Simplify error handling with separate NetworkError and generic Exception catches
This commit is contained in:
@@ -101,16 +101,8 @@ def buy(ctx, ait_amount: float, quote_currency: str, max_price: Optional[float])
|
|||||||
|
|
||||||
# Submit transaction to blockchain
|
# Submit transaction to blockchain
|
||||||
try:
|
try:
|
||||||
import httpx
|
http_client = AITBCHTTPClient(base_url=rpc_endpoint, timeout=10)
|
||||||
with httpx.Client() as client:
|
result = http_client.post("/transaction", json=buy_order_data)
|
||||||
response = client.post(
|
|
||||||
f"{rpc_endpoint}/transaction",
|
|
||||||
json=buy_order_data,
|
|
||||||
timeout=10
|
|
||||||
)
|
|
||||||
|
|
||||||
if response.status_code == 200:
|
|
||||||
result = response.json()
|
|
||||||
success(f"Buy order created successfully!")
|
success(f"Buy order created successfully!")
|
||||||
success(f"Order ID: {order_id}")
|
success(f"Order ID: {order_id}")
|
||||||
success(f"Buying {ait_amount} AIT with {quote_currency}")
|
success(f"Buying {ait_amount} AIT with {quote_currency}")
|
||||||
@@ -128,15 +120,12 @@ def buy(ctx, ait_amount: float, quote_currency: str, max_price: Optional[float])
|
|||||||
"User": user_id[:16] + "...",
|
"User": user_id[:16] + "...",
|
||||||
"Island": island_id[:16] + "..."
|
"Island": island_id[:16] + "..."
|
||||||
}
|
}
|
||||||
|
|
||||||
output(order_info, ctx.obj.get('output_format', 'table'))
|
output(order_info, ctx.obj.get('output_format', 'table'))
|
||||||
else:
|
except NetworkError as e:
|
||||||
error(f"Failed to submit transaction: {response.status_code}")
|
error(f"Network error submitting transaction: {e}")
|
||||||
if response.text:
|
|
||||||
error(f"Error details: {response.text}")
|
|
||||||
raise click.Abort()
|
raise click.Abort()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error(f"Network error submitting transaction: {e}")
|
error(f"Error submitting transaction: {e}")
|
||||||
raise click.Abort()
|
raise click.Abort()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user