big update

This commit is contained in:
user committed 2024-04-05 02:35:15 +03:00
1 parent 7d05a3f2c0
commit f45d593a84
32 files changed
+726 -320

No files matched your search

+11 -3
View File
@@ -9,12 +9,13 @@ from app.core.logger import make_log
class TonCenter:
def __init__(self, host: str, api_key: str = None, testnet: bool = False):
def __init__(self, host: str, api_key: str = None, v3_host: str = None, testnet: bool = False):
self.host = host
self.api_key = api_key
self.v3_host = v3_host
self.last_used = time.time()
async def request(self, method: str, endpoint: str, *args, tries_count=0, **kwargs) -> dict:
async def request(self, method: str, endpoint: str, *args, v3: bool=False, tries_count=0, **kwargs) -> dict:
if tries_count > 3:
raise Exception(f'Error while toncenter request {endpoint}: {tries_count}')
@@ -30,7 +31,7 @@ class TonCenter:
await asyncio.sleep(0.1)
self.last_used = time.time()
response = await client.request(method, f"{self.host}{endpoint}", *args, **kwargs)
response = await client.request(method, f"{self.host_v3 if v3 is True else self.host}{endpoint}", *args, **kwargs)
try:
if response.status_code != 200:
raise Exception(f'Error while toncenter request {endpoint}: {response.text}')
@@ -80,5 +81,12 @@ class TonCenter:
}
)).get('result', {})
async def get_nft_items(self, limit: int = 100, offset: int = 0, **search_options):
return (await self.request(
"GET", 'nft/items',
params={**search_options, 'limit': limit, 'offset': offset},
v3=True
)).get('nft_items', [])
toncenter = TonCenter(TONCENTER_HOST, TONCENTER_API_KEY)