diff --git a/modules/account.py b/modules/account.py index 90dd128..8996d72 100644 --- a/modules/account.py +++ b/modules/account.py @@ -56,23 +56,32 @@ async def get_amount( return amount_wei, amount, balance - async def wait_until_tx_finished(self, tx_hash: HexBytes, max_wait_time=180): + async def wait_until_tx_finished(self, hash, max_wait_time=180): start_time = time.time() while True: try: - receipts = await self.w3.eth.get_transaction_receipt(tx_hash) + receipts = await self.w3.eth.get_transaction_receipt(hash) status = receipts.get("status") if status == 1: - logger.success(f"[{self._id}][{self.address}] {self.explorer}{tx_hash.hex()} successfully!") + if not isinstance(hash, str): + hash = str(hash.hex()) + logger.success(f"[{self.account_id}][{self.address}] {self.explorer}{hash} successfully!") return True elif status is None: - await asyncio.sleep(1) + if time.time() - start_time > max_wait_time: + return False + await asyncio.sleep(0.3) else: - logger.error(f"[{self._id}][{self.address}] {self.explorer}{tx_hash.hex()} transaction failed!") + if not isinstance(hash, str): + hash = str(hash.hex()) + logger.error(f"[{self.account_id}][{self.address}] {self.explorer}{hash} transaction failed!") return False except TransactionNotFound: + if not isinstance(hash, str): + hash = str(hash.hex()) if time.time() - start_time > max_wait_time: - print(f'FAILED TX: {tx_hash.hex()}') + logger.error( + f"[{self.account_id}][{self.address}] {self.explorer}{hash} transaction not found -> failed!") return False await asyncio.sleep(1) diff --git a/utils/gas_checker.py b/utils/gas_checker.py index 4f58b18..5e80dcb 100644 --- a/utils/gas_checker.py +++ b/utils/gas_checker.py @@ -10,6 +10,7 @@ from loguru import logger from utils.sleeping import sleep +from utils.helpers import floor async def get_gas(): @@ -31,10 +32,10 @@ async def wait_gas_ethereum(): gas = await get_gas() if gas > MAX_GWEI: - logger.info(f'Current GWEI: {gas} > {MAX_GWEI}') + logger.info(f'Current GWEI: {floor(gas,2)} > {MAX_GWEI}') await sleep(60, 70) else: - logger.success(f"GWEI is normal | current: {gas} < {MAX_GWEI}") + logger.success(f"GWEI is normal | current: {floor(gas,2)} < {MAX_GWEI}") break @@ -48,10 +49,10 @@ async def wait_gas_starknet(): gas = Web3.from_wei(block_data.gas_price, "gwei") if gas > MAX_GWEI: - logger.info(f'Current GWEI: {gas} > {MAX_GWEI}') + logger.info(f'Current GWEI: {floor(gas,2)} > {MAX_GWEI}') await sleep(60, 70) else: - logger.success(f"GWEI is normal | current: {gas} < {MAX_GWEI}") + logger.success(f"GWEI is normal | current: {floor(gas,2)} < {MAX_GWEI}") break diff --git a/utils/helpers.py b/utils/helpers.py index ced1e9d..aa0003a 100644 --- a/utils/helpers.py +++ b/utils/helpers.py @@ -1,19 +1,27 @@ +import math + from loguru import logger from settings import RETRY_COUNT from utils.sleeping import sleep + def retry(func): async def wrapper(*args, **kwargs): retries = 0 - while retries < RETRY_COUNT: + while retries <= RETRY_COUNT: try: result = await func(*args, **kwargs) return result except Exception as e: - logger.error(f"Error | {e}") - await sleep(10, 60) + logger.error(f"Error | {e} | calling {func.__name__}") + await sleep(10, 20) retries += 1 return wrapper + +def floor(number, digits): + if number is None: + return None + return math.floor(float(number) * math.pow(10, digits)) / math.pow(10, digits) \ No newline at end of file