Skip to content

Commit

Permalink
add specific exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
godekina committed Oct 31, 2024
1 parent 3ec7fb2 commit 5632dcc
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions web_app/tasks/claim_airdrops.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import asyncio
import logging
from requests.exceptions import ConnectionError, Timeout
from sqlalchemy.exc import SQLAlchemyError
from typing import List

from web_app.contract_tools.airdrop import ZkLendAirdrop
Expand Down Expand Up @@ -45,23 +47,41 @@ async def claim_airdrops(self) -> None:
if claim_succesful:
self.db_connector.save_claim_data(airdrop.id, airdrop.amount)
logger.info("Airdrop %s claimed succesfully.", airdrop.id)
except ValueError as ve:
logger.error("Invalid data for airdrop %s: %s", airdrop.id, ve)
except SQLAlchemyError as db_err:
logger.error("Database error while updating claim data for airdrop %s: %s", airdrop.id, db_err)
except ConnectionError as ce:
logger.error("Network connection error during claim for airdrop %s: %s", airdrop.id, ce)
except Timeout as te:
logger.error("Timeout during claim for airdrop %s: %s", airdrop.id, te)
except Exception as e:
logger.error("Error claiming airdrop %s: %s", airdrop.id, e)
logger.error("Unexpected error claiming airdrop %s: %s", airdrop.id, e)


async def _claim_airdrop(self, contract_address: str, proof: List[int]) -> bool:
async def _claim_airdrop(self, contract_address: str, proof: List[str]) -> bool:
"""
Claims a single airdrop by making a contract call on the Starknet blockchain.
"""
calldata = [100] + proof
calldata = [] + proof
try:
await self.starknet_client._func_call(
addr=self.starknet_client._convert_address(contract_address),
selector="claim",
calldata=calldata,
)
return True
except ConnectionError as ce:
logger.error("Network connection failed for address %s: %s", contract_address, ce)
return False
except Timeout as te:
logger.error("Timeout during claim for address %s: %s", contract_address, te)
return False
except ValueError as ve:
logger.error("Invalid data format for calldata during claim for address %s: %s", contract_address, ve)
return False
except Exception as e:
logger.error("Claim failed for address %s: %s", contract_address, e)
logger.error("Unexpected error claiming address %s: %s", contract_address, e)
return False


Expand Down

0 comments on commit 5632dcc

Please sign in to comment.