2024-11-13 08:13:06 +00:00
|
|
|
from api import Tronscan
|
2024-11-21 09:34:38 +00:00
|
|
|
from loguru import logger
|
|
|
|
|
2024-11-13 08:13:06 +00:00
|
|
|
from custom_decorators import singleton
|
|
|
|
from utils.datetime import current_timestamp
|
|
|
|
|
|
|
|
|
|
|
|
@singleton
|
|
|
|
class PaymentService:
|
|
|
|
def __init__(self, api_key):
|
|
|
|
self.tronscan = Tronscan(api_key)
|
|
|
|
|
|
|
|
def check_payment(self, quant, from_address, to_address, order_create_timestamp, end_timestamp=None):
|
2024-11-20 17:09:07 +00:00
|
|
|
# # 删除测试代码
|
|
|
|
# return 1, 1
|
2024-11-13 08:13:06 +00:00
|
|
|
if end_timestamp is None:
|
|
|
|
end_timestamp = current_timestamp()
|
|
|
|
result = self.tronscan.token_trc20_transfers(limit=100,
|
|
|
|
from_address=from_address, to_address=to_address,
|
|
|
|
start_timestamp=order_create_timestamp, end_timestamp=end_timestamp)
|
|
|
|
if result['rangeTotal'] == 0:
|
2024-11-21 09:34:38 +00:00
|
|
|
logger.debug('No payments found')
|
2024-11-13 09:44:45 +00:00
|
|
|
return 0, 0
|
2024-11-13 08:13:06 +00:00
|
|
|
token_transfers = result['token_transfers']
|
|
|
|
token_transfer = token_transfers[-1]
|
|
|
|
confirmed = token_transfer['confirmed']
|
|
|
|
correct_quant = int(quant == (token_transfer['quant'] / 6))
|
2024-11-21 09:34:38 +00:00
|
|
|
logger.debug(f'correct_quant: {correct_quant} confirmed: {confirmed}')
|
2024-11-13 08:13:06 +00:00
|
|
|
return correct_quant, confirmed
|