chore: comments on base64 encoding

This commit is contained in:
smypmsa
2025-04-01 14:37:13 +00:00
parent 54f3bd4b0e
commit 1064247e6d
2 changed files with 11 additions and 11 deletions
+5 -5
View File
@@ -64,7 +64,7 @@ class SolanaClient:
ValueError: If account doesn't exist or has no data ValueError: If account doesn't exist or has no data
""" """
client = await self.get_client() client = await self.get_client()
response = await client.get_account_info(pubkey) response = await client.get_account_info(pubkey, encoding="base64") # base64 encoding for account data by default
if not response.value: if not response.value:
raise ValueError(f"Account {pubkey} not found") raise ValueError(f"Account {pubkey} not found")
return response.value return response.value
@@ -149,7 +149,7 @@ class SolanaClient:
wait_time = 2**attempt wait_time = 2**attempt
logger.warning( logger.warning(
f"Transaction attempt {attempt + 1} failed: {str(e)}, retrying in {wait_time}s" f"Transaction attempt {attempt + 1} failed: {e!s}, retrying in {wait_time}s"
) )
await asyncio.sleep(wait_time) await asyncio.sleep(wait_time)
@@ -170,7 +170,7 @@ class SolanaClient:
await client.confirm_transaction(signature, commitment=commitment) await client.confirm_transaction(signature, commitment=commitment)
return True return True
except Exception as e: except Exception as e:
logger.error(f"Failed to confirm transaction {signature}: {str(e)}") logger.error(f"Failed to confirm transaction {signature}: {e!s}")
return False return False
async def post_rpc(self, body: dict[str, Any]) -> dict[str, Any] | None: async def post_rpc(self, body: dict[str, Any]) -> dict[str, Any] | None:
@@ -193,8 +193,8 @@ class SolanaClient:
response.raise_for_status() response.raise_for_status()
return await response.json() return await response.json()
except aiohttp.ClientError as e: except aiohttp.ClientError as e:
logger.error(f"RPC request failed: {str(e)}", exc_info=True) logger.error(f"RPC request failed: {e!s}", exc_info=True)
return None return None
except json.JSONDecodeError as e: except json.JSONDecodeError as e:
logger.error(f"Failed to decode RPC response: {str(e)}", exc_info=True) logger.error(f"Failed to decode RPC response: {e!s}", exc_info=True)
return None return None
+6 -6
View File
@@ -86,7 +86,7 @@ class BlockListener(BaseTokenListener):
ping_task.cancel() ping_task.cancel()
except Exception as e: except Exception as e:
logger.error(f"WebSocket connection error: {str(e)}") logger.error(f"WebSocket connection error: {e!s}")
logger.info("Reconnecting in 5 seconds...") logger.info("Reconnecting in 5 seconds...")
await asyncio.sleep(5) await asyncio.sleep(5)
@@ -105,7 +105,7 @@ class BlockListener(BaseTokenListener):
{"mentionsAccountOrProgram": str(self.pump_program)}, {"mentionsAccountOrProgram": str(self.pump_program)},
{ {
"commitment": "confirmed", "commitment": "confirmed",
"encoding": "base64", "encoding": "base64", # base64 is faster than other encoding options
"showRewards": False, "showRewards": False,
"transactionDetails": "full", "transactionDetails": "full",
"maxSupportedTransactionVersion": 0, "maxSupportedTransactionVersion": 0,
@@ -129,7 +129,7 @@ class BlockListener(BaseTokenListener):
try: try:
pong_waiter = await websocket.ping() pong_waiter = await websocket.ping()
await asyncio.wait_for(pong_waiter, timeout=10) await asyncio.wait_for(pong_waiter, timeout=10)
except asyncio.TimeoutError: except TimeoutError:
logger.warning("Ping timeout - server not responding") logger.warning("Ping timeout - server not responding")
# Force reconnection # Force reconnection
await websocket.close() await websocket.close()
@@ -137,7 +137,7 @@ class BlockListener(BaseTokenListener):
except asyncio.CancelledError: except asyncio.CancelledError:
pass pass
except Exception as e: except Exception as e:
logger.error(f"Ping error: {str(e)}") logger.error(f"Ping error: {e!s}")
async def _wait_for_token_creation(self, websocket) -> TokenInfo | None: async def _wait_for_token_creation(self, websocket) -> TokenInfo | None:
"""Wait for token creation event. """Wait for token creation event.
@@ -176,12 +176,12 @@ class BlockListener(BaseTokenListener):
if token_info: if token_info:
return token_info return token_info
except asyncio.TimeoutError: except TimeoutError:
logger.debug("No data received for 30 seconds") logger.debug("No data received for 30 seconds")
except websockets.exceptions.ConnectionClosed: except websockets.exceptions.ConnectionClosed:
logger.warning("WebSocket connection closed") logger.warning("WebSocket connection closed")
raise raise
except Exception as e: except Exception as e:
logger.error(f"Error processing WebSocket message: {str(e)}") logger.error(f"Error processing WebSocket message: {e!s}")
return None return None