Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

Commit

Permalink
Fix logging for axie utils cli
Browse files Browse the repository at this point in the history
  • Loading branch information
FerranMarin committed Apr 30, 2022
1 parent e993b6f commit c7588eb
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 102 deletions.
18 changes: 9 additions & 9 deletions axie-utils/axie_utils/breeding.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ def execute(self):
logging.info("Could not find TX, giving it a bit more time.")
sleep(20)
else:
logging.warning("Error occurred trying to find recepit for transaction '{self}'.\n"
"Error given: {err}.")
logging.warning(f"Important: Error occurred trying to find recepit for transaction '{self}'.\n"
f"Error given: {err}.")
return

if success:
logging.info(f"{self} completed successfully")
logging.info(f"Important: {self} completed successfully")
return _hash
else:
logging.info(f"{self} failed")
logging.info(f"Important: {self} failed")

def __str__(self):
return (f"Breeding axie {self.sire_axie} with {self.matron_axie} in account "
Expand Down Expand Up @@ -149,7 +149,7 @@ def execute(self):
# get transaction _hash
_hash = self.w3.toHex(self.w3.keccak(transaction))
# Wait for transaction to finish or timeout
logging.info("{self} about to start!")
logging.info(f"{self} about to start!")
start_time = datetime.now()
while True:
# We will wait for max 10minutes for this tx to respond
Expand All @@ -173,15 +173,15 @@ def execute(self):
logging.info("Could not find TX, giving it a bit more time.")
sleep(20)
else:
logging.warning("Error occurred trying to find recepit for transaction '{self}'.\n"
"Error given: {err}.")
logging.warning(f"Important: Error occurred trying to find recepit for transaction '{self}'.\n"
f"Error given: {err}.")
return

if success:
logging.info(f"{self} completed successfully")
logging.info(f"Important: {self} completed successfully")
return _hash
else:
logging.info(f"{self} failed")
logging.info(f"Important: {self} failed")
return

def __str__(self):
Expand Down
74 changes: 37 additions & 37 deletions axie-utils/axie_utils/claims.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def has_unclaimed_slp(self):
try:
response = self.request.get(url, headers={"User-Agent": self.user_agent})
except RetryError:
logging.critical(f"Failed to check if there is unclaimed SLP for acc {self.acc_name} "
logging.critical(f"Important: Failed to check if there is unclaimed SLP for acc {self.acc_name} "
f"({self.account.replace('0x','ronin:')})")
return None
if 200 <= response.status_code <= 299:
Expand All @@ -56,7 +56,7 @@ def has_unclaimed_slp(self):
next_claim_date = last_claimed + timedelta(days=14)
utcnow = datetime.utcnow()
if utcnow < next_claim_date and not self.force:
logging.critical(f"This account will be claimable again on {self.humanize_date(next_claim_date)}.")
logging.critical(f"Important: This account will be claimable again on {self.humanize_date(next_claim_date)}.")
return None
elif self.force:
logging.info('Skipping check of dates, --force option was selected')
Expand All @@ -76,7 +76,7 @@ async def async_execute(self):
f"{unclaimed} unclaimed SLP")
jwt = self.get_jwt()
if not jwt:
logging.critical("Skipping claiming, we could not get the JWT for account "
logging.critical("Important: Skipping claiming, we could not get the JWT for account "
f"{self.account.replace('0x', 'ronin:')}")
return
headers = {
Expand All @@ -87,17 +87,17 @@ async def async_execute(self):
try:
response = self.request.post(url, headers=headers, json="")
except RetryError as e:
logging.critical(f"Error! Executing SLP claim API call for account {self.acc_name}"
logging.critical(f"Important: Error! Executing SLP claim API call for account {self.acc_name}"
f"({self.account.replace('0x', 'ronin:')}). Error {e}")
return
if 200 <= response.status_code <= 299:
signature = response.json()["blockchain_related"].get("signature")
if not signature or not signature["signature"]:
logging.critical(f"Account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) had no signature "
logging.critical(f"Important: Account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) had no signature "
"in blockchain_related")
return
else:
logging.info(f"Claim for account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) "
logging.info(f"Important: Claim for account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) "
"had to be skipped")
return
nonce = get_nonce(self.account)
Expand All @@ -123,7 +123,7 @@ async def async_execute(self):
# We will wait for max 5 minutes for this tx to respond
if datetime.now() - start_time > timedelta(minutes=TIMEOUT_MINS):
success = False
logging.info(f"Transaction {self}, timed out!")
logging.info(f"Important: Transaction {self}, timed out!")
break
try:
recepit = self.w3.eth.get_transaction_receipt(hash)
Expand All @@ -138,10 +138,10 @@ async def async_execute(self):
# Sleep 5 seconds not to constantly send requests!
await asyncio.sleep(5)
if success:
logging.info(f"SLP Claimed! New balance for account {self.acc_name} "
logging.info(f"Important: SLP Claimed! New balance for account {self.acc_name} "
f"({self.account.replace('0x', 'ronin:')}) is: {check_balance(self.account)}")
else:
logging.info(f"Claim for account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) "
logging.info(f"Important: Claim for account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) "
"failed")

def execute(self):
Expand All @@ -154,7 +154,7 @@ def execute(self):
f"{unclaimed} unclaimed SLP")
jwt = self.get_jwt()
if not jwt:
logging.critical("Skipping claiming, we could not get the JWT for account "
logging.critical("Important: Skipping claiming, we could not get the JWT for account "
f"{self.account.replace('0x', 'ronin:')}")
return
headers = {
Expand All @@ -165,17 +165,17 @@ def execute(self):
try:
response = self.request.post(url, headers=headers, json="")
except RetryError as e:
logging.critical(f"Error! Executing SLP claim API call for account {self.acc_name}"
logging.critical(f"Important: Error! Executing SLP claim API call for account {self.acc_name}"
f"({self.account.replace('0x', 'ronin:')}). Error {e}")
return
if 200 <= response.status_code <= 299:
signature = response.json()["blockchain_related"].get("signature")
if not signature or not signature["signature"]:
logging.critical(f"Account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) had no signature "
logging.critical(f"Important: Account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) had no signature "
"in blockchain_related")
return
else:
logging.info(f"Claim for account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) "
logging.info(f"Important: Claim for account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) "
"had to be skipped")
return
nonce = get_nonce(self.account)
Expand All @@ -201,7 +201,7 @@ def execute(self):
# We will wait for max 5 minutes for this tx to respond
if datetime.now() - start_time > timedelta(minutes=TIMEOUT_MINS):
success = False
logging.info(f"Transaction {self}, timed out!")
logging.info(f"Important: Transaction {self}, timed out!")
break
try:
recepit = self.w3.eth.get_transaction_receipt(hash)
Expand All @@ -216,10 +216,10 @@ def execute(self):
# Sleep 5 seconds not to constantly send requests!
sleep(5)
if success:
logging.info(f"SLP Claimed! New balance for account {self.acc_name} "
logging.info(f"Important: SLP Claimed! New balance for account {self.acc_name} "
f"({self.account.replace('0x', 'ronin:')}) is: {check_balance(self.account)}")
else:
logging.info(f"Claim for account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) "
logging.info(f"Important: Claim for account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) "
"failed")

def __str__(self):
Expand Down Expand Up @@ -255,7 +255,7 @@ def has_unclaimed_slp(self):
try:
response = self.request.get(url, headers={"User-Agent": self.user_agent})
except RetryError:
logging.critical(f"Failed to check if there is unclaimed SLP for acc {self.acc_name} "
logging.critical(f"Important: Failed to check if there is unclaimed SLP for acc {self.acc_name} "
f"({self.account.replace('0x','ronin:')})")
return None
if 200 <= response.status_code <= 299:
Expand All @@ -264,10 +264,10 @@ def has_unclaimed_slp(self):
next_claim_date = last_claimed + timedelta(days=14)
utcnow = datetime.utcnow()
if utcnow < next_claim_date and not self.force:
logging.critical(f"This account will be claimable again on {self.humanize_date(next_claim_date)}.")
logging.critical(f"Important: This account will be claimable again on {self.humanize_date(next_claim_date)}.")
return None
elif self.force:
logging.info('Skipping check of dates, --force option was selected')
logging.info('Important: Skipping check of dates, --force option was selected')
wallet_total = check_balance(self.account)
in_game_total = int(data['total'])
if in_game_total > wallet_total:
Expand All @@ -277,14 +277,14 @@ def has_unclaimed_slp(self):
async def async_execute(self):
unclaimed = self.has_unclaimed_slp()
if not unclaimed:
logging.info(f"Account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) "
logging.info(f"Important: Account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) "
"has no claimable SLP")
return
logging.info(f"Account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) has "
logging.info(f"Important: Account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) has "
f"{unclaimed} unclaimed SLP")
jwt = self.get_jwt()
if not jwt:
logging.critical("Skipping claiming, we could not get the JWT for account "
logging.critical("Important: Skipping claiming, we could not get the JWT for account "
f"{self.account.replace('0x', 'ronin:')}")
return
headers = {
Expand All @@ -295,17 +295,17 @@ async def async_execute(self):
try:
response = self.request.post(url, headers=headers, json="")
except RetryError as e:
logging.critical(f"Error! Executing SLP claim API call for account {self.acc_name}"
logging.critical(f"Important: Error! Executing SLP claim API call for account {self.acc_name}"
f"({self.account.replace('0x', 'ronin:')}). Error {e}")
return
if 200 <= response.status_code <= 299:
signature = response.json()["blockchain_related"].get("signature")
if not signature or not signature["signature"]:
logging.critical(f"Account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) had no signature "
logging.critical(f"Important: Account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) had no signature "
"in blockchain_related")
return
else:
logging.info(f"Claim for account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) "
logging.info(f"Important: Claim for account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) "
"had to be skipped")
return
nonce = get_nonce(self.account)
Expand Down Expand Up @@ -343,7 +343,7 @@ async def async_execute(self):
# We will wait for max 5 minutes for this tx to respond
if datetime.now() - start_time > timedelta(minutes=TIMEOUT_MINS):
success = False
logging.info(f"Transaction {self}, timed out!")
logging.info(f"Important: Transaction {self}, timed out!")
break
try:
recepit = self.w3.eth.get_transaction_receipt(hash)
Expand All @@ -358,25 +358,25 @@ async def async_execute(self):
# Sleep 5 seconds not to constantly send requests!
await asyncio.sleep(5)
if success:
logging.info(f"SLP Claimed! New balance for account {self.acc_name} "
logging.info(f"Important: SLP Claimed! New balance for account {self.acc_name} "
f"({self.account.replace('0x', 'ronin:')}) is: {check_balance(self.account)}")
return
else:
logging.info(f"Claim for account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) "
logging.info(f"Important: Claim for account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) "
"failed")
return

def execute(self):
unclaimed = self.has_unclaimed_slp()
if not unclaimed:
logging.info(f"Account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) "
logging.info(f"Important: Account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) "
"has no claimable SLP")
return
logging.info(f"Account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) has "
logging.info(f"Important: Account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) has "
f"{unclaimed} unclaimed SLP")
jwt = self.get_jwt()
if not jwt:
logging.critical("Skipping claiming, we could not get the JWT for account "
logging.critical("Important: Skipping claiming, we could not get the JWT for account "
f"{self.account.replace('0x', 'ronin:')}")
return
headers = {
Expand All @@ -387,17 +387,17 @@ def execute(self):
try:
response = self.request.post(url, headers=headers, json="")
except RetryError as e:
logging.critical(f"Error! Executing SLP claim API call for account {self.acc_name}"
logging.critical(f"Important: Error! Executing SLP claim API call for account {self.acc_name}"
f"({self.account.replace('0x', 'ronin:')}). Error {e}")
return
if 200 <= response.status_code <= 299:
signature = response.json()["blockchain_related"].get("signature")
if not signature or not signature["signature"]:
logging.critical(f"Account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) had no signature "
logging.critical(f"Important: Account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) had no signature "
"in blockchain_related")
return
else:
logging.info(f"Claim for account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) "
logging.info(f"Important: Claim for account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) "
"had to be skipped")
return
nonce = get_nonce(self.account)
Expand Down Expand Up @@ -435,7 +435,7 @@ def execute(self):
# We will wait for max 5 minutes for this tx to respond
if datetime.now() - start_time > timedelta(minutes=TIMEOUT_MINS):
success = False
logging.info(f"Transaction {self}, timed out!")
logging.info(f"Important: Transaction {self}, timed out!")
break
try:
recepit = self.w3.eth.get_transaction_receipt(hash)
Expand All @@ -450,11 +450,11 @@ def execute(self):
# Sleep 5 seconds not to constantly send requests!
sleep(5)
if success:
logging.info(f"SLP Claimed! New balance for account {self.acc_name} "
logging.info(f"Important: SLP Claimed! New balance for account {self.acc_name} "
f"({self.account.replace('0x', 'ronin:')}) is: {check_balance(self.account)}")
return
else:
logging.info(f"Claim for account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) "
logging.info(f"Important: Claim for account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) "
"failed")
return

Expand Down
14 changes: 7 additions & 7 deletions axie-utils/axie_utils/morphing.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ def execute(self):
try:
response = self.request.post(url, headers=headers, json=payload)
except RetryError:
logging.critical(f"Important! Axie {self.axie} in {self.account} is not ready to be morphed!")
logging.critical(f"Important: Axie {self.axie} in {self.account} is not ready to be morphed!")
return

if 200 <= response.status_code <= 299:
if response.json().get('data') and response.json()['data'].get('morphAxie'):
logging.info(f"Axie {self.axie} in {self.account} correctly morphed!")
logging.info(f"Important: Axie {self.axie} in {self.account} correctly morphed!")
return
else:
logging.info(f"Something went wrong morphing axie {self.axie} in {self.account}")
logging.info(f"Important: Something went wrong morphing axie {self.axie} in {self.account}")
return
else:
logging.critical(f"Axie {self.axie} in {self.account} is not ready to be morphed!")
logging.critical(f"Important: Axie {self.axie} in {self.account} is not ready to be morphed!")
return


Expand Down Expand Up @@ -86,8 +86,8 @@ def execute(self):

if 200 <= response.status_code <= 299:
if response.json().get('data') and response.json()['data'].get('morphAxie'):
logging.info(f"Axie {self.axie} in {self.account} correctly morphed!")
logging.info(f"Important: Axie {self.axie} in {self.account} correctly morphed!")
else:
logging.info(f"Something went wrong morphing axie {self.axie} in {self.account}")
logging.info(f"Important: Something went wrong morphing axie {self.axie} in {self.account}")
else:
logging.critical(f"Axie {self.axie} in {self.account} is not ready to be morphed!")
logging.critical(f"Important: Axie {self.axie} in {self.account} is not ready to be morphed!")
Loading

0 comments on commit c7588eb

Please sign in to comment.