Skip to content

Commit

Permalink
Merge pull request #241 from UnitapApp/fix/prizetap
Browse files Browse the repository at this point in the history
Fix/prizetap
  • Loading branch information
ShayanShiravani authored Jan 3, 2024
2 parents 7aa64b2 + 28c85d9 commit 33b87d5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions prizetap/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
17 changes: 15 additions & 2 deletions prizetap/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -205,7 +205,6 @@ class Meta:
"raffleId",
"constraints",
"constraint_params",
"reversed_constraints",
"created_at",
"start_at",
"deadline",
Expand All @@ -224,6 +223,20 @@ class Meta:
"winners_count",
]

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 reversed_constraints else False,
}
for c in raffle.constraints.all()
]

def get_user_entry(self, raffle: Raffle):
try:
return RaffleEntrySerializer(
Expand Down
4 changes: 3 additions & 1 deletion prizetap/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)

Expand All @@ -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")
Expand Down

0 comments on commit 33b87d5

Please sign in to comment.