diff --git a/core/utils.py b/core/utils.py index c28a4db7..1c1b3f2d 100644 --- a/core/utils.py +++ b/core/utils.py @@ -3,6 +3,7 @@ import pytz from web3 import Web3 from web3.contract.contract import Contract, ContractFunction +from web3.logs import DISCARD, IGNORE, STRICT, WARN from web3.middleware import geth_poa_middleware from web3.types import TxParams, Type @@ -58,6 +59,11 @@ def get_first_day_of_last_month(): class Web3Utils: + LOG_STRICT = STRICT + LOG_IGNORE = IGNORE + LOG_DISCARD = DISCARD + LOG_WARN = WARN + def __init__(self, rpc_url, poa=False) -> None: self._rpc_url = rpc_url self._w3 = None diff --git a/prizetap/tasks.py b/prizetap/tasks.py index c7024ca1..f5397b2d 100644 --- a/prizetap/tasks.py +++ b/prizetap/tasks.py @@ -168,56 +168,60 @@ def set_raffle_ids(self): ) if raffles_queryset.count() > 0: for raffle in raffles_queryset: - print(f"Setting the raffle {raffle.name} raffleId") - contract_client = PrizetapContractClient(raffle) - - receipt = contract_client.get_transaction_receipt(raffle.tx_hash) - raffle_created_log = receipt["logs"][1] - log = contract_client.contract.events.RaffleCreated().process_log(raffle_created_log) - - raffle.raffleId = log["args"]["raffleId"] - onchain_raffle = contract_client.get_raffle() - is_valid = True - if onchain_raffle["status"] != 0: - is_valid = False - logging.error(f"Mismatch raffle {raffle.pk} status") - if onchain_raffle["lastParticipantIndex"] != 0: - is_valid = False - logging.error(f"Mismatch raffle {raffle.pk} lastParticipantIndex") - if onchain_raffle["lastWinnerIndex"] != 0: - is_valid = False - logging.error(f"Mismatch raffle {raffle.pk} lastWinnerIndex") - if onchain_raffle["participantsCount"] != 0: - is_valid = False - logging.error(f"Mismatch raffle {raffle.pk} participantsCount") - if raffle.creator_address != onchain_raffle["initiator"]: - is_valid = False - logging.error(f"Mismatch raffle {raffle.pk} initiator") - if raffle.max_number_of_entries != onchain_raffle["maxParticipants"]: - is_valid = False - logging.error(f"Mismatch raffle {raffle.pk} maxParticipants") - if raffle.max_multiplier != onchain_raffle["maxMultiplier"]: - is_valid = False - logging.error(f"Mismatch raffle {raffle.pk} maxMultiplier") - if int(raffle.start_at.timestamp()) != onchain_raffle["startTime"]: - is_valid = False - logging.error(f"Mismatch raffle {raffle.pk} startTime") - if int(raffle.deadline.timestamp()) != onchain_raffle["endTime"]: - is_valid = False - logging.error(f"Mismatch raffle {raffle.pk} endTime") - if raffle.winners_count != onchain_raffle["winnersCount"]: - is_valid = False - logging.error(f"Mismatch raffle {raffle.pk} winnersCount") - if raffle.is_prize_nft: - if raffle.prize_asset != onchain_raffle["collection"]: + try: + print(f"Setting the raffle {raffle.name} raffleId") + contract_client = PrizetapContractClient(raffle) + + receipt = contract_client.get_transaction_receipt(raffle.tx_hash) + log = contract_client.contract.events.RaffleCreated().process_receipt( + receipt, errors=contract_client.LOG_DISCARD + )[0] + + raffle.raffleId = log["args"]["raffleId"] + onchain_raffle = contract_client.get_raffle() + is_valid = True + if onchain_raffle["status"] != 0: is_valid = False - logging.error(f"Mismatch raffle {raffle.pk} collection") - else: - if raffle.prize_amount != onchain_raffle["prizeAmount"]: + logging.error(f"Mismatch raffle {raffle.pk} status") + if onchain_raffle["lastParticipantIndex"] != 0: is_valid = False - logging.error(f"Mismatch raffle {raffle.pk} prizeAmount") - if raffle.prize_asset != onchain_raffle["currency"]: + logging.error(f"Mismatch raffle {raffle.pk} lastParticipantIndex") + if onchain_raffle["lastWinnerIndex"] != 0: is_valid = False - logging.error(f"Mismatch raffle {raffle.pk} currency") - if is_valid: - raffle.save() + logging.error(f"Mismatch raffle {raffle.pk} lastWinnerIndex") + if onchain_raffle["participantsCount"] != 0: + is_valid = False + logging.error(f"Mismatch raffle {raffle.pk} participantsCount") + if raffle.creator_address != onchain_raffle["initiator"]: + is_valid = False + logging.error(f"Mismatch raffle {raffle.pk} initiator") + if raffle.max_number_of_entries != onchain_raffle["maxParticipants"]: + is_valid = False + logging.error(f"Mismatch raffle {raffle.pk} maxParticipants") + if raffle.max_multiplier != onchain_raffle["maxMultiplier"]: + is_valid = False + logging.error(f"Mismatch raffle {raffle.pk} maxMultiplier") + if int(raffle.start_at.timestamp()) != onchain_raffle["startTime"]: + is_valid = False + logging.error(f"Mismatch raffle {raffle.pk} startTime") + if int(raffle.deadline.timestamp()) != onchain_raffle["endTime"]: + is_valid = False + logging.error(f"Mismatch raffle {raffle.pk} endTime") + if raffle.winners_count != onchain_raffle["winnersCount"]: + is_valid = False + logging.error(f"Mismatch raffle {raffle.pk} winnersCount") + if raffle.is_prize_nft: + if raffle.prize_asset != onchain_raffle["collection"]: + is_valid = False + logging.error(f"Mismatch raffle {raffle.pk} collection") + else: + if raffle.prize_amount != onchain_raffle["prizeAmount"]: + is_valid = False + logging.error(f"Mismatch raffle {raffle.pk} prizeAmount") + if raffle.prize_asset != onchain_raffle["currency"]: + is_valid = False + logging.error(f"Mismatch raffle {raffle.pk} currency") + if is_valid: + raffle.save() + except Exception as e: + logging.error(e)