diff --git a/prizetap/validators.py b/prizetap/validators.py index 7b9c998f..e2883086 100644 --- a/prizetap/validators.py +++ b/prizetap/validators.py @@ -4,18 +4,18 @@ from authentication.models import UserProfile from .models import RaffleEntry, Raffle from .constraints import * +from faucet.constraints import OptimismClaimingGasConstraint + class RaffleEnrollmentValidator: def __init__(self, *args, **kwargs): - self.user_profile: UserProfile = kwargs['user_profile'] - self.raffle: Raffle = kwargs['raffle'] + self.user_profile: UserProfile = kwargs["user_profile"] + self.raffle: Raffle = kwargs["raffle"] def can_enroll_in_raffle(self): if not self.raffle.is_claimable: - raise PermissionDenied( - "Can't enroll in this raffle" - ) - + raise PermissionDenied("Can't enroll in this raffle") + def check_user_constraints(self): try: param_values = json.loads(self.raffle.constraint_params) @@ -29,13 +29,12 @@ def check_user_constraints(self): except KeyError: pass if not constraint.is_observed(): - raise PermissionDenied( - constraint.response - ) + raise PermissionDenied(constraint.response) def check_user_has_wallet(self): if not self.user_profile.wallets.filter( - wallet_type=self.raffle.chain.chain_type).exists(): + wallet_type=self.raffle.chain.chain_type + ).exists(): raise PermissionDenied( f"You have not connected an {self.raffle.chain.chain_type} wallet to your account" ) @@ -47,23 +46,21 @@ def is_valid(self, data): self.check_user_has_wallet() + class SetRaffleEntryTxValidator: - def __init__(self, *args, **kwargs): - self.user_profile: UserProfile = kwargs['user_profile'] - self.raffle_entry: RaffleEntry = kwargs['raffle_entry'] + self.user_profile: UserProfile = kwargs["user_profile"] + self.raffle_entry: RaffleEntry = kwargs["raffle_entry"] def is_owner_of_raffle_entry(self): if not self.raffle_entry.user_profile == self.user_profile: raise PermissionDenied( "You don't have permission to update this raffle entry" ) - + def is_tx_empty(self): if self.raffle_entry.tx_hash: - raise PermissionDenied( - "This raffle entry is already updated" - ) + raise PermissionDenied("This raffle entry is already updated") def is_valid(self, data): self.is_owner_of_raffle_entry() @@ -71,26 +68,20 @@ def is_valid(self, data): tx_hash = data.get("tx_hash", None) if not tx_hash or len(tx_hash) != 66: - raise PermissionDenied( - "Tx hash is not valid" - ) + raise PermissionDenied("Tx hash is not valid") + class SetClaimingPrizeTxValidator: - def __init__(self, *args, **kwargs): - self.raffle_entry: RaffleEntry = kwargs['raffle_entry'] - + self.raffle_entry: RaffleEntry = kwargs["raffle_entry"] + def is_winner(self): if not self.raffle_entry.is_winner: - raise PermissionDenied( - "You are not the raffle winner" - ) - + raise PermissionDenied("You are not the raffle winner") + def is_tx_empty(self): if self.raffle_entry.claiming_prize_tx: - raise PermissionDenied( - "The tx_hash is already set" - ) + raise PermissionDenied("The tx_hash is already set") def is_valid(self, data): self.is_winner() @@ -98,27 +89,21 @@ def is_valid(self, data): tx_hash = data.get("tx_hash", None) if not tx_hash or len(tx_hash) != 66: - raise PermissionDenied( - "Tx hash is not valid" - ) + raise PermissionDenied("Tx hash is not valid") + class SetRaffleTxValidator: - def __init__(self, *args, **kwargs): - self.user_profile: UserProfile = kwargs['user_profile'] - self.raffle: Raffle = kwargs['raffle'] + self.user_profile: UserProfile = kwargs["user_profile"] + self.raffle: Raffle = kwargs["raffle"] def is_owner_of_raffle(self): if not self.raffle.creator_profile == self.user_profile: - raise PermissionDenied( - "You don't have permission to update this raffle" - ) - + raise PermissionDenied("You don't have permission to update this raffle") + def is_tx_empty(self): if self.raffle.tx_hash: - raise PermissionDenied( - "This raffle is already updated" - ) + raise PermissionDenied("This raffle is already updated") def is_valid(self, data): self.is_owner_of_raffle() @@ -126,6 +111,4 @@ def is_valid(self, data): tx_hash = data.get("tx_hash", None) if not tx_hash or len(tx_hash) != 66: - raise PermissionDenied( - "Tx hash is not valid" - ) \ No newline at end of file + raise PermissionDenied("Tx hash is not valid")