Skip to content

Commit

Permalink
handle None pot application & update start block
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlanglen committed May 23, 2024
1 parent c827597 commit ba8c3e9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion indexer_app/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ async def handle_streamer_message(streamer_message: near_primitives.StreamerMess
created_at,
)
break

# TODO: update to use handle_apply method??
case "assert_can_apply_callback":
logger.info(
f"application case: {args_dict}, {action}, {receipt}"
Expand Down
2 changes: 1 addition & 1 deletion indexer_app/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def listen_to_near_events():
try:
# Update below with desired network & block height
# start_block = get_block_height("current_block_height")
start_block = 114056625
start_block = 112952680
logger.info(f"what's the start block, pray tell? {start_block-1}")
loop.run_until_complete(indexer("mainnet", start_block - 1, None))
except WorkerLostError:
Expand Down
32 changes: 19 additions & 13 deletions indexer_app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,13 @@ async def handle_pot_application_status_change(
# Retrieve the PotApplication object
appl = await PotApplication.objects.filter(
applicant_id=data["project_id"]
).afirst() # TODO: handle this being None
).afirst()

if not appl:
logger.error(
f"PotApplication object not found for project_id: {data['project_id']}"
)
return

# Create the PotApplicationReview object
logger.info(f"create review...... {appl}")
Expand All @@ -411,7 +417,7 @@ async def handle_pot_application_status_change(

logger.info("PotApplicationReview and PotApplication updated successfully.")
except Exception as e:
logger.warning(f"Failed to change pot application status, Error: {e}")
logger.error(f"Failed to change pot application status, Error: {e}")


async def handle_default_list_status_change(
Expand Down Expand Up @@ -442,7 +448,7 @@ async def handle_default_list_status_change(

logger.info("List updated successfully.")
except Exception as e:
logger.warning(f"Failed to change list status, Error: {e}")
logger.error(f"Failed to change list status, Error: {e}")


async def handle_list_upvote(
Expand Down Expand Up @@ -478,7 +484,7 @@ async def handle_list_upvote(
f"Upvote and activity records created successfully. {activity_created}"
)
except Exception as e:
logger.warning(f"Failed to upvote list, Error: {e}")
logger.error(f"Failed to upvote list, Error: {e}")


async def handle_set_payouts(data: dict, receiverId: str, receipt: Receipt):
Expand All @@ -500,7 +506,7 @@ async def handle_set_payouts(data: dict, receiverId: str, receipt: Receipt):

await PotPayout.objects.abulk_create(insertion_data, ignore_conflicts=True)
except Exception as e:
logger.warning(f"Failed to set payouts, Error: {e}")
logger.error(f"Failed to set payouts, Error: {e}")


async def handle_transfer_payout(
Expand All @@ -520,7 +526,7 @@ async def handle_transfer_payout(
**payout
)
except Exception as e:
logger.warning(f"Failed to create payout data, Error: {e}")
logger.error(f"Failed to create payout data, Error: {e}")


async def handle_payout_challenge(
Expand Down Expand Up @@ -549,7 +555,7 @@ async def handle_payout_challenge(
action_result=payoutChallenge, type="Challenge_Payout", defaults=defaults
)
except Exception as e:
logger.warning(f"Failed to create payoutchallenge, Error: {e}")
logger.error(f"Failed to create payoutchallenge, Error: {e}")


async def handle_payout_challenge_response(
Expand Down Expand Up @@ -593,7 +599,7 @@ async def handle_list_admin_removal(data, receiverId, signerId, receiptId):
type="Remove_List_Admin", defaults=activity
)
except Exception as e:
logger.warning(f"Failed to remove list admin, Error: {e}")
logger.error(f"Failed to remove list admin, Error: {e}")


# TODO: Need to abstract some actions.
Expand Down Expand Up @@ -685,7 +691,7 @@ async def handle_new_donations(
id=(donation_data.get("ft_id") or "near")
)
except Exception as e:
logger.warning(f"Failed to create/get an account involved in donation: {e}")
logger.error(f"Failed to create/get an account involved in donation: {e}")

# # Upsert token
# try:
Expand All @@ -704,10 +710,10 @@ async def handle_new_donations(
# response = requests.get(endpoint)
# logger.info(f"response: {response}")
# if response.status_code == 429:
# logger.warning("Coingecko rate limit exceeded")
# logger.error("Coingecko rate limit exceeded")
# price_data = response.json()
# except Exception as e:
# logger.warning(f"Failed to fetch price data: {e}")
# logger.error(f"Failed to fetch price data: {e}")
# logger.info(f"price data: {price_data}")
# unit_price = price_data.get("market_data", {}).get("current_price", {}).get("usd")
# logger.info(f"unit price: {unit_price}")
Expand All @@ -719,7 +725,7 @@ async def handle_new_donations(
# timestamp=donated_at,
# )
# except Exception as e:
# logger.warning(
# logger.error(
# f"Error creating TokenHistoricalPrice: {e} token: {token} unit_price: {unit_price}"
# )
# # historical_price = await token.get_most_recent_price() # to use model methods, we might have to use asgiref sync_to_async
Expand Down Expand Up @@ -806,7 +812,7 @@ async def handle_new_donations(
except Exception as e:
logger.info(f"Failed to create Activity: {e}")
except Exception as e:
logger.warning(f"Failed to create/update donation: {e}")
logger.error(f"Failed to create/update donation: {e}")

### COMMENTING OUT FOR NOW SINCE WE HAVE PERIODIC JOB RUNNING TO UPDATE ACCOUNT STATS (NB: DOESN'T CURRENTLY COVER POT STATS)
### CAN ALWAYS ADD BACK IF DESIRED
Expand Down

0 comments on commit ba8c3e9

Please sign in to comment.