Skip to content

Commit

Permalink
fix update list
Browse files Browse the repository at this point in the history
  • Loading branch information
Prometheo committed Oct 10, 2024
1 parent 8856e60 commit 16ae0a3
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
14 changes: 14 additions & 0 deletions indexer_app/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
handle_list_owner_change,
handle_list_registration_removal,
handle_list_registration_update,
handle_list_update,
handle_list_upvote,
handle_new_donation,
handle_new_group,
Expand Down Expand Up @@ -153,6 +154,12 @@ async def handle_streamer_message(streamer_message: near_primitives.StreamerMess
await handle_list_admin_ops(
parsed_log.get("data")[0], receiver_id, signer_id, receipt.receipt_id
)
if event_name == "update_lis":
if receiver_id != LISTS_CONTRACT:
continue
await handle_list_update(
parsed_log.get("data")[0], receiver_id, signer_id, receipt.receipt_id
)
except json.JSONDecodeError:
logger.warning(
f"Receipt ID: `{receipt_execution_outcome.receipt.receipt_id}`\nError during parsing logs from JSON string to dict"
Expand Down Expand Up @@ -435,6 +442,13 @@ async def handle_streamer_message(streamer_message: near_primitives.StreamerMess
await handle_new_list(signer_id, receiver_id, status_obj, None)
break

case "update_list":
logger.info(f"updating list... {args_dict}, {action}")
if receiver_id != LISTS_CONTRACT:
break
await handle_list_update(signer_id, receiver_id, status_obj, None)
break

case "upvote":
logger.info(f"up voting... {args_dict}")
if receiver_id != LISTS_CONTRACT:
Expand Down
39 changes: 38 additions & 1 deletion indexer_app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,43 @@ async def handle_new_list(
logger.error(f"Failed to handle new list, Error: {e}")



async def handle_list_update(
signer_id: str, receiver_id: str, status_obj: ExecutionOutcome | None, data: dict | None
):
try:

if not data:
data = json.loads(
base64.b64decode(status_obj.status.get("SuccessValue")).decode(
"utf-8"
) # TODO: RECEIVE AS A FUNCTION ARGUMENT
)


logger.info(f"updating list..... {data}")

listObject = await List.objects.filter(on_chain_id=data["id"]).aupdate(
owner_id=data["owner"],
default_registration_status=data["default_registration_status"],
name=data["name"],
description=data["description"],
cover_image_url=data["cover_image_url"],
admin_only_registrations=data["admin_only_registrations"],
created_at=datetime.fromtimestamp(data["created_at"] / 1000),
updated_at=datetime.fromtimestamp(data["updated_at"] / 1000),
)

# if data.get("admins"):
# for admin_id in data["admins"]:
# admin_object, _ = await Account.objects.aget_or_create(defaults={"chain_id":1},
# id=admin_id,
# )
# await listObject.admins.aadd(admin_object)
except Exception as e:
logger.error(f"Failed to handle list update, Error: {e}")


async def handle_delete_list(
data: dict
):
Expand Down Expand Up @@ -848,7 +885,7 @@ async def handle_list_admin_ops(data, receiver_id, signer_id, receiptId):
try:

logger.info(f"updating admin...: {data}, {receiver_id}")
list_obj = await List.objects.aget(id=data["list_id"])
list_obj = await List.objects.aget(on_chain_id=data["list_id"])

for acct in data["admins"]:
acct_obj = await Account.objects.aget(id=acct)
Expand Down

0 comments on commit 16ae0a3

Please sign in to comment.