Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/prizetap #241

Merged
merged 4 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading