From d0fa8b00a994c934a50badf5c126438cc3dcaae8 Mon Sep 17 00:00:00 2001 From: Lachlan Glen <54282009+lachlanglen@users.noreply.github.com> Date: Mon, 24 Jun 2024 14:50:26 -0400 Subject: [PATCH] attempt to resolve None error on new Donation --- indexer_app/handler.py | 18 ++++++++++++++++-- indexer_app/utils.py | 7 +++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/indexer_app/handler.py b/indexer_app/handler.py index 48098e8..04ed609 100644 --- a/indexer_app/handler.py +++ b/indexer_app/handler.py @@ -220,14 +220,28 @@ async def handle_streamer_message(streamer_message: near_primitives.StreamerMess if not result: logger.info("No result found. Skipping...") break + decoded_success_val = base64.b64decode(result).decode( + "utf-8" + ) + logger.info(f"Decoded success value: {decoded_success_val}") + if ( + decoded_success_val == "null" + ): # weird edge case that sometimes occurs where the response is a literal string "null" + logger.info("Result is null. Skipping...") + try: + donation_data = json.loads(decoded_success_val) + except json.JSONDecodeError: + logger.error( + f"Error decoding result to JSON: {decoded_success_val}" + ) + donation_data = {} await handle_new_donation( args_dict, receiver_id, signer_id, donation_type, receipt, - result, - # log_data, + donation_data, ) break diff --git a/indexer_app/utils.py b/indexer_app/utils.py index f085bfb..02a0f4d 100644 --- a/indexer_app/utils.py +++ b/indexer_app/utils.py @@ -671,11 +671,10 @@ async def handle_new_donation( signer_id: str, donation_type: str, # "direct" or "pot" receipt_obj: Receipt, - result: dict, # Donation object (note that these vary between direct and pot donations - see examples of each in ./examples.txt) + donation_data: dict, # Donation object (note that these vary between direct and pot donations - see examples of each in ./examples.txt) ): - logger.info(f"handle_new_donation data: {data}, {receiver_id}") - donation_data = json.loads(base64.b64decode(result).decode("utf-8")) - logger.info(f"decoded result: {donation_data}") + logger.info(f"handle_new_donation args data: {data}, {receiver_id}") + logger.info(f"donation data: {donation_data}") if "net_amount" in donation_data: net_amount = int(donation_data["net_amount"])