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

Get valid chains #234

Merged
merged 1 commit into from
Dec 23, 2023
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
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})