Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions modules/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
9 changes: 5 additions & 4 deletions utils/gas_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from loguru import logger

from utils.sleeping import sleep
from utils.helpers import floor


async def get_gas():
Expand All @@ -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


Expand All @@ -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


Expand Down
14 changes: 11 additions & 3 deletions utils/helpers.py
Original file line number Diff line number Diff line change
@@ -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)