Skip to content

Commit

Permalink
attempt to resolve None error on new Donation
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlanglen committed Jun 24, 2024
1 parent 974ace3 commit d0fa8b0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
18 changes: 16 additions & 2 deletions indexer_app/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 3 additions & 4 deletions indexer_app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down

0 comments on commit d0fa8b0

Please sign in to comment.