From 1c64ed6a6eb408c13e92e4e1b2b51aa4599e268f Mon Sep 17 00:00:00 2001 From: Chipe1 Date: Thu, 20 Jun 2024 00:55:23 +0530 Subject: [PATCH] Add method to get single Jetton balance by owner address --- AvailableMethods.md | 1 + pytonapi/async_tonapi/methods/accounts.py | 15 ++++++++++++++- pytonapi/tonapi/methods/accounts.py | 15 ++++++++++++++- tests/async_tonapi/test_accounts_methods.py | 4 ++++ tests/tonapi/test_accounts_methods.py | 4 ++++ 5 files changed, 37 insertions(+), 2 deletions(-) diff --git a/AvailableMethods.md b/AvailableMethods.md index a1c6539..32c097c 100644 --- a/AvailableMethods.md +++ b/AvailableMethods.md @@ -54,6 +54,7 @@ - [x] /v2/accounts/{account_id} - [x] /v2/accounts/{account_id}/dns/backresolve - [x] /v2/accounts/{account_id}/jettons +- [x] /v2/accounts/{account_id}/jettons/{jetton_id} - [x] /v2/accounts/{account_id}/jettons/history - [x] /v2/accounts/{account_id}/jettons/{jetton_id}/history - [x] /v2/accounts/{account_id}/nfts diff --git a/pytonapi/async_tonapi/methods/accounts.py b/pytonapi/async_tonapi/methods/accounts.py index 86927fd..5196c5a 100644 --- a/pytonapi/async_tonapi/methods/accounts.py +++ b/pytonapi/async_tonapi/methods/accounts.py @@ -13,7 +13,7 @@ ) from pytonapi.schema.domains import DomainNames from pytonapi.schema.events import AccountEvents, AccountEvent -from pytonapi.schema.jettons import JettonsBalances +from pytonapi.schema.jettons import JettonBalance, JettonsBalances from pytonapi.schema.nft import NftItems, NftItem from pytonapi.schema.traces import TraceIds @@ -81,6 +81,19 @@ async def get_jettons_balances(self, account_id: str) -> JettonsBalances: return JettonsBalances(**response) + async def get_jetton_balance(self, account_id: str, jetton_id: str) -> JettonBalance: + """ + Get Jetton balance by owner address + + :param account_id: account ID + :param jetton_id: jetton ID + :return: :class:`JettonBalance` + """ + method = f"v2/accounts/{account_id}/jettons/{jetton_id}" + response = await self._get(method=method) + + return JettonBalance(**response) + async def get_jettons_history( self, account_id: str, diff --git a/pytonapi/tonapi/methods/accounts.py b/pytonapi/tonapi/methods/accounts.py index d420863..8bde7b5 100644 --- a/pytonapi/tonapi/methods/accounts.py +++ b/pytonapi/tonapi/methods/accounts.py @@ -13,7 +13,7 @@ BalanceChange, ) from pytonapi.schema.domains import DomainNames -from pytonapi.schema.jettons import JettonsBalances +from pytonapi.schema.jettons import JettonBalance, JettonsBalances from pytonapi.schema.nft import NftItems, NftItem from pytonapi.schema.traces import TraceIds @@ -81,6 +81,19 @@ def get_jettons_balances(self, account_id: str) -> JettonsBalances: return JettonsBalances(**response) + def get_jetton_balance(self, account_id: str, jetton_id: str) -> JettonBalance: + """ + Get Jetton balance by owner address + + :param account_id: account ID + :param jetton_id: jetton ID + :return: :class:`JettonBalance` + """ + method = f"v2/accounts/{account_id}/jettons/{jetton_id}" + response = self._get(method=method) + + return JettonBalance(**response) + def get_jettons_history( self, account_id: str, diff --git a/tests/async_tonapi/test_accounts_methods.py b/tests/async_tonapi/test_accounts_methods.py index 2949405..e2943a0 100644 --- a/tests/async_tonapi/test_accounts_methods.py +++ b/tests/async_tonapi/test_accounts_methods.py @@ -29,6 +29,10 @@ async def test_get_jettons(self): response = await self.tonapi.accounts.get_jettons_balances(ACCOUNT_ID) self.assertIsInstance(response, schema.jettons.JettonsBalances) + async def test_get_jetton(self): + response = await self.tonapi.accounts.get_jetton_balance(ACCOUNT_ID, JETTON_ID) + self.assertIsInstance(response, schema.jettons.JettonBalance) + async def test_get_jettons_history(self): response = await self.tonapi.accounts.get_jettons_history(ACCOUNT_ID) self.assertIsInstance(response, schema.events.AccountEvents) diff --git a/tests/tonapi/test_accounts_methods.py b/tests/tonapi/test_accounts_methods.py index f56e924..415e7d1 100644 --- a/tests/tonapi/test_accounts_methods.py +++ b/tests/tonapi/test_accounts_methods.py @@ -29,6 +29,10 @@ def test_get_jettons(self): response = self.tonapi.accounts.get_jettons_balances(ACCOUNT_ID) self.assertIsInstance(response, schema.jettons.JettonsBalances) + def test_get_jetton(self): + response = self.tonapi.accounts.get_jetton_balance(ACCOUNT_ID, JETTON_ID) + self.assertIsInstance(response, schema.jettons.JettonBalance) + def test_get_jettons_history(self): response = self.tonapi.accounts.get_jettons_history(ACCOUNT_ID) self.assertIsInstance(response, schema.events.AccountEvents)