Skip to content

Commit

Permalink
feat(api): returning all stake events relevant to an address (#462)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucianHymer authored Nov 13, 2023
1 parent 2d44885 commit 005b52f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
3 changes: 2 additions & 1 deletion api/registry/api/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,8 @@ def stamp_display(request) -> List[StampDisplayResponse]:

@router.get(
"/gtc-stake/{str:address}/{int:round_id}",
auth=ApiKey(),
# auth=ApiKey(),
auth=None,
response=GtcEventsResponse,
summary="Retrieve GTC stake amounts for the GTC Staking stamp",
description="Get self and community staking amounts based on address and round ID",
Expand Down
26 changes: 4 additions & 22 deletions api/registry/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,11 @@ class Meta:
def filter_address(self, queryset, name, value):
round_id_value = int(self.form.cleaned_data.get("round_id", ""))

beginner_experienced_community_staker = Q(
round_id=round_id_value,
event_type="Xstake",
staker=value,
amount__gte=5,
) | Q(address=value)

trusted_citizen_staker = Q(
round_id=round_id_value,
event_type="Xstake",
address=value,
amount__gte=20,
)

self_stake = Q(
round_id=round_id_value,
event_type="SelfStake",
staker=value,
amount__gte=5,
)

results = queryset.filter(
beginner_experienced_community_staker | trusted_citizen_staker | self_stake
Q(
round_id=round_id_value,
)
& (Q(staker=value) | Q(address=value))
)

return results
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.6 on 2023-11-13 21:48

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("registry", "0027_alter_gtcstakeevent_amount"),
]

operations = [
migrations.AddIndex(
model_name="gtcstakeevent",
index=models.Index(
fields=["round_id", "staker"], name="gtc_staking_index_by_staker"
),
),
]
4 changes: 4 additions & 0 deletions api/registry/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,8 @@ class Meta:
fields=["round_id", "address", "staker"],
name="gtc_staking_index",
),
models.Index(
fields=["round_id", "staker"],
name="gtc_staking_index_by_staker",
),
]

0 comments on commit 005b52f

Please sign in to comment.