Skip to content

Commit

Permalink
added query bandwidth of the account
Browse files Browse the repository at this point in the history
  • Loading branch information
yxy committed Jun 17, 2022
1 parent b6b011e commit 7ca39e1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tronpy/async_tron.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,18 @@ async def get_account(self, addr: TAddress) -> dict:
else:
raise AddressNotFound("account not found on-chain")

# Bandwidth query
async def get_bandwidth(self, addr: TAddress) -> dict:
"""Query the bandwidth of the account"""

ret = await self.provider.make_request(
"wallet/getaccountnet", {"address": keys.to_base58check_address(addr)}
)
if ret:
return ret['freeNetLimit'] - ret.get('freeNetUsed', 0)
else:
raise AddressNotFound("account not found on-chain")

async def get_account_resource(self, addr: TAddress) -> dict:
"""Get resource info of an account."""

Expand Down
10 changes: 10 additions & 0 deletions tronpy/tron.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,16 @@ def get_account_balance(self, addr: TAddress) -> Decimal:
info = self.get_account(addr)
return Decimal(info.get("balance", 0)) / 1_000_000

def get_account_bandwidth(self, addr: TAddress) -> int:
"""Query the bandwidth of the account"""
ret = self.provider.make_request(
"wallet/getaccountnet", {"address": keys.to_base58check_address(addr)}
)
if ret:
return ret['freeNetLimit'] - ret.get('freeNetUsed', 0)
else:
raise AddressNotFound("account not found on-chain")

def get_account_asset_balances(self, addr: TAddress) -> dict:
"""Get all TRC10 token balances of an account."""
info = self.get_account(addr)
Expand Down

0 comments on commit 7ca39e1

Please sign in to comment.