Skip to content

Commit

Permalink
remove manual start block setting
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlanglen committed May 6, 2024
1 parent 077090d commit c4afcf1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 21 deletions.
54 changes: 35 additions & 19 deletions indexer_app/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ async def handle_streamer_message(streamer_message: near_primitives.StreamerMess
"block_height", block_height
) # TODO: add custom timeout if it should be valid for longer than default (5 minutes)
formatted_date = convert_ns_to_utc(block_timestamp)
logger.info(f"Block Height: {block_height}, Block Timestamp: {block_timestamp} ({formatted_date})")
logger.info(
f"Block Height: {block_height}, Block Timestamp: {block_timestamp} ({formatted_date})"
)
# if block_height == 111867204:
# with open("indexer_outcome2.json", "w") as file:
# file.write(f"{streamer_message}")
Expand Down Expand Up @@ -108,11 +110,15 @@ async def handle_streamer_message(streamer_message: near_primitives.StreamerMess
args_dict = json.loads(decoded_text)
except UnicodeDecodeError:
# Handle case where the byte sequence cannot be decoded to UTF-8
logger.warning(f"Cannot decode args to UTF-8 text: {decoded_bytes}")
logger.warning(
f"Cannot decode args to UTF-8 text: {decoded_bytes}"
)
args_dict = {}
except json.JSONDecodeError:
# Handle case where the text cannot be parsed as JSON
logger.warning(f"Decoded text is not valid JSON: {decoded_text}")
logger.warning(
f"Decoded text is not valid JSON: {decoded_text}"
)
args_dict = {}

match method_name:
Expand All @@ -123,7 +129,9 @@ async def handle_streamer_message(streamer_message: near_primitives.StreamerMess
args_dict, receiver_id, created_at
)
else:
logger.info(f"new pot deployment: {args_dict}, {action}")
logger.info(
f"new pot deployment: {args_dict}, {action}"
)
await handle_new_pot(
args_dict,
receiver_id,
Expand All @@ -135,7 +143,9 @@ async def handle_streamer_message(streamer_message: near_primitives.StreamerMess
break

case "assert_can_apply_callback":
logger.info(f"application case: {args_dict}, {action}, {receipt}")
logger.info(
f"application case: {args_dict}, {action}, {receipt}"
)
await handle_pot_application(
args_dict,
receiver_id,
Expand All @@ -147,7 +157,9 @@ async def handle_streamer_message(streamer_message: near_primitives.StreamerMess
break

case "apply":
logger.info(f"application case 2: {args_dict}, {action}, {receipt}")
logger.info(
f"application case 2: {args_dict}, {action}, {receipt}"
)
await handle_pot_application(
args_dict,
receiver_id,
Expand All @@ -159,14 +171,12 @@ async def handle_streamer_message(streamer_message: near_primitives.StreamerMess
break

case "donate": # TODO: donate that produces result
logger.info(f"switching bazooka to knifee works!! donate his blood: {args_dict}, {receipt}, {action}, {log_data}")
logger.info(
f"switching bazooka to knifee works!! donate his blood: {args_dict}, {receipt}, {action}, {log_data}"
)
if len(log_data) > 1:
await handle_batch_donations(
receiver_id,
signer_id,
"direct",
receipt,
log_data
receiver_id, signer_id, "direct", receipt, log_data
)
else:
await handle_new_donations(
Expand All @@ -181,7 +191,9 @@ async def handle_streamer_message(streamer_message: near_primitives.StreamerMess
break

case "handle_protocol_fee_callback":
logger.info(f"donations to pool incoming: {args_dict}, {receipt}, {receipt_execution_outcome}")
logger.info(
f"donations to pool incoming: {args_dict}, {receipt}, {receipt_execution_outcome}"
)
await handle_new_donations(
args_dict,
receiver_id,
Expand All @@ -194,7 +206,9 @@ async def handle_streamer_message(streamer_message: near_primitives.StreamerMess
break

case "transfer_funds_callback":
logger.info(f"new version donations to pool incoming: {args_dict}, {action}")
logger.info(
f"new version donations to pool incoming: {args_dict}, {action}"
)
await handle_new_donations(
args_dict,
receiver_id,
Expand All @@ -209,7 +223,9 @@ async def handle_streamer_message(streamer_message: near_primitives.StreamerMess
case (
"register_batch"
): # TODO: listen for create_registration event instead of method call
logger.info(f"registrations incoming: {args_dict}, {action}")
logger.info(
f"registrations incoming: {args_dict}, {action}"
)
if receiver_id != "lists.potlock.near":
break
await handle_new_list_registration(
Expand All @@ -218,7 +234,9 @@ async def handle_streamer_message(streamer_message: near_primitives.StreamerMess
break

case "chef_set_application_status":
logger.info(f"application status change incoming: {args_dict}")
logger.info(
f"application status change incoming: {args_dict}"
)
await handle_pot_application_status_change(
args_dict, receiver_id, signer_id, receipt, status_obj
)
Expand Down Expand Up @@ -292,8 +310,6 @@ async def handle_streamer_message(streamer_message: near_primitives.StreamerMess
# TODO: handle remove upvote

except Exception as e:
logger.warning(
f"Error during parsing method call from JSON string to dict\n{e}"
)
logger.error(f"Error in indexer handler:\n{e}")
# with open("indexer_error.txt", "a") as file:
# file.write(f"{e}\n")
4 changes: 2 additions & 2 deletions indexer_app/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def listen_to_near_events():

try:
# Update below with desired network & block height
# start_block = get_block_height("current_block_height")
start_block = 105_112_120 # manually setting for reindexing TODO: remove this
start_block = get_block_height("current_block_height")
# start_block = 105_112_120 # manually setting for reindexing TODO: remove this
logger.info(f"what's the start block, pray tell? {start_block-1}")
loop.run_until_complete(indexer("mainnet", start_block - 1, None))
finally:
Expand Down

0 comments on commit c4afcf1

Please sign in to comment.