From b30bfcd358c2e4ed82954b94af77cadb4047a284 Mon Sep 17 00:00:00 2001 From: Shayan Shiravani Date: Wed, 3 Jan 2024 10:02:09 +0330 Subject: [PATCH 1/4] More checks to set raffle random words --- prizetap/tasks.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/prizetap/tasks.py b/prizetap/tasks.py index 7ae14a2a..51edf486 100644 --- a/prizetap/tasks.py +++ b/prizetap/tasks.py @@ -25,6 +25,7 @@ def set_raffle_random_words(self): Raffle.objects.filter(deadline__lt=timezone.now()) .filter(status=Raffle.Status.VERIFIED) .filter(vrf_tx_hash__isnull=False) + .exclude(vrf_tx_hash__exact="") .first() ) @@ -33,8 +34,9 @@ def set_raffle_random_words(self): vrf_client = VRFClientContractClient(raffle.chain) last_request = vrf_client.get_last_request() expiration_time = last_request[0] + num_words = last_request[1] now = int(time.time()) - if now < expiration_time: + if now < expiration_time and num_words == raffle.winners_count: set_random_words(raffle) else: print("Random words have expired") From 1188215a8fcfcfb912b338575661aadcfdf5ffef Mon Sep 17 00:00:00 2001 From: Shayan Shiravani Date: Wed, 3 Jan 2024 10:03:30 +0330 Subject: [PATCH 2/4] Make vrf_tx_hash readonly in admin panel --- prizetap/admin.py | 1 + 1 file changed, 1 insertion(+) diff --git a/prizetap/admin.py b/prizetap/admin.py index 94a7ea38..33a77728 100644 --- a/prizetap/admin.py +++ b/prizetap/admin.py @@ -7,6 +7,7 @@ class RaffleAdmin(admin.ModelAdmin): list_display = ["pk", "name", "creator_name", "status"] + readonly_fields = ["vrf_tx_hash"] class RaffleŁEntryAdmin(admin.ModelAdmin): From 9417560b3032f0b6492a1d15282c974e2d9c4f78 Mon Sep 17 00:00:00 2001 From: Shayan Shiravani Date: Wed, 3 Jan 2024 10:21:13 +0330 Subject: [PATCH 3/4] Include is_reversed in the constraint itself --- prizetap/serializers.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/prizetap/serializers.py b/prizetap/serializers.py index 6fbb300d..31e90fdb 100644 --- a/prizetap/serializers.py +++ b/prizetap/serializers.py @@ -173,7 +173,7 @@ class RaffleSerializer(serializers.ModelSerializer): chain = ChainSerializer() winner_entries = WinnerEntrySerializer(many=True, read_only=True) user_entry = serializers.SerializerMethodField() - constraints = ConstraintSerializer(many=True, read_only=True) + constraints = serializers.SerializerMethodField() creator_profile = SimpleProfilerSerializer() class Meta: @@ -205,7 +205,6 @@ class Meta: "raffleId", "constraints", "constraint_params", - "reversed_constraints", "created_at", "start_at", "deadline", @@ -224,6 +223,17 @@ class Meta: "winners_count", ] + def get_constraints(self, raffle: Raffle): + return [ + { + **ConstraintSerializer(c).data, + "is_reversed": True + if c.pk in raffle.reversed_constraints.split(",") + else False, + } + for c in raffle.constraints.all() + ] + def get_user_entry(self, raffle: Raffle): try: return RaffleEntrySerializer( From 28c85d9555a9a3f01491b5a815e6f90b6d398337 Mon Sep 17 00:00:00 2001 From: Shayan Shiravani Date: Wed, 3 Jan 2024 10:44:22 +0330 Subject: [PATCH 4/4] Include is_reversed in the constraint itself --- prizetap/serializers.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/prizetap/serializers.py b/prizetap/serializers.py index 31e90fdb..4d510329 100644 --- a/prizetap/serializers.py +++ b/prizetap/serializers.py @@ -224,12 +224,15 @@ class Meta: ] def get_constraints(self, raffle: Raffle): + reversed_constraints = ( + raffle.reversed_constraints.split(",") + if raffle.reversed_constraints + else [] + ) return [ { **ConstraintSerializer(c).data, - "is_reversed": True - if c.pk in raffle.reversed_constraints.split(",") - else False, + "is_reversed": True if c.pk in reversed_constraints else False, } for c in raffle.constraints.all() ]