Skip to content

Commit

Permalink
Merge pull request #234 from UnitapApp/refactor/tokentap-valid-chains
Browse files Browse the repository at this point in the history
Get valid chains
  • Loading branch information
ShayanShiravani authored Dec 23, 2023
2 parents 8c01ca8 + 98163b2 commit 2e06e5a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
5 changes: 5 additions & 0 deletions tokenTap/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CONTRACT_ADDRESSES = {
"100": "0xB67ec856346b22e4BDA2ab2B53d70D61a2014358",
"74": "0x3d1b1D14333D56472f7ADf044598d1605C67609f",
"10": "0x54a839FF128DC1891a03d7a81724bD5D51A5902b",
}
16 changes: 15 additions & 1 deletion tokenTap/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
from django.urls import path
from tokenTap.views import *

from tokenTap.views import (
GetTokenDistributionConstraintsView,
TokenDistributionClaimListView,
TokenDistributionClaimRetrieveView,
TokenDistributionClaimStatusUpdateView,
TokenDistributionClaimView,
TokenDistributionListView,
ValidChainsView,
)

urlpatterns = [
path(
Expand Down Expand Up @@ -28,4 +37,9 @@
GetTokenDistributionConstraintsView.as_view(),
name="get-token-distribution-constraints",
),
path(
"get-valid-chains/",
ValidChainsView.as_view(),
name="get-valid-chains",
),
]
24 changes: 23 additions & 1 deletion tokenTap/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from rest_framework.views import APIView

from core.constraints import ConstraintVerification, get_constraint
from core.models import NetworkTypes
from core.models import Chain, NetworkTypes
from core.serializers import ChainSerializer
from faucet.models import Chain as FaucetChain
from faucet.models import ClaimReceipt
from tokenTap.models import TokenDistribution, TokenDistributionClaim
Expand All @@ -25,6 +26,7 @@
TokenDistributionSerializer,
)

from .constants import CONTRACT_ADDRESSES
from .helpers import (
create_uint32_random_nonce,
has_weekly_credit_left,
Expand Down Expand Up @@ -253,3 +255,23 @@ def get_object(self):
return TokenDistributionClaim.objects.get(
pk=self.kwargs["pk"], user_profile=user_profile
)


class ValidChainsView(ListAPIView):
queryset = Chain.objects.filter(
chain_id__in=list(CONTRACT_ADDRESSES.keys())
).order_by("pk")
serializer_class = ChainSerializer

def get(self, request):
queryset = self.get_queryset()
serializer = ChainSerializer(queryset, many=True)
response = []
for chain in serializer.data:
response.append(
{
**chain,
"tokentap_contract_address": CONTRACT_ADDRESSES[chain["chain_id"]],
}
)
return Response({"success": True, "data": response})

0 comments on commit 2e06e5a

Please sign in to comment.