mirror of
https://github.com/vibe-existing/pyfragment.git
synced 2026-07-25 06:54:31 +00:00
refactor: enhance transaction logging for premium, stars, and TON topup methods
This commit is contained in:
@@ -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": {
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -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
@@ -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:
|
||||
|
||||
@@ -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']}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user