This commit is contained in:
Dobromir Popov
2024-11-11 22:38:05 +02:00
parent efd7d8df5a
commit 5851af8f80
8 changed files with 115 additions and 199 deletions

View File

@ -1,6 +1,8 @@
# telegram_utils.py
import sys
import os
from base58 import b58decode
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import aiohttp
@ -65,7 +67,8 @@ class CSVFormatter(logging.Formatter):
record.wallet_address
])
return ''
class Log:
class Logging:
# Set up success logger for accounting CSV
def __init__(self):
@ -105,6 +108,26 @@ class Log:
})
def decode_instruction_data(data: str) -> dict:
try:
# Decode base58 data
decoded = b58decode(data)
# First byte usually represents instruction type
instruction_type = decoded[0] if decoded else None
# Rest of the data might contain amounts, token info etc
# Exact parsing depends on the program (Raydium, Orca, etc)
params = decoded[1:] if len(decoded) > 1 else None
return {
"instruction_type": instruction_type,
"params": params.hex() if params else None
}
except Exception as e:
return {"error": str(e)}
def safe_get_property(info, property_name, default='Unknown'):
if not isinstance(info, dict):
return str(default)
@ -154,7 +177,7 @@ async def async_safe_call(
# Create a global instance of TelegramUtils
telegram_utils = TelegramUtils()
log = Log().logger
log = Logging().logger
# You can add more Telegram-related methods to the TelegramUtils class if needed