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

Commit

Permalink
Change claim endpoint for the new one
Browse files Browse the repository at this point in the history
  • Loading branch information
FerranMarin committed May 24, 2022
1 parent c7588eb commit 642b86f
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 71 deletions.
58 changes: 28 additions & 30 deletions axie-utils/axie_utils/claims.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,29 @@ def localize_date(self, date_utc):
def humanize_date(self, date):
local_date = self.localize_date(date)
return local_date.strftime("%m/%d/%Y, %H:%M")

def has_unclaimed_slp(self):
url = f"https://game-api.skymavis.com/game-api/clients/{self.account}/items/1"
url = f"http://game-api-pre.skymavis.com/v1/players/{self.account}/items/1"
try:
response = self.request.get(url, headers={"User-Agent": self.user_agent})
except RetryError:
logging.critical(f"Important: Failed to check if there is unclaimed SLP for acc {self.acc_name} "
f"({self.account.replace('0x','ronin:')})")
f"({self.account.replace('0x', 'ronin:')})")
return None
if 200 <= response.status_code <= 299:
data = response.json()
last_claimed = datetime.utcfromtimestamp(data['last_claimed_item_at'])
last_claimed = datetime.utcfromtimestamp(data['lastClaimedItemAt'])
next_claim_date = last_claimed + timedelta(days=14)
utcnow = datetime.utcnow()
if utcnow < next_claim_date and not self.force:
logging.critical(f"Important: 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')
wallet_total = check_balance(self.account)
in_game_total = int(data['total'])
if in_game_total > wallet_total:
return in_game_total - wallet_total
logging.info('Important: Skipping check of dates, --force option was selected')
claimable_total = int(data['rawClaimableTotal'])
if claimable_total > 0:
return claimable_total
return None

async def async_execute(self):
Expand All @@ -83,18 +83,18 @@ async def async_execute(self):
"User-Agent": self.user_agent,
"authorization": f"Bearer {jwt}"
}
url = f"https://game-api.skymavis.com/game-api/clients/{self.account}/items/1/claim"
url = "http://game-api-pre.skymavis.com/v1/players/me/items/1/claim"
try:
response = self.request.post(url, headers=headers, json="")
except RetryError as e:
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")
signature = response.json()["blockchainRelated"].get("signature")
if not signature or not signature["signature"]:
logging.critical(f"Important: Account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) had no signature "
"in blockchain_related")
"in blockchainRelated")
return
else:
logging.info(f"Important: Claim for account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) "
Expand Down Expand Up @@ -161,18 +161,18 @@ def execute(self):
"User-Agent": self.user_agent,
"authorization": f"Bearer {jwt}"
}
url = f"https://game-api.skymavis.com/game-api/clients/{self.account}/items/1/claim"
url = "http://game-api-pre.skymavis.com/v1/players/me/items/1/claim"
try:
response = self.request.post(url, headers=headers, json="")
except RetryError as e:
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")
signature = response.json()["blockchainRelated"].get("signature")
if not signature or not signature["signature"]:
logging.critical(f"Important: Account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) had no signature "
"in blockchain_related")
"in blockchainRelated")
return
else:
logging.info(f"Important: Claim for account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) "
Expand Down Expand Up @@ -248,10 +248,9 @@ def localize_date(self, date_utc):
def humanize_date(self, date):
local_date = self.localize_date(date)
return local_date.strftime("%m/%d/%Y, %H:%M")



def has_unclaimed_slp(self):
url = f"https://game-api.skymavis.com/game-api/clients/{self.account}/items/1"
url = f"http://game-api-pre.skymavis.com/v1/players/{self.account}/items/1"
try:
response = self.request.get(url, headers={"User-Agent": self.user_agent})
except RetryError:
Expand All @@ -260,18 +259,17 @@ def has_unclaimed_slp(self):
return None
if 200 <= response.status_code <= 299:
data = response.json()
last_claimed = datetime.utcfromtimestamp(data['last_claimed_item_at'])
last_claimed = datetime.utcfromtimestamp(data['lastClaimedItemAt'])
next_claim_date = last_claimed + timedelta(days=14)
utcnow = datetime.utcnow()
if utcnow < next_claim_date and not self.force:
logging.critical(f"Important: This account will be claimable again on {self.humanize_date(next_claim_date)}.")
return None
elif self.force:
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:
return in_game_total - wallet_total
claimable_total = int(data['rawClaimableTotal'])
if claimable_total > 0:
return claimable_total
return None

async def async_execute(self):
Expand All @@ -291,18 +289,18 @@ async def async_execute(self):
"User-Agent": self.user_agent,
"authorization": f"Bearer {jwt}"
}
url = f"https://game-api.skymavis.com/game-api/clients/{self.account}/items/1/claim"
url = "http://game-api-pre.skymavis.com/v1/players/me/items/1/claim"
try:
response = self.request.post(url, headers=headers, json="")
except RetryError as e:
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")
signature = response.json()["blockchainRelated"].get("signature")
if not signature or not signature["signature"]:
logging.critical(f"Important: Account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) had no signature "
"in blockchain_related")
"in blockchainRelated")
return
else:
logging.info(f"Important: Claim for account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) "
Expand Down Expand Up @@ -383,18 +381,18 @@ def execute(self):
"User-Agent": self.user_agent,
"authorization": f"Bearer {jwt}"
}
url = f"https://game-api.skymavis.com/game-api/clients/{self.account}/items/1/claim"
url = "http://game-api-pre.skymavis.com/v1/players/me/items/1/claim"
try:
response = self.request.post(url, headers=headers, json="")
except RetryError as e:
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")
signature = response.json()["blockchainRelated"].get("signature")
if not signature or not signature["signature"]:
logging.critical(f"Important: Account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) had no signature "
"in blockchain_related")
"in blockchainRelated")
return
else:
logging.info(f"Important: Claim for account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) "
Expand Down
Loading

0 comments on commit 642b86f

Please sign in to comment.