31 lines
1.3 KiB
Python
31 lines
1.3 KiB
Python
from api import Tronscan
|
|
from loguru import logger
|
|
|
|
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):
|
|
# # 删除测试代码
|
|
# return 1, 1
|
|
if end_timestamp is None:
|
|
end_timestamp = current_timestamp()
|
|
logger.debug(f'检查从{from_address}到{to_address}的转账交易信息')
|
|
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:
|
|
logger.debug('No payments found')
|
|
return 0, 0
|
|
token_transfers = result['token_transfers']
|
|
token_transfer = token_transfers[-1]
|
|
confirmed = token_transfer['confirmed']
|
|
correct_quant = int(quant == (token_transfer['quant'] / 6))
|
|
logger.debug(f'correct_quant: {correct_quant} confirmed: {confirmed}')
|
|
return correct_quant, confirmed
|