solana-proxy/normalizer.py
afd afa26d0e29 This is a bunch of untested AI slop, first pass.
Implement Solana RPC proxy with automatic failover and caching

- Add multi-provider support for 5 free Solana RPC endpoints (Alchemy, PublicNode, Helius, QuickNode, Solana Public)
- Implement automatic failover with 30-minute backoff for failed providers
- Add disk-based response caching with 100GB LRU eviction
- Create SQLite error logging with UUID tracking
- Support both HTTP JSON-RPC and WebSocket connections
- Include provider-specific authentication handling
- Add response normalization for consistent output
- Write end-to-end tests for core functionality

The proxy provides a unified endpoint that automatically routes requests to available providers, caches responses to reduce load, and logs all errors with retrievable UUIDs for debugging.
2025-07-15 22:10:06 -04:00

28 lines
770 B
Python

from typing import Dict, Any
def normalize_response(provider: str, response: Dict[str, Any]) -> Dict[str, Any]:
normalized = response.copy()
# Ensure consistent field names
if "result" in normalized and normalized["result"] is None:
# Some providers return null, others omit the field
pass
# Handle null vs missing fields consistently
if "error" in normalized and normalized["error"] is None:
del normalized["error"]
return normalized
def normalize_error(error: Exception, error_id: str) -> Dict[str, Any]:
return {
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32603,
"message": str(error),
"data": {"error_id": error_id}
}
}