Skip to content

Commit

Permalink
Merge pull request #18 from Chipe1/cgv-add-single-jetton-balance
Browse files Browse the repository at this point in the history
Add method to get single Jetton balance by owner address
  • Loading branch information
nessshon authored Jun 20, 2024
2 parents c045918 + 1c64ed6 commit 696144f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions AvailableMethods.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion pytonapi/async_tonapi/methods/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down
15 changes: 14 additions & 1 deletion pytonapi/tonapi/methods/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions tests/async_tonapi/test_accounts_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions tests/tonapi/test_accounts_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 696144f

Please sign in to comment.