Skip to content

Commit

Permalink
add attributes property for token amount
Browse files Browse the repository at this point in the history
  • Loading branch information
popenta committed Jan 22, 2025
1 parent 42e7fce commit b578d15
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions multiversx_sdk/network_providers/api_network_provider_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ def test_get_fungible_tokens_of_account(self):
assert len(filtered) == 1
assert filtered[0].token.identifier == "TEST-ff155e"
assert filtered[0].amount == 99999999999980000
assert not filtered[0].attributes

def test_get_non_fungible_tokens_of_account(self):
address = Address.new_from_bech32("erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl")
Expand All @@ -390,6 +391,7 @@ def test_get_non_fungible_tokens_of_account(self):
assert filtered[0].token.identifier == "NFTEST-ec88b8-01"
assert filtered[0].token.nonce == 1
assert filtered[0].amount == 1
assert filtered[0].attributes

def test_get_definition_of_fungible_token(self):
result = self.api.get_definition_of_fungible_token("TEST-ff155e")
Expand Down
11 changes: 7 additions & 4 deletions multiversx_sdk/network_providers/http_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,23 +497,24 @@ def token_amount_on_network_from_proxy_response(raw_response: dict[str, Any]) ->
balance = int(token_data.get("balance", "0"))
nonce = token_data.get("nonce", 0)
token = Token(identifier, nonce)
attributes = base64.b64decode(token_data.get("attributes", ""))

return TokenAmountOnNetwork(
raw=raw_response,
token=token,
amount=balance,
attributes=attributes,
block_coordinates=block_coordinates,
)


def token_amount_from_api_response(raw_response: dict[str, Any]) -> TokenAmountOnNetwork:
identifier = raw_response.get("identifier", "")
nonce = raw_response.get("nonce", 0)
amount = int(raw_response.get("balance", 0))
attributes = base64.b64decode(raw_response.get("attributes", ""))

# nfts don't have the balance field, thus in case it's nft we set the balance to 1
amount = int(raw_response.get("balance", 1))

return TokenAmountOnNetwork(raw=raw_response, token=Token(identifier, nonce), amount=amount)
return TokenAmountOnNetwork(raw=raw_response, token=Token(identifier, nonce), amount=amount, attributes=attributes)


def token_amounts_from_proxy_response(raw_response: dict[str, Any]) -> list[TokenAmountOnNetwork]:
Expand All @@ -527,12 +528,14 @@ def token_amounts_from_proxy_response(raw_response: dict[str, Any]) -> list[Toke
balance = int(token_data.get("balance", "0"))
nonce = token_data.get("nonce", 0)
token = Token(identifier, nonce)
attributes = base64.b64decode(raw_response.get("attributes", ""))

result.append(
TokenAmountOnNetwork(
raw={item: token_data},
token=token,
amount=balance,
attributes=attributes,
block_coordinates=block_coordinates,
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def test_get_fungible_tokens_of_account(self):
assert len(filtered) == 1
assert filtered[0].token.identifier == "TEST-ff155e"
assert filtered[0].amount == 99999999999980000
assert not filtered[0].attributes

def test_get_non_fungible_tokens_of_account(self):
address = Address.new_from_bech32("erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl")
Expand All @@ -127,6 +128,7 @@ def test_get_non_fungible_tokens_of_account(self):
assert filtered[0].token.identifier == "NFTEST-ec88b8-01"
assert filtered[0].token.nonce == 1
assert filtered[0].amount == 1
assert filtered[0].attributes

def test_get_transaction_status(self):
result = self.proxy.get_transaction_status(
Expand Down
1 change: 1 addition & 0 deletions multiversx_sdk/network_providers/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class TokenAmountOnNetwork:
raw: dict[str, Any]
token: Token
amount: int
attributes: bytes
block_coordinates: Optional[BlockCoordinates] = None


Expand Down

0 comments on commit b578d15

Please sign in to comment.