From 4bb091d3970fa61161f73975d1e8d8bd55a0bc7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Wed, 5 Jun 2024 16:11:35 +0300 Subject: [PATCH 1/3] Additional fields on AccountOnNetwork. --- multiversx_sdk/network_providers/accounts.py | 47 ++++++++++++------- .../api_network_provider_test.py | 2 + 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/multiversx_sdk/network_providers/accounts.py b/multiversx_sdk/network_providers/accounts.py index bd062b3c..1b1c23fc 100644 --- a/multiversx_sdk/network_providers/accounts.py +++ b/multiversx_sdk/network_providers/accounts.py @@ -1,3 +1,4 @@ +import base64 from typing import Any, Dict from multiversx_sdk.core.address import Address @@ -8,35 +9,47 @@ class AccountOnNetwork: def __init__(self): self.address: IAddress = EmptyAddress() + self.owner_address = EmptyAddress() self.nonce: int = 0 self.balance: int = 0 - self.code: bytes = b'' - self.username: str = '' - self.code_hash: str = '' + self.developer_reward = 0 + self.code: bytes = b"" + self.username: str = "" + self.code_hash: str = "" + self.root_hash: str = "" @staticmethod - def from_http_response(payload: Dict[str, Any]) -> 'AccountOnNetwork': + def from_http_response(payload: Dict[str, Any]) -> "AccountOnNetwork": result = AccountOnNetwork() - address = payload.get('address', '') + address = payload.get("address", "") + owner_address = payload.get("ownerAddress", "") + result.address = Address.new_from_bech32(address) if address else EmptyAddress() + result.owner_address = Address.new_from_bech32(owner_address) if owner_address else EmptyAddress() + + result.nonce = payload.get("nonce", 0) + result.balance = int(payload.get("balance", 0)) + result.developer_reward = int(payload.get("developerReward", 0)) - result.nonce = payload.get('nonce', 0) - result.balance = int(payload.get('balance', 0)) - result.code = bytes.fromhex(payload.get('code', '')) - result.username = payload.get('username', '') - result.code_hash = payload.get('codeHash', '') + result.code = bytes.fromhex(payload.get("code", "")) + result.username = payload.get("username", "") + result.code_hash = base64.b64decode(payload.get("codeHash", "") or "").hex() + result.root_hash = base64.b64decode(payload.get("rootHash", "") or "").hex() return result def to_dictionary(self) -> Dict[str, Any]: return { "address": self.address.to_bech32(), + "ownerAddress": self.owner_address.to_bech32(), "nonce": self.nonce, "balance": self.balance, + "developerReward": self.developer_reward, "code": self.code.hex(), "username": self.username, - "codeHash": self.code_hash + "codeHash": self.code_hash, + "rootHash": self.root_hash } @@ -47,10 +60,10 @@ def __init__(self): self.pending_guardian: Guardian = Guardian() @staticmethod - def from_http_response(response: Dict[str, Any]) -> 'GuardianData': + def from_http_response(response: Dict[str, Any]) -> "GuardianData": result = GuardianData() - result.guarded = response.get('guarded', False) + result.guarded = response.get("guarded", False) if response.get("activeGuardian", None): result.active_guardian = Guardian.from_http_response(response["activeGuardian"]) @@ -73,11 +86,11 @@ def __init__(self) -> None: self.service_uid: str = "" @staticmethod - def from_http_response(response: Dict[str, Any]) -> 'Guardian': + def from_http_response(response: Dict[str, Any]) -> "Guardian": result = Guardian() - result.activation_epoch = int(response.get('activationEpoch', 0)) - result.address = Address.new_from_bech32(response.get('address', '')) - result.service_uid = response.get('serviceUID', '') + result.activation_epoch = int(response.get("activationEpoch", 0)) + result.address = Address.new_from_bech32(response.get("address", "")) + result.service_uid = response.get("serviceUID", "") return result diff --git a/multiversx_sdk/network_providers/api_network_provider_test.py b/multiversx_sdk/network_providers/api_network_provider_test.py index 3f6e5ecf..1fd38433 100644 --- a/multiversx_sdk/network_providers/api_network_provider_test.py +++ b/multiversx_sdk/network_providers/api_network_provider_test.py @@ -58,6 +58,8 @@ def test_get_account(self): assert result.address.to_bech32() == 'erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl' assert result.username == '' + assert len(result.code_hash) == 0 + assert len(result.root_hash) == 64 def test_get_generic_with_bad_address(self): with pytest.raises(GenericError, match='a bech32 address is expected'): From 8723e1ed3091c42021dd3200b4c6ca875250f1b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Wed, 5 Jun 2024 17:07:01 +0300 Subject: [PATCH 2/3] Undo breaking change. --- multiversx_sdk/network_providers/accounts.py | 5 ++--- .../network_providers/api_network_provider_test.py | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/multiversx_sdk/network_providers/accounts.py b/multiversx_sdk/network_providers/accounts.py index 1b1c23fc..b4915ea3 100644 --- a/multiversx_sdk/network_providers/accounts.py +++ b/multiversx_sdk/network_providers/accounts.py @@ -1,4 +1,3 @@ -import base64 from typing import Any, Dict from multiversx_sdk.core.address import Address @@ -34,8 +33,8 @@ def from_http_response(payload: Dict[str, Any]) -> "AccountOnNetwork": result.code = bytes.fromhex(payload.get("code", "")) result.username = payload.get("username", "") - result.code_hash = base64.b64decode(payload.get("codeHash", "") or "").hex() - result.root_hash = base64.b64decode(payload.get("rootHash", "") or "").hex() + result.code_hash = payload.get("codeHash", "") + result.root_hash = payload.get("rootHash", "") return result diff --git a/multiversx_sdk/network_providers/api_network_provider_test.py b/multiversx_sdk/network_providers/api_network_provider_test.py index 1fd38433..3a959d2c 100644 --- a/multiversx_sdk/network_providers/api_network_provider_test.py +++ b/multiversx_sdk/network_providers/api_network_provider_test.py @@ -1,3 +1,5 @@ +import base64 + import pytest from multiversx_sdk.core.address import Address @@ -56,10 +58,18 @@ def test_get_account(self): address = Address.new_from_bech32('erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl') result = self.api.get_account(address) - assert result.address.to_bech32() == 'erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl' + assert result.address.to_bech32() == address.to_bech32() assert result.username == '' assert len(result.code_hash) == 0 - assert len(result.root_hash) == 64 + assert len(base64.b64decode(result.root_hash)) == 32 + + address = Address.new_from_bech32('erd1qqqqqqqqqqqqqpgqws44xjx2t056nn79fn29q0rjwfrd3m43396ql35kxy') + result = self.api.get_account(address) + + assert result.address.to_bech32() == address.to_bech32() + assert result.username == '' + assert len(base64.b64decode(result.code_hash)) == 32 + assert len(base64.b64decode(result.root_hash)) == 32 def test_get_generic_with_bad_address(self): with pytest.raises(GenericError, match='a bech32 address is expected'): From b183fde02cd34db472509af2d437759f6315288c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Wed, 5 Jun 2024 17:07:16 +0300 Subject: [PATCH 3/3] Bump version. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 7ba0a2d9..21d37741 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ allow-direct-references = true [project] name = "multiversx-sdk" -version = "0.9.1" +version = "0.9.2" authors = [ { name="MultiversX" }, ]