Skip to content

Commit

Permalink
use onchain id for lists route
Browse files Browse the repository at this point in the history
  • Loading branch information
Prometheo committed Oct 8, 2024
1 parent 5e3f19a commit f01709e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
11 changes: 9 additions & 2 deletions indexer_app/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
handle_default_list_status_change,
handle_delete_list,
handle_list_admin_removal,
handle_list_owner_change,
handle_list_registration_update,
handle_list_upvote,
handle_new_donation,
Expand Down Expand Up @@ -96,6 +97,7 @@ async def handle_streamer_message(streamer_message: near_primitives.StreamerMess
log_data = []
receipt = receipt_execution_outcome.receipt
signer_id = receipt.receipt["Action"]["signer_id"]
LISTS_CONTRACT = "lists." + settings.POTLOCK_TLA

log_processing_start = time.time()
for log_index, log in enumerate(
Expand Down Expand Up @@ -138,6 +140,12 @@ async def handle_streamer_message(streamer_message: near_primitives.StreamerMess
await handle_delete_list(
parsed_log.get("data")[0]
)
if event_name == "owner_transfer":
if receiver_id != LISTS_CONTRACT:
continue
await handle_list_owner_change(
parsed_log.get("data")[0]
)
except json.JSONDecodeError:
logger.warning(
f"Receipt ID: `{receipt_execution_outcome.receipt.receipt_id}`\nError during parsing logs from JSON string to dict"
Expand All @@ -164,8 +172,7 @@ async def handle_streamer_message(streamer_message: near_primitives.StreamerMess
# # consider logging failures to logging service; for now, just skip
# print("here we are...")
# continue
method_call_processing_start = time.time()
LISTS_CONTRACT = "lists." + settings.POTLOCK_TLA
# method_call_processing_start = time.time()
DONATE_CONTRACT = "donate." + settings.POTLOCK_TLA

for index, action in enumerate(
Expand Down
10 changes: 10 additions & 0 deletions indexer_app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,16 @@ async def handle_list_admin_removal(data, receiver_id, signer_id, receiptId):
logger.error(f"Failed to remove list admin, Error: {e}")


async def handle_list_owner_change(data):
try:
logger.info(f"changing owner... ...: {data}")
await List.objects.filter(id=data["list_id"]).aupdate(**{
"owner": data["new_owner_id"]
})

except Exception as e:
logger.error(f"Failed to change list owner, Error: {e}")

async def handle_add_nadabot_admin(data, receiverId):
logger.info(f"adding admin...: {data}, {receiverId}")
try:
Expand Down
12 changes: 6 additions & 6 deletions lists/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ class ListDetailAPI(APIView):
def get(self, request: Request, *args, **kwargs):
list_id = kwargs.get("list_id")
try:
list_obj = List.objects.get(id=list_id)
list_obj = List.objects.get(on_chain_id=list_id)
except List.DoesNotExist:
return Response(
{"message": f"List with ID {list_id} not found."}, status=404
{"message": f"List with onchain ID {list_id} not found."}, status=404
)
serializer = ListSerializer(list_obj)
return Response(serializer.data)
Expand Down Expand Up @@ -156,10 +156,10 @@ class ListRegistrationsAPI(APIView, CustomSizePageNumberPagination):
def get(self, request: Request, *args, **kwargs):
list_id = kwargs.get("list_id")
try:
list_obj = List.objects.prefetch_related('registrations').get(id=list_id)
list_obj = List.objects.prefetch_related('registrations').get(on_chain_id=list_id)
except List.DoesNotExist:
return Response(
{"message": f"List with ID {list_id} not found."}, status=404
{"message": f"List with on chain ID {list_id} not found."}, status=404
)

registrations = list_obj.registrations.select_related().all()
Expand Down Expand Up @@ -214,10 +214,10 @@ class ListRandomRegistrationAPI(APIView):
def get(self, request: Request, *args, **kwargs):
list_id = kwargs.get("list_id")
try:
list_obj = List.objects.get(id=list_id)
list_obj = List.objects.get(on_chain_id=list_id)
except List.DoesNotExist:
return Response(
{"message": f"List with ID {list_id} not found."}, status=404
{"message": f"List on chain ID {list_id} not found."}, status=404
)

registrations = list_obj.registrations.all()
Expand Down

0 comments on commit f01709e

Please sign in to comment.