refactor: enhance transaction logging for premium, stars, and TON topup methods

This commit is contained in:
bohd4nx
2026-03-08 04:37:07 +02:00
parent 38a4619e42
commit c3de8a8ca3
6 changed files with 11 additions and 16 deletions
+3
View File
@@ -118,6 +118,9 @@ async def buy_premium(username: str, months: int) -> dict:
logger.info("Broadcasting transaction to TON blockchain")
tx_hash = await process_transaction(transaction)
logger.info(
"Premium purchase successful: %s months -> %s | tx: %s", months, username, tx_hash
)
return {
"success": True,
"data": {
+1
View File
@@ -107,6 +107,7 @@ async def buy_stars(username: str, amount: int) -> dict:
logger.info("Broadcasting transaction to TON blockchain")
tx_hash = await process_transaction(transaction)
logger.info("Stars purchase successful: %s stars -> %s | tx: %s", amount, username, tx_hash)
return {
"success": True,
"data": {
+1
View File
@@ -105,6 +105,7 @@ async def topup_ton(username: str, amount: int) -> dict:
logger.info("Broadcasting transaction to TON blockchain")
tx_hash = await process_transaction(transaction)
logger.info("TON topup successful: %s TON -> %s | tx: %s", amount, username, tx_hash)
return {
"success": True,
"data": {
+1 -3
View File
@@ -19,8 +19,6 @@ logger = logging.getLogger(__name__)
def clean_decode(payload: str) -> str:
logger.debug("Original payload: %s", payload)
# Pad and decode base64 → BOC bytes
s = payload.strip()
if not s:
@@ -34,5 +32,5 @@ def clean_decode(payload: str) -> str:
sl.load_uint(32) # op code — always 0 for text comment
result = sl.load_snake_string().strip()
logger.debug("Decoded payload: %s", result.replace("\n", " "))
logger.debug("Payload: %s -> %s", payload, result.replace("\n", " "))
return result
+2 -2
View File
@@ -56,8 +56,8 @@ async def process_transaction(transaction_data: dict) -> str:
amount=int(message["amount"]), # nanotons, not TON
body=payload,
)
return result
tx_hash = result.normalized_hash
return tx_hash
except (WalletError, TransactionError):
raise
except Exception as exc:
+3 -11
View File
@@ -14,9 +14,7 @@ async def topup_ton_example():
result = await topup_ton("@bohd4nx", 100)
if result["success"]:
data = result["data"]
logger.info(f"TON topup successful: {data['amount']} TON sent to {data['username']}")
logger.info(f"Transaction ID: {data['transaction_id']}")
pass # Transaction successful, details are logged in the method
else:
logger.error(f"TON topup failed: {result['error']}")
@@ -28,11 +26,7 @@ async def buy_premium_example():
result = await buy_premium("@bohd4nx", 12)
if result["success"]:
data = result["data"]
logger.info(
f"Premium purchase successful: {data['months']} months sent to {data['username']}"
)
logger.info(f"Transaction ID: {data['transaction_id']}")
pass # Transaction successful, details are logged in the method
else:
logger.error(f"Premium purchase failed: {result['error']}")
@@ -44,9 +38,7 @@ async def buy_stars_example():
result = await buy_stars("@bohd4nx", 1000000)
if result["success"]:
data = result["data"]
logger.info(f"Stars purchase successful: {data['amount']} stars sent to {data['username']}")
logger.info(f"Transaction ID: {data['transaction_id']}")
pass # Transaction successful, details are logged in the method
else:
logger.error(f"Stars purchase failed: {result['error']}")