-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrypto_service.py
More file actions
44 lines (36 loc) · 1.95 KB
/
crypto_service.py
File metadata and controls
44 lines (36 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import aiohttp
import logging
from config import USDT_CONTRACT_ADDRESS, USDT_WALLET_TRC20, TICKET_PRICE_USDT_CENTS
async def verify_transaction(txid: str) -> bool:
url = f"https://api.trongrid.io/v1/transactions/{txid}/events"
try:
async with aiohttp.ClientSession() as session:
async with session.get(url, timeout=10) as response:
if response.status != 200:
logging.error(f"TronGrid API error: HTTP {response.status}")
return False
data = await response.json()
if not data.get("success", False) or "data" not in data:
logging.error(f"TronGrid API returned missing or unsuccessful data: {data}")
return False
events = data["data"]
if not events:
return False
# Iterate through events for the hash
for event in events:
# Check if event is a continuous Token Transfer for the TRC20 smart contract
if event.get("contract_address") == USDT_CONTRACT_ADDRESS and event.get("event_name") == "Transfer":
result = event.get("result", {})
to_address = result.get("to")
value = result.get("value")
if to_address == USDT_WALLET_TRC20 and value is not None:
try:
value_int = int(value)
if value_int >= TICKET_PRICE_USDT_CENTS:
return True
except ValueError:
pass
return False
except Exception as e:
logging.error(f"Error checking transaction {txid}: {e}")
return False