from api import Tronscan 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): 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: return -1, 0 token_transfers = result['token_transfers'] token_transfer = token_transfers[-1] confirmed = token_transfer['confirmed'] correct_quant = int(quant == (token_transfer['quant'] / 6)) return correct_quant, confirmed