From f6e9180cecc1a7eb3a63c92ee54e733b91bbf3c5 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Tue, 5 Nov 2024 10:57:18 +0200 Subject: [PATCH 1/7] wip: change type of sender & receiver --- .../controllers/account_controller.py | 23 ++--- .../controllers/delegation_controller.py | 80 +++++++++-------- multiversx_sdk/controllers/interfaces.py | 9 +- .../controllers/relayed_controller.py | 12 +-- .../controllers/smart_contract_controller.py | 29 +++--- .../token_management_controller.py | 57 ++++++------ .../controllers/transfers_controller.py | 18 ++-- .../converters/transactions_converter.py | 3 +- .../converters/transactions_converter_test.py | 6 +- multiversx_sdk/core/account.py | 47 ++++++++++ multiversx_sdk/core/address.py | 24 ++--- multiversx_sdk/core/interfaces.py | 36 +------- multiversx_sdk/core/message.py | 9 +- .../core/proto/transaction_serializer.py | 36 ++------ .../core/proto/transaction_serializer_test.py | 22 ++--- multiversx_sdk/core/transaction.py | 10 ++- multiversx_sdk/core/transaction_computer.py | 37 ++++---- .../account_transactions_factory.py | 13 +-- .../delegation_transactions_factory.py | 76 ++++++++-------- .../relayed_transactions_factory.py | 44 +++++---- .../relayed_transactions_factory_test.py | 34 +++---- .../smart_contract_transactions_factory.py | 21 +++-- .../token_management_transactions_factory.py | 89 ++++++++++--------- .../token_transfers_data_builder.py | 7 +- .../transaction_builder.py | 10 +-- .../transactions_factory_config.py | 3 +- .../transfer_transactions_factory.py | 27 +++--- multiversx_sdk/facades/entrypoints.py | 2 +- .../api_network_provider_test.py | 48 +++++----- .../network_providers/http_resources.py | 11 +-- .../proxy_network_provider_test.py | 40 ++++----- multiversx_sdk/network_providers/resources.py | 8 -- .../testutils/mock_network_provider.py | 3 +- 33 files changed, 453 insertions(+), 441 deletions(-) diff --git a/multiversx_sdk/controllers/account_controller.py b/multiversx_sdk/controllers/account_controller.py index d492c995..40c75604 100644 --- a/multiversx_sdk/controllers/account_controller.py +++ b/multiversx_sdk/controllers/account_controller.py @@ -1,7 +1,7 @@ from typing import Dict -from multiversx_sdk.controllers.interfaces import IAccount -from multiversx_sdk.core.interfaces import IAddress +from multiversx_sdk.core.account import Account +from multiversx_sdk.core.address import Address from multiversx_sdk.core.transaction import Transaction from multiversx_sdk.core.transaction_computer import TransactionComputer from multiversx_sdk.core.transactions_factories import ( @@ -10,11 +10,12 @@ class AccountController: def __init__(self, chain_id: str) -> None: - self.factory = AccountTransactionsFactory(TransactionsFactoryConfig(chain_id)) + self.factory = AccountTransactionsFactory( + TransactionsFactoryConfig(chain_id)) self.tx_computer = TransactionComputer() def create_transaction_for_saving_key_value(self, - sender: IAccount, + sender: Account, nonce: int, key_value_pairs: Dict[bytes, bytes]) -> Transaction: transaction = self.factory.create_transaction_for_saving_key_value( @@ -28,9 +29,9 @@ def create_transaction_for_saving_key_value(self, return transaction def create_transaction_for_setting_guardian(self, - sender: IAccount, + sender: Account, nonce: int, - guardian_address: IAddress, + guardian_address: Address, service_id: str) -> Transaction: transaction = self.factory.create_transaction_for_setting_guardian( sender=sender.address, @@ -44,25 +45,27 @@ def create_transaction_for_setting_guardian(self, return transaction def create_transaction_for_guarding_account(self, - sender: IAccount, + sender: Account, nonce: int) -> Transaction: transaction = self.factory.create_transaction_for_guarding_account( sender=sender.address ) transaction.nonce = nonce - transaction.signature = sender.sign(self.tx_computer.compute_bytes_for_signing(transaction)) + transaction.signature = sender.sign( + self.tx_computer.compute_bytes_for_signing(transaction)) return transaction def create_transaction_for_unguarding_account(self, - sender: IAccount, + sender: Account, nonce: int) -> Transaction: transaction = self.factory.create_transaction_for_unguarding_account( sender=sender.address ) transaction.nonce = nonce - transaction.signature = sender.sign(self.tx_computer.compute_bytes_for_signing(transaction)) + transaction.signature = sender.sign( + self.tx_computer.compute_bytes_for_signing(transaction)) return transaction diff --git a/multiversx_sdk/controllers/delegation_controller.py b/multiversx_sdk/controllers/delegation_controller.py index fbd707b5..0783b469 100644 --- a/multiversx_sdk/controllers/delegation_controller.py +++ b/multiversx_sdk/controllers/delegation_controller.py @@ -1,7 +1,8 @@ from typing import List, Sequence -from multiversx_sdk.controllers.interfaces import IAccount, INetworkProvider -from multiversx_sdk.core.interfaces import IAddress, IValidatorPublicKey +from multiversx_sdk.controllers.interfaces import INetworkProvider +from multiversx_sdk.core.address import Address +from multiversx_sdk.core.interfaces import IValidatorPublicKey from multiversx_sdk.core.transaction import Transaction from multiversx_sdk.core.transaction_computer import TransactionComputer from multiversx_sdk.core.transaction_on_network import TransactionOnNetwork @@ -9,6 +10,7 @@ DelegationTransactionsFactory, TransactionsFactoryConfig) from multiversx_sdk.core.transactions_outcome_parsers.delegation_transactions_outcome_parser import ( CreateNewDelegationContractOutcome, DelegationTransactionsOutcomeParser) +from multiversx_sdk.core.account import Account class DelegationController: @@ -19,7 +21,7 @@ def __init__(self, chain_id: str, network_provider: INetworkProvider) -> None: self.tx_computer = TransactionComputer() def create_transaction_for_new_delegation_contract(self, - sender: IAccount, + sender: Account, nonce: int, total_delegation_cap: int, service_fee: int, @@ -46,9 +48,9 @@ def await_completed_create_new_delegation_contract( return self.parse_create_new_delegation_contract(transaction) def create_transaction_for_adding_nodes(self, - sender: IAccount, + sender: Account, nonce: int, - delegation_contract: IAddress, + delegation_contract: Address, public_keys: Sequence[IValidatorPublicKey], signed_messages: Sequence[bytes]) -> Transaction: transaction = self.factory.create_transaction_for_adding_nodes( @@ -64,9 +66,9 @@ def create_transaction_for_adding_nodes(self, return transaction def create_transaction_for_removing_nodes(self, - sender: IAccount, + sender: Account, nonce: int, - delegation_contract: IAddress, + delegation_contract: Address, public_keys: Sequence[IValidatorPublicKey]) -> Transaction: transaction = self.factory.create_transaction_for_removing_nodes( sender=sender.address, @@ -80,9 +82,9 @@ def create_transaction_for_removing_nodes(self, return transaction def create_transaction_for_staking_nodes(self, - sender: IAccount, + sender: Account, nonce: int, - delegation_contract: IAddress, + delegation_contract: Address, public_keys: Sequence[IValidatorPublicKey]) -> Transaction: transaction = self.factory.create_transaction_for_staking_nodes( sender=sender.address, @@ -96,9 +98,9 @@ def create_transaction_for_staking_nodes(self, return transaction def create_transaction_for_unbonding_nodes(self, - sender: IAccount, + sender: Account, nonce: int, - delegation_contract: IAddress, + delegation_contract: Address, public_keys: Sequence[IValidatorPublicKey]) -> Transaction: transaction = self.factory.create_transaction_for_unbonding_nodes( sender=sender.address, @@ -112,9 +114,9 @@ def create_transaction_for_unbonding_nodes(self, return transaction def create_transaction_for_unstaking_nodes(self, - sender: IAccount, + sender: Account, nonce: int, - delegation_contract: IAddress, + delegation_contract: Address, public_keys: Sequence[IValidatorPublicKey]) -> Transaction: transaction = self.factory.create_transaction_for_unstaking_nodes( sender=sender.address, @@ -128,9 +130,9 @@ def create_transaction_for_unstaking_nodes(self, return transaction def create_transaction_for_unjailing_nodes(self, - sender: IAccount, + sender: Account, nonce: int, - delegation_contract: IAddress, + delegation_contract: Address, public_keys: Sequence[IValidatorPublicKey], amount: int) -> Transaction: transaction = self.factory.create_transaction_for_unjailing_nodes( @@ -146,9 +148,9 @@ def create_transaction_for_unjailing_nodes(self, return transaction def create_transaction_for_changing_service_fee(self, - sender: IAccount, + sender: Account, nonce: int, - delegation_contract: IAddress, + delegation_contract: Address, service_fee: int) -> Transaction: transaction = self.factory.create_transaction_for_changing_service_fee( sender=sender.address, @@ -162,9 +164,9 @@ def create_transaction_for_changing_service_fee(self, return transaction def create_transaction_for_modifying_delegation_cap(self, - sender: IAccount, + sender: Account, nonce: int, - delegation_contract: IAddress, + delegation_contract: Address, delegation_cap: int) -> Transaction: transaction = self.factory.create_transaction_for_modifying_delegation_cap( sender=sender.address, @@ -178,9 +180,9 @@ def create_transaction_for_modifying_delegation_cap(self, return transaction def create_transaction_for_setting_automatic_activation(self, - sender: IAccount, + sender: Account, nonce: int, - delegation_contract: IAddress) -> Transaction: + delegation_contract: Address) -> Transaction: transaction = self.factory.create_transaction_for_setting_automatic_activation( sender=sender.address, delegation_contract=delegation_contract @@ -192,9 +194,9 @@ def create_transaction_for_setting_automatic_activation(self, return transaction def create_transaction_for_unsetting_automatic_activation(self, - sender: IAccount, + sender: Account, nonce: int, - delegation_contract: IAddress) -> Transaction: + delegation_contract: Address) -> Transaction: transaction = self.factory.create_transaction_for_unsetting_automatic_activation( sender=sender.address, delegation_contract=delegation_contract @@ -206,9 +208,9 @@ def create_transaction_for_unsetting_automatic_activation(self, return transaction def create_transaction_for_setting_cap_check_on_redelegate_rewards(self, - sender: IAccount, + sender: Account, nonce: int, - delegation_contract: IAddress) -> Transaction: + delegation_contract: Address) -> Transaction: transaction = self.factory.create_transaction_for_setting_cap_check_on_redelegate_rewards( sender=sender.address, delegation_contract=delegation_contract @@ -220,9 +222,9 @@ def create_transaction_for_setting_cap_check_on_redelegate_rewards(self, return transaction def create_transaction_for_unsetting_cap_check_on_redelegate_rewards(self, - sender: IAccount, + sender: Account, nonce: int, - delegation_contract: IAddress) -> Transaction: + delegation_contract: Address) -> Transaction: transaction = self.factory.create_transaction_for_unsetting_cap_check_on_redelegate_rewards( sender=sender.address, delegation_contract=delegation_contract @@ -234,9 +236,9 @@ def create_transaction_for_unsetting_cap_check_on_redelegate_rewards(self, return transaction def create_transaction_for_setting_metadata(self, - sender: IAccount, + sender: Account, nonce: int, - delegation_contract: IAddress, + delegation_contract: Address, name: str, website: str, identifier: str) -> Transaction: @@ -254,9 +256,9 @@ def create_transaction_for_setting_metadata(self, return transaction def create_transaction_for_delegating(self, - sender: IAccount, + sender: Account, nonce: int, - delegation_contract: IAddress, + delegation_contract: Address, amount: int) -> Transaction: transaction = self.factory.create_transaction_for_delegating( sender=sender.address, @@ -270,9 +272,9 @@ def create_transaction_for_delegating(self, return transaction def create_transaction_for_claiming_rewards(self, - sender: IAccount, + sender: Account, nonce: int, - delegation_contract: IAddress) -> Transaction: + delegation_contract: Address) -> Transaction: transaction = self.factory.create_transaction_for_claiming_rewards( sender=sender.address, delegation_contract=delegation_contract @@ -284,9 +286,9 @@ def create_transaction_for_claiming_rewards(self, return transaction def create_transaction_for_redelegating_rewards(self, - sender: IAccount, + sender: Account, nonce: int, - delegation_contract: IAddress) -> Transaction: + delegation_contract: Address) -> Transaction: transaction = self.factory.create_transaction_for_redelegating_rewards( sender=sender.address, delegation_contract=delegation_contract @@ -298,9 +300,9 @@ def create_transaction_for_redelegating_rewards(self, return transaction def create_transaction_for_undelegating(self, - sender: IAccount, + sender: Account, nonce: int, - delegation_contract: IAddress, + delegation_contract: Address, amount: int) -> Transaction: transaction = self.factory.create_transaction_for_undelegating( sender=sender.address, @@ -314,9 +316,9 @@ def create_transaction_for_undelegating(self, return transaction def create_transaction_for_withdrawing(self, - sender: IAccount, + sender: Account, nonce: int, - delegation_contract: IAddress) -> Transaction: + delegation_contract: Address) -> Transaction: transaction = self.factory.create_transaction_for_withdrawing( sender=sender.address, delegation_contract=delegation_contract diff --git a/multiversx_sdk/controllers/interfaces.py b/multiversx_sdk/controllers/interfaces.py index 78a4f7fa..86f37f93 100644 --- a/multiversx_sdk/controllers/interfaces.py +++ b/multiversx_sdk/controllers/interfaces.py @@ -1,12 +1,19 @@ from typing import Any, List, Optional, Protocol, Union -from multiversx_sdk.core.interfaces import IAddress from multiversx_sdk.core.smart_contract_query import ( SmartContractQuery, SmartContractQueryResponse) from multiversx_sdk.core.transaction_on_network import TransactionOnNetwork from multiversx_sdk.network_providers.resources import AwaitingOptions +class IAddress(Protocol): + def to_bech32(self) -> str: + ... + + def to_hex(self) -> str: + ... + + class IAccount(Protocol): @property def address(self) -> IAddress: diff --git a/multiversx_sdk/controllers/relayed_controller.py b/multiversx_sdk/controllers/relayed_controller.py index 6ba2de68..4e36948a 100644 --- a/multiversx_sdk/controllers/relayed_controller.py +++ b/multiversx_sdk/controllers/relayed_controller.py @@ -1,10 +1,10 @@ -from multiversx_sdk.controllers.interfaces import IAccount -from multiversx_sdk.core.interfaces import ITransaction from multiversx_sdk.core.transaction import Transaction from multiversx_sdk.core.transaction_computer import TransactionComputer from multiversx_sdk.core.transactions_factories import ( RelayedTransactionsFactory, TransactionsFactoryConfig) +from multiversx_sdk.core.account import Account + class RelayedController: """The transactions are created from the perspective of the relayer. The 'sender' represents the relayer.""" @@ -14,9 +14,9 @@ def __init__(self, chain_id: str) -> None: self.tx_computer = TransactionComputer() def create_relayed_v1_transaction(self, - sender: IAccount, + sender: Account, nonce: int, - inner_transaction: ITransaction) -> Transaction: + inner_transaction: Transaction) -> Transaction: transaction = self.factory.create_relayed_v1_transaction( inner_transaction=inner_transaction, relayer_address=sender.address @@ -28,9 +28,9 @@ def create_relayed_v1_transaction(self, return transaction def create_relayed_v2_transaction(self, - sender: IAccount, + sender: Account, nonce: int, - inner_transaction: ITransaction, + inner_transaction: Transaction, inner_transaction_gas_limit: int) -> Transaction: transaction = self.factory.create_relayed_v2_transaction( inner_transaction=inner_transaction, diff --git a/multiversx_sdk/controllers/smart_contract_controller.py b/multiversx_sdk/controllers/smart_contract_controller.py index 6a6b079c..a5f65bd3 100644 --- a/multiversx_sdk/controllers/smart_contract_controller.py +++ b/multiversx_sdk/controllers/smart_contract_controller.py @@ -1,9 +1,8 @@ from pathlib import Path from typing import Any, List, Optional, Sequence, Union -from multiversx_sdk.controllers.interfaces import (IAbi, IAccount, - INetworkProvider) -from multiversx_sdk.core.interfaces import IAddress +from multiversx_sdk.controllers.interfaces import IAbi, INetworkProvider +from multiversx_sdk.core.address import Address from multiversx_sdk.core.smart_contract_queries_controller import \ SmartContractQueriesController from multiversx_sdk.core.tokens import TokenTransfer @@ -14,12 +13,14 @@ SmartContractTransactionsFactory, TransactionsFactoryConfig) from multiversx_sdk.core.transactions_outcome_parsers import ( SmartContractDeployOutcome, SmartContractTransactionsOutcomeParser) +from multiversx_sdk.core.account import Account class SmartContractController: def __init__(self, chain_id: str, network_provider: INetworkProvider, abi: Optional[IAbi] = None) -> None: self.abi = abi - self.factory = SmartContractTransactionsFactory(TransactionsFactoryConfig(chain_id)) + self.factory = SmartContractTransactionsFactory( + TransactionsFactoryConfig(chain_id)) self.parser = SmartContractTransactionsOutcomeParser() self.query_controller = SmartContractQueriesController( network_provider=network_provider, @@ -29,7 +30,7 @@ def __init__(self, chain_id: str, network_provider: INetworkProvider, abi: Optio self.tx_computer = TransactionComputer() def create_transaction_for_deploy(self, - sender: IAccount, + sender: Account, nonce: int, bytecode: Union[Path, bytes], gas_limit: int, @@ -52,7 +53,8 @@ def create_transaction_for_deploy(self, ) transaction.nonce = nonce - transaction.signature = sender.sign(self.tx_computer.compute_bytes_for_signing(transaction)) + transaction.signature = sender.sign( + self.tx_computer.compute_bytes_for_signing(transaction)) return transaction @@ -60,13 +62,14 @@ def parse_deploy(self, transaction_on_network: TransactionOnNetwork) -> SmartCon return self.parser.parse_deploy(transaction_on_network) def await_completed_deploy(self, transaction_hash: Union[str, bytes]) -> SmartContractDeployOutcome: - transaction = self.network_provider.await_transaction_completed(transaction_hash) + transaction = self.network_provider.await_transaction_completed( + transaction_hash) return self.parse_deploy(transaction) def create_transaction_for_upgrade(self, - sender: IAccount, + sender: Account, nonce: int, - contract: IAddress, + contract: Address, bytecode: Union[Path, bytes], gas_limit: int, arguments: Sequence[Any] = [], @@ -94,9 +97,9 @@ def create_transaction_for_upgrade(self, return transaction def create_transaction_for_execute(self, - sender: IAccount, + sender: Account, nonce: int, - contract: IAddress, + contract: Address, gas_limit: int, function: str, arguments: Sequence[Any] = [], @@ -124,10 +127,10 @@ def await_completed_execute(self, transaction_hash: Union[str, bytes]) -> List[A raise NotImplementedError("This feature is not yet implemented") def query_contract(self, - contract: IAddress, + contract: Address, function: str, arguments: List[Any], - caller: Optional[IAddress] = None, + caller: Optional[Address] = None, value: Optional[int] = None) -> List[Any]: return self.query_controller.query( contract=contract.to_bech32(), diff --git a/multiversx_sdk/controllers/token_management_controller.py b/multiversx_sdk/controllers/token_management_controller.py index 40539d5d..b19fa613 100644 --- a/multiversx_sdk/controllers/token_management_controller.py +++ b/multiversx_sdk/controllers/token_management_controller.py @@ -1,9 +1,8 @@ from typing import List, Union -from multiversx_sdk.controllers.interfaces import IAccount, INetworkProvider +from multiversx_sdk.controllers.interfaces import INetworkProvider from multiversx_sdk.converters.transactions_converter import \ TransactionsConverter -from multiversx_sdk.core.interfaces import IAddress from multiversx_sdk.core.transaction import Transaction from multiversx_sdk.core.transaction_computer import TransactionComputer from multiversx_sdk.core.transaction_on_network import TransactionOnNetwork @@ -17,6 +16,10 @@ TokenManagementTransactionsOutcomeParser, UnFreezeOutcome, UnPauseOutcome, UpdateAttributesOutcome, WipeOutcome) +from multiversx_sdk.core.account import Account + +from multiversx_sdk.core.address import Address + class TokenManagementController: def __init__(self, chain_id: str, network_provider: INetworkProvider) -> None: @@ -27,7 +30,7 @@ def __init__(self, chain_id: str, network_provider: INetworkProvider) -> None: self.parser = TokenManagementTransactionsOutcomeParser() def create_transaction_for_issuing_fungible(self, - sender: IAccount, + sender: Account, nonce: int, token_name: str, token_ticker: str, @@ -66,7 +69,7 @@ def await_completed_issue_fungible(self, transaction_hash: Union[str, bytes]) -> return self.parse_issue_fungible(transaction) def create_transaction_for_issuing_semi_fungible(self, - sender: IAccount, + sender: Account, nonce: int, token_name: str, token_ticker: str, @@ -104,7 +107,7 @@ def await_completed_issue_semi_fungible( return self.parse_issue_semi_fungible(transaction) def create_transaction_for_issuing_non_fungible(self, - sender: IAccount, + sender: Account, nonce: int, token_name: str, token_ticker: str, @@ -141,7 +144,7 @@ def await_completed_issue_non_fungible(self, transaction_hash: Union[str, bytes] return self.parse_issue_non_fungible(transaction) def create_transaction_for_registering_meta_esdt(self, - sender: IAccount, + sender: Account, nonce: int, token_name: str, token_ticker: str, @@ -180,7 +183,7 @@ def await_completed_register_meta_esdt(self, transaction_hash: Union[str, bytes] return self.parse_register_meta_esdt(transaction) def create_transaction_for_registering_and_setting_roles(self, - sender: IAccount, + sender: Account, nonce: int, token_name: str, token_ticker: str, @@ -209,7 +212,7 @@ def await_completed_register_and_set_all_roles( return self.parse_register_and_set_all_roles(transaction) def create_transaction_for_setting_burn_role_globally(self, - sender: IAccount, + sender: Account, nonce: int, token_identifier: str) -> Transaction: transaction = self.factory.create_transaction_for_setting_burn_role_globally( @@ -230,7 +233,7 @@ def await_completed_set_burn_role_globally(self, transaction_hash: Union[str, by return self.parse_set_burn_role_globally(transaction) def create_transaction_for_unsetting_burn_role_globally(self, - sender: IAccount, + sender: Account, nonce: int, token_identifier: str) -> Transaction: transaction = self.factory.create_transaction_for_unsetting_burn_role_globally( @@ -251,9 +254,9 @@ def await_completed_unset_burn_role_globally(self, transaction_hash: Union[str, return self.parse_unset_burn_role_globally(transaction) def create_transaction_for_setting_special_role_on_fungible_token(self, - sender: IAccount, + sender: Account, nonce: int, - user: IAddress, + user: Address, token_identifier: str, add_role_local_mint: bool, add_role_local_burn: bool, @@ -282,7 +285,7 @@ def await_completed_set_special_role_on_fungible_token( return self.parse_set_special_role_on_fungible_token(transaction) def create_transaction_for_setting_special_role_on_semi_fungible_token( - self, sender: IAccount, nonce: int, user: IAddress, token_identifier: str, add_role_nft_create: bool, + self, sender: Account, nonce: int, user: Address, token_identifier: str, add_role_nft_create: bool, add_role_nft_burn: bool, add_role_nft_add_quantity: bool, add_role_esdt_transfer_role: bool) -> Transaction: transaction = self.factory.create_transaction_for_setting_special_role_on_semi_fungible_token( sender=sender.address, @@ -309,7 +312,7 @@ def await_completed_set_special_role_on_semi_fungible_token( return self.parse_set_special_role_on_semi_fungible_token(transaction) def create_transaction_for_setting_special_role_on_non_fungible_token( - self, sender: IAccount, nonce: int, user: IAddress, token_identifier: str, add_role_nft_create: bool, + self, sender: Account, nonce: int, user: Address, token_identifier: str, add_role_nft_create: bool, add_role_nft_burn: bool, add_role_nft_update_attributes: bool, add_role_nft_add_uri: bool, add_role_esdt_transfer_role: bool) -> Transaction: transaction = self.factory.create_transaction_for_setting_special_role_on_non_fungible_token( @@ -338,7 +341,7 @@ def await_completed_set_special_role_on_non_fungible_token( return self.parse_set_special_role_on_non_fungible_token(transaction) def create_transaction_for_creating_nft(self, - sender: IAccount, + sender: Account, nonce: int, token_identifier: str, initial_quantity: int, @@ -371,7 +374,7 @@ def await_completed_create_nft(self, transaction_hash: Union[str, bytes]) -> Lis return self.parse_create_nft(transaction) def create_transaction_for_pausing(self, - sender: IAccount, + sender: Account, nonce: int, token_identifier: str) -> Transaction: transaction = self.factory.create_transaction_for_pausing( @@ -392,7 +395,7 @@ def await_completed_pause(self, transaction_hash: Union[str, bytes]) -> List[Pau return self.parse_pause(transaction) def create_transaction_for_unpausing(self, - sender: IAccount, + sender: Account, nonce: int, token_identifier: str) -> Transaction: transaction = self.factory.create_transaction_for_unpausing( @@ -413,9 +416,9 @@ def await_completed_unpause(self, transaction_hash: Union[str, bytes]) -> List[U return self.parse_unpause(transaction) def create_transaction_for_freezing(self, - sender: IAccount, + sender: Account, nonce: int, - user: IAddress, + user: Address, token_identifier: str) -> Transaction: transaction = self.factory.create_transaction_for_freezing( sender=sender.address, @@ -436,9 +439,9 @@ def await_completed_freeze(self, transaction_hash: Union[str, bytes]) -> List[Fr return self.parse_freeze(transaction) def create_transaction_for_unfreezing(self, - sender: IAccount, + sender: Account, nonce: int, - user: IAddress, + user: Address, token_identifier: str) -> Transaction: transaction = self.factory.create_transaction_for_unfreezing( sender=sender.address, @@ -459,9 +462,9 @@ def await_completed_unfreeze(self, transaction_hash: Union[str, bytes]) -> List[ return self.parse_unfreeze(transaction) def create_transaction_for_wiping(self, - sender: IAccount, + sender: Account, nonce: int, - user: IAddress, + user: Address, token_identifier: str) -> Transaction: transaction = self.factory.create_transaction_for_wiping( sender=sender.address, @@ -482,7 +485,7 @@ def await_completed_wipe(self, transaction_hash: Union[str, bytes]) -> List[Wipe return self.parse_wipe(transaction) def create_transaction_for_local_minting(self, - sender: IAccount, + sender: Account, nonce: int, token_identifier: str, supply_to_mint: int) -> Transaction: @@ -505,7 +508,7 @@ def await_completed_local_mint(self, transaction_hash: Union[str, bytes]) -> Lis return self.parse_local_mint(transaction) def create_transaction_for_local_burning(self, - sender: IAccount, + sender: Account, nonce: int, token_identifier: str, supply_to_burn: int) -> Transaction: @@ -528,7 +531,7 @@ def await_completed_local_burn(self, transaction_hash: Union[str, bytes]) -> Lis return self.parse_local_burn(transaction) def create_transaction_for_updating_attributes(self, - sender: IAccount, + sender: Account, nonce: int, token_identifier: str, token_nonce: int, @@ -553,7 +556,7 @@ def await_completed_update_attributes(self, transaction_hash: Union[str, bytes]) return self.parse_update_attributes(transaction) def create_transaction_for_adding_quantity(self, - sender: IAccount, + sender: Account, nonce: int, token_identifier: str, token_nonce: int, @@ -578,7 +581,7 @@ def await_completed_add_quantity(self, transaction_hash: Union[str, bytes]) -> L return self.parse_add_quantity(transaction) def create_transaction_for_burning_quantity(self, - sender: IAccount, + sender: Account, nonce: int, token_identifier: str, token_nonce: int, diff --git a/multiversx_sdk/controllers/transfers_controller.py b/multiversx_sdk/controllers/transfers_controller.py index d4c6638e..d9a5f36d 100644 --- a/multiversx_sdk/controllers/transfers_controller.py +++ b/multiversx_sdk/controllers/transfers_controller.py @@ -1,13 +1,15 @@ from typing import List, Optional -from multiversx_sdk.controllers.interfaces import IAccount -from multiversx_sdk.core.interfaces import IAddress from multiversx_sdk.core.tokens import TokenTransfer from multiversx_sdk.core.transaction import Transaction from multiversx_sdk.core.transaction_computer import TransactionComputer from multiversx_sdk.core.transactions_factories import ( TransactionsFactoryConfig, TransferTransactionsFactory) +from multiversx_sdk.core.account import Account + +from multiversx_sdk.core.address import Address + class TransfersController: def __init__(self, chain_id: str) -> None: @@ -15,9 +17,9 @@ def __init__(self, chain_id: str) -> None: self.tx_computer = TransactionComputer() def create_transaction_for_native_token_transfer(self, - sender: IAccount, + sender: Account, nonce: int, - receiver: IAddress, + receiver: Address, native_transfer_amount: int = 0, data: Optional[bytes] = None) -> Transaction: transaction = self.factory.create_transaction_for_native_token_transfer( @@ -33,9 +35,9 @@ def create_transaction_for_native_token_transfer(self, return transaction def create_transaction_for_esdt_token_transfer(self, - sender: IAccount, + sender: Account, nonce: int, - receiver: IAddress, + receiver: Address, token_transfers: List[TokenTransfer]) -> Transaction: transaction = self.factory.create_transaction_for_esdt_token_transfer( sender=sender.address, @@ -49,9 +51,9 @@ def create_transaction_for_esdt_token_transfer(self, return transaction def create_transaction_for_transfer(self, - sender: IAccount, + sender: Account, nonce: int, - receiver: IAddress, + receiver: Address, native_transfer_amount: Optional[int] = None, token_transfers: Optional[List[TokenTransfer]] = None, data: Optional[bytes] = None) -> Transaction: diff --git a/multiversx_sdk/converters/transactions_converter.py b/multiversx_sdk/converters/transactions_converter.py index dbf12c0d..7bbc7e7c 100644 --- a/multiversx_sdk/converters/transactions_converter.py +++ b/multiversx_sdk/converters/transactions_converter.py @@ -2,7 +2,6 @@ from typing import Any, Dict, Union from multiversx_sdk.converters.errors import MissingFieldError -from multiversx_sdk.core.interfaces import ITransaction from multiversx_sdk.core.transaction import Transaction @@ -10,7 +9,7 @@ class TransactionsConverter: def __init__(self) -> None: pass - def transaction_to_dictionary(self, transaction: ITransaction) -> Dict[str, Any]: + def transaction_to_dictionary(self, transaction: Transaction) -> Dict[str, Any]: return { "nonce": transaction.nonce, "value": str(transaction.value), diff --git a/multiversx_sdk/converters/transactions_converter_test.py b/multiversx_sdk/converters/transactions_converter_test.py index 9b34607c..4ba2cf43 100644 --- a/multiversx_sdk/converters/transactions_converter_test.py +++ b/multiversx_sdk/converters/transactions_converter_test.py @@ -2,6 +2,8 @@ TransactionsConverter from multiversx_sdk.core.transaction import Transaction +from multiversx_sdk.core.address import Address + def test_transaction_converter(): converter = TransactionsConverter() @@ -9,8 +11,8 @@ def test_transaction_converter(): transaction = Transaction( nonce=90, value=123456789000000000000000000000, - sender="erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th", - receiver="erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx", + sender=Address.new_from_bech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"), + receiver=Address.new_from_bech32("erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx"), sender_username="alice", receiver_username="bob", gas_price=1000000000, diff --git a/multiversx_sdk/core/account.py b/multiversx_sdk/core/account.py index b0bb5faf..f74d0e22 100644 --- a/multiversx_sdk/core/account.py +++ b/multiversx_sdk/core/account.py @@ -1,3 +1,10 @@ +from multiversx_sdk.wallet.user_wallet import UserWallet +from multiversx_sdk.wallet.user_signer import UserSigner +from multiversx_sdk.wallet.mnemonic import Mnemonic +from multiversx_sdk.core.constants import DEFAULT_HRP +from pathlib import Path + + class AccountNonceHolder(): """An abstraction representing an account's nonce on the Network.""" @@ -20,3 +27,43 @@ def get_nonce_then_increment(self) -> int: def increment_nonce(self): """Increments the current nonce""" self.nonce += 1 + + +class Account: + def __init__(self, signer: UserSigner, hrp: str = DEFAULT_HRP) -> None: + self.signer = signer + self.address = signer.get_pubkey().to_address(hrp) + self.nonce = 0 + + @classmethod + def new_from_pem(cls, file_path: Path, index: int = 0, hrp: str = DEFAULT_HRP) -> "Account": + signer = UserSigner.from_pem_file(file_path, index) + return Account(signer, hrp) + + @classmethod + def new_from_keystore(cls, + file_path: Path, + password: str, + address_index: int = 0, + hrp: str = DEFAULT_HRP) -> "Account": + secret_key = UserWallet.load_secret_key( + file_path, password, address_index) + signer = UserSigner(secret_key) + return Account(signer, hrp) + + @classmethod + def new_from_mnemonic(cls, + mnemonic: str, + address_index: int = 0, + hrp: str = DEFAULT_HRP) -> "Account": + mnemonic_handler = Mnemonic(mnemonic) + secret_key = mnemonic_handler.derive_key(address_index) + return Account(UserSigner(secret_key), hrp) + + def sign(self, data: bytes) -> bytes: + return self.signer.sign(data) + + def get_nonce_then_increment(self) -> int: + nonce = self.nonce + self.nonce += 1 + return nonce diff --git a/multiversx_sdk/core/address.py b/multiversx_sdk/core/address.py index e7452614..a2f0ff2f 100644 --- a/multiversx_sdk/core/address.py +++ b/multiversx_sdk/core/address.py @@ -1,5 +1,4 @@ import logging -from typing import Protocol, Tuple from Cryptodome.Hash import keccak @@ -9,20 +8,14 @@ SC_HEX_PUBKEY_PREFIX = "0" * 16 PUBKEY_LENGTH = 32 + +# can be deleted PUBKEY_STRING_LENGTH = PUBKEY_LENGTH * 2 # hex-encoded BECH32_LENGTH = 62 logger = logging.getLogger("address") -class IAddress(Protocol): - def get_public_key(self) -> bytes: - ... - - def get_hrp(self) -> str: - ... - - class Address: """An Address, as an immutable object.""" @@ -144,11 +137,11 @@ def __init__(self, number_of_shards: int = 3) -> None: number_of_shards (int): The number of shards in the network (default: 3).""" self.number_of_shards = number_of_shards - def compute_contract_address(self, deployer: IAddress, deployment_nonce: int) -> Address: + def compute_contract_address(self, deployer: Address, deployment_nonce: int) -> Address: """Computes the contract address based on the deployer's address and deployment nonce. Args: - deployer (IAddress): The address of the deployer\n + deployer (Address): The address of the deployer\n deployment_nonce (int): The nonce of the deployment Returns: @@ -162,11 +155,11 @@ def compute_contract_address(self, deployer: IAddress, deployment_nonce: int) -> contract_pubkey = bytes([0] * 8) + bytes([5, 0]) + contract_pubkey[10:30] + deployer_pubkey[30:] return Address(contract_pubkey, deployer.get_hrp()) - def get_shard_of_address(self, address: IAddress) -> int: + def get_shard_of_address(self, address: Address) -> int: """Returns the shard number of a given address. Args: - address (IAddress): The address for which to determine the shard. + address (Address): The address for which to determine the shard. Returns: int: The shard number.""" @@ -178,7 +171,7 @@ def is_valid_bech32(value: str, expected_hrp: str) -> bool: return hrp == expected_hrp and value_bytes is not None -def _decode_bech32(value: str) -> Tuple[str, bytes]: +def _decode_bech32(value: str) -> tuple[str, bytes]: hrp, value_bytes = bech32.bech32_decode(value) if hrp is None or value_bytes is None: raise ErrBadAddress(value) @@ -207,7 +200,8 @@ def get_shard_of_pubkey(pubkey: bytes, number_of_shards: int) -> int: def _is_pubkey_of_metachain(pubkey: bytes) -> bool: - metachain_prefix = bytearray([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) + metachain_prefix = bytearray( + [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) pubkey_prefix = pubkey[0:len(metachain_prefix)] if pubkey_prefix == bytes(metachain_prefix): return True diff --git a/multiversx_sdk/core/interfaces.py b/multiversx_sdk/core/interfaces.py index f86a9616..37563fbe 100644 --- a/multiversx_sdk/core/interfaces.py +++ b/multiversx_sdk/core/interfaces.py @@ -1,38 +1,4 @@ -from typing import Optional, Protocol - - -class IAddress(Protocol): - def to_bech32(self) -> str: - ... - - def to_hex(self) -> str: - ... - - -class ITransaction(Protocol): - sender: str - receiver: str - gas_limit: int - chain_id: str - nonce: int - value: int - sender_username: str - receiver_username: str - gas_price: int - data: bytes - version: int - options: int - guardian: str - signature: bytes - guardian_signature: bytes - - -class IMessage(Protocol): - data: bytes - signature: bytes - address: Optional[IAddress] - version: int - signer: str +from typing import Protocol class IToken(Protocol): diff --git a/multiversx_sdk/core/message.py b/multiversx_sdk/core/message.py index 5cb9e826..24384380 100644 --- a/multiversx_sdk/core/message.py +++ b/multiversx_sdk/core/message.py @@ -5,14 +5,13 @@ from multiversx_sdk.core.address import Address from multiversx_sdk.core.constants import (DEFAULT_MESSAGE_VERSION, SDK_PY_SIGNER, UNKNOWN_SIGNER) -from multiversx_sdk.core.interfaces import IAddress, IMessage class Message: def __init__(self, data: bytes, signature: bytes = b"", - address: Optional[IAddress] = None, + address: Optional[Address] = None, version: int = DEFAULT_MESSAGE_VERSION, signer: str = SDK_PY_SIGNER) -> None: self.data = data @@ -32,7 +31,7 @@ class MessageComputer: def __init__(self) -> None: pass - def compute_bytes_for_signing(self, message: IMessage) -> bytes: + def compute_bytes_for_signing(self, message: Message) -> bytes: PREFIX = bytes.fromhex("17456c726f6e64205369676e6564204d6573736167653a0a") size = str(len(message.data)).encode() content = PREFIX + size + message.data @@ -40,10 +39,10 @@ def compute_bytes_for_signing(self, message: IMessage) -> bytes: return content_hash - def compute_bytes_for_verifying(self, message: IMessage) -> bytes: + def compute_bytes_for_verifying(self, message: Message) -> bytes: return self.compute_bytes_for_signing(message) - def pack_message(self, message: IMessage) -> Dict[str, Any]: + def pack_message(self, message: Message) -> Dict[str, Any]: return { "address": message.address.to_bech32() if message.address else "", "message": message.data.hex(), diff --git a/multiversx_sdk/core/proto/transaction_serializer.py b/multiversx_sdk/core/proto/transaction_serializer.py index b0176a0e..713f7c34 100644 --- a/multiversx_sdk/core/proto/transaction_serializer.py +++ b/multiversx_sdk/core/proto/transaction_serializer.py @@ -1,37 +1,15 @@ -from typing import Protocol - import multiversx_sdk.core.proto.transaction_pb2 as ProtoTransaction -from multiversx_sdk.core.address import Address from multiversx_sdk.core.codec import encode_unsigned_number - - -class ITransaction(Protocol): - sender: str - receiver: str - gas_limit: int - chain_id: str - nonce: int - value: int - sender_username: str - receiver_username: str - gas_price: int - data: bytes - version: int - options: int - guardian: str - signature: bytes - guardian_signature: bytes +from multiversx_sdk.core.transaction import Transaction class ProtoSerializer: def __init__(self) -> None: pass - def serialize_transaction(self, transaction: ITransaction) -> bytes: + def serialize_transaction(self, transaction: Transaction) -> bytes: proto_transaction = self.convert_to_proto_message(transaction) - - encoded_tx: bytes = proto_transaction.SerializeToString() - return encoded_tx + return proto_transaction.SerializeToString() def serialize_transaction_value(self, tx_value: int): if tx_value == 0: @@ -42,9 +20,9 @@ def serialize_transaction_value(self, tx_value: int): return buffer - def convert_to_proto_message(self, transaction: ITransaction) -> ProtoTransaction.Transaction: - receiver_pubkey = Address.new_from_bech32(transaction.receiver).get_public_key() - sender_pubkey = Address.new_from_bech32(transaction.sender).get_public_key() + def convert_to_proto_message(self, transaction: Transaction) -> ProtoTransaction.Transaction: + receiver_pubkey = transaction.receiver.get_public_key() + sender_pubkey = transaction.sender.get_public_key() proto_transaction = ProtoTransaction.Transaction() proto_transaction.Nonce = transaction.nonce @@ -63,7 +41,7 @@ def convert_to_proto_message(self, transaction: ITransaction) -> ProtoTransactio if transaction.guardian: guardian_address = transaction.guardian - proto_transaction.GuardAddr = Address.new_from_bech32(guardian_address).get_public_key() + proto_transaction.GuardAddr = guardian_address.get_public_key() proto_transaction.GuardSignature = transaction.guardian_signature return proto_transaction diff --git a/multiversx_sdk/core/proto/transaction_serializer_test.py b/multiversx_sdk/core/proto/transaction_serializer_test.py index 1ec470a9..d92ee727 100644 --- a/multiversx_sdk/core/proto/transaction_serializer_test.py +++ b/multiversx_sdk/core/proto/transaction_serializer_test.py @@ -3,6 +3,8 @@ from multiversx_sdk.core.transaction_computer import TransactionComputer from multiversx_sdk.testutils.wallets import load_wallets +from multiversx_sdk.core.address import Address + class TestProtoSerializer: wallets = load_wallets() @@ -14,8 +16,8 @@ class TestProtoSerializer: def test_serialize_tx_no_data_no_value(self): transaction = Transaction( - sender=self.alice.label, - receiver=self.bob.label, + sender=Address.new_from_bech32(self.alice.label), + receiver=Address.new_from_bech32(self.bob.label), gas_limit=50000, chain_id="local-testnet", nonce=89, @@ -28,8 +30,8 @@ def test_serialize_tx_no_data_no_value(self): def test_serialize_tx_with_data_no_value(self): transaction = Transaction( - sender=self.alice.label, - receiver=self.bob.label, + sender=Address.new_from_bech32(self.alice.label), + receiver=Address.new_from_bech32(self.bob.label), gas_limit=80000, chain_id="local-testnet", data=b"hello", @@ -42,8 +44,8 @@ def test_serialize_tx_with_data_no_value(self): def test_serialize_tx_with_data_and_value(self): transaction = Transaction( - sender=self.alice.label, - receiver=self.bob.label, + sender=Address.new_from_bech32(self.alice.label), + receiver=Address.new_from_bech32(self.bob.label), gas_limit=100000, chain_id="local-testnet", nonce=92, @@ -57,8 +59,8 @@ def test_serialize_tx_with_data_and_value(self): def test_serialize_tx_with_nonce_zero(self): transaction = Transaction( - sender=self.alice.label, - receiver=self.bob.label, + sender=Address.new_from_bech32(self.alice.label), + receiver=Address.new_from_bech32(self.bob.label), chain_id="local-testnet", gas_limit=80000, nonce=0, @@ -73,8 +75,8 @@ def test_serialize_tx_with_nonce_zero(self): def test_serialized_tx_with_usernames(self): transaction = Transaction( - sender=self.carol.label, - receiver=self.alice.label, + sender=Address.new_from_bech32(self.carol.label), + receiver=Address.new_from_bech32(self.alice.label), gas_limit=50000, chain_id="T", nonce=204, diff --git a/multiversx_sdk/core/transaction.py b/multiversx_sdk/core/transaction.py index 0f87e289..af52fa44 100644 --- a/multiversx_sdk/core/transaction.py +++ b/multiversx_sdk/core/transaction.py @@ -1,5 +1,6 @@ from typing import Optional +from multiversx_sdk.core.address import Address from multiversx_sdk.core.constants import (TRANSACTION_MIN_GAS_PRICE, TRANSACTION_OPTIONS_DEFAULT, TRANSACTION_VERSION_DEFAULT) @@ -7,8 +8,8 @@ class Transaction: def __init__(self, - sender: str, - receiver: str, + sender: Address, + receiver: Address, gas_limit: int, chain_id: str, nonce: Optional[int] = None, @@ -19,7 +20,7 @@ def __init__(self, data: Optional[bytes] = None, version: Optional[int] = None, options: Optional[int] = None, - guardian: Optional[str] = None, + guardian: Optional[Address] = None, signature: Optional[bytes] = None, guardian_signature: Optional[bytes] = None) -> None: self.chain_id = chain_id @@ -39,10 +40,11 @@ def __init__(self, self.version = version or TRANSACTION_VERSION_DEFAULT self.options = options or TRANSACTION_OPTIONS_DEFAULT - self.guardian = guardian or "" + self.guardian = guardian self.guardian_signature = guardian_signature or bytes() def __eq__(self, other: object) -> bool: + # don;t think this is properly working if not isinstance(other, Transaction): return False diff --git a/multiversx_sdk/core/transaction_computer.py b/multiversx_sdk/core/transaction_computer.py index 647c1b99..94ef1ba4 100644 --- a/multiversx_sdk/core/transaction_computer.py +++ b/multiversx_sdk/core/transaction_computer.py @@ -11,16 +11,20 @@ MIN_TRANSACTION_VERSION_THAT_SUPPORTS_OPTIONS, TRANSACTION_OPTIONS_TX_GUARDED, TRANSACTION_OPTIONS_TX_HASH_SIGN) from multiversx_sdk.core.errors import BadUsageError, NotEnoughGasError -from multiversx_sdk.core.interfaces import INetworkConfig, ITransaction +from multiversx_sdk.core.interfaces import INetworkConfig from multiversx_sdk.core.proto.transaction_serializer import ProtoSerializer +from multiversx_sdk.core.transaction import Transaction + +from multiversx_sdk.core.address import Address class TransactionComputer: def __init__(self) -> None: pass - def compute_transaction_fee(self, transaction: ITransaction, network_config: INetworkConfig) -> int: - move_balance_gas = network_config.min_gas_limit + len(transaction.data) * network_config.gas_per_data_byte + def compute_transaction_fee(self, transaction: Transaction, network_config: INetworkConfig) -> int: + move_balance_gas = network_config.min_gas_limit + \ + len(transaction.data) * network_config.gas_per_data_byte if move_balance_gas > transaction.gas_limit: raise NotEnoughGasError(transaction.gas_limit) @@ -34,14 +38,14 @@ def compute_transaction_fee(self, transaction: ITransaction, network_config: INe return int(fee_for_move + processing_fee) - def compute_bytes_for_signing(self, transaction: ITransaction) -> bytes: + def compute_bytes_for_signing(self, transaction: Transaction) -> bytes: self._ensure_fields(transaction) dictionary = self._to_dictionary(transaction) serialized = self._dict_to_json(dictionary) return serialized - def compute_bytes_for_verifying(self, transaction: ITransaction) -> bytes: + def compute_bytes_for_verifying(self, transaction: Transaction) -> bytes: is_signed_by_hash = self.has_options_set_for_hash_signing(transaction) if is_signed_by_hash: @@ -49,39 +53,39 @@ def compute_bytes_for_verifying(self, transaction: ITransaction) -> bytes: return self.compute_bytes_for_signing(transaction) - def compute_hash_for_signing(self, transaction: ITransaction) -> bytes: + def compute_hash_for_signing(self, transaction: Transaction) -> bytes: return keccak.new(digest_bits=256).update(self.compute_bytes_for_signing(transaction)).digest() - def compute_transaction_hash(self, transaction: ITransaction) -> bytes: + def compute_transaction_hash(self, transaction: Transaction) -> bytes: proto = ProtoSerializer() serialized_tx = proto.serialize_transaction(transaction) tx_hash = blake2b(serialized_tx, digest_size=DIGEST_SIZE).hexdigest() return bytes.fromhex(tx_hash) - def has_options_set_for_guarded_transaction(self, transaction: ITransaction) -> bool: + def has_options_set_for_guarded_transaction(self, transaction: Transaction) -> bool: return (transaction.options & TRANSACTION_OPTIONS_TX_GUARDED) == TRANSACTION_OPTIONS_TX_GUARDED - def has_options_set_for_hash_signing(self, transaction: ITransaction) -> bool: + def has_options_set_for_hash_signing(self, transaction: Transaction) -> bool: return (transaction.options & TRANSACTION_OPTIONS_TX_HASH_SIGN) == TRANSACTION_OPTIONS_TX_HASH_SIGN - def apply_guardian(self, transaction: ITransaction, guardian: str) -> None: + def apply_guardian(self, transaction: Transaction, guardian: Address) -> None: if transaction.version < MIN_TRANSACTION_VERSION_THAT_SUPPORTS_OPTIONS: transaction.version = MIN_TRANSACTION_VERSION_THAT_SUPPORTS_OPTIONS transaction.options = transaction.options | TRANSACTION_OPTIONS_TX_GUARDED transaction.guardian = guardian - def apply_options_for_hash_signing(self, transaction: ITransaction) -> None: + def apply_options_for_hash_signing(self, transaction: Transaction) -> None: if transaction.version < MIN_TRANSACTION_VERSION_THAT_SUPPORTS_OPTIONS: transaction.version = MIN_TRANSACTION_VERSION_THAT_SUPPORTS_OPTIONS transaction.options = transaction.options | TRANSACTION_OPTIONS_TX_HASH_SIGN - def _ensure_fields(self, transaction: ITransaction) -> None: - if len(transaction.sender) != BECH32_ADDRESS_LENGTH: + def _ensure_fields(self, transaction: Transaction) -> None: + if len(transaction.sender.to_bech32()) != BECH32_ADDRESS_LENGTH: raise BadUsageError("Invalid `sender` field. Should be the bech32 address of the sender.") - if len(transaction.receiver) != BECH32_ADDRESS_LENGTH: + if len(transaction.receiver.to_bech32()) != BECH32_ADDRESS_LENGTH: raise BadUsageError("Invalid `receiver` field. Should be the bech32 address of the receiver.") if not len(transaction.chain_id): @@ -91,7 +95,7 @@ def _ensure_fields(self, transaction: ITransaction) -> None: if self.has_options_set_for_guarded_transaction(transaction) or self.has_options_set_for_hash_signing(transaction): raise BadUsageError(f"Non-empty transaction options requires transaction version >= {MIN_TRANSACTION_VERSION_THAT_SUPPORTS_OPTIONS}") - def _to_dictionary(self, transaction: ITransaction, with_signature: bool = False) -> Dict[str, Any]: + def _to_dictionary(self, transaction: Transaction, with_signature: bool = False) -> Dict[str, Any]: dictionary: Dict[str, Any] = OrderedDict() dictionary["nonce"] = transaction.nonce dictionary["value"] = str(transaction.value) @@ -129,5 +133,4 @@ def _to_dictionary(self, transaction: ITransaction, with_signature: bool = False return dictionary def _dict_to_json(self, dictionary: Dict[str, Any]) -> bytes: - serialized = json.dumps(dictionary, separators=(',', ':')).encode("utf-8") - return serialized + return json.dumps(dictionary, separators=(',', ':')).encode("utf-8") diff --git a/multiversx_sdk/core/transactions_factories/account_transactions_factory.py b/multiversx_sdk/core/transactions_factories/account_transactions_factory.py index 61f251db..e62ab486 100644 --- a/multiversx_sdk/core/transactions_factories/account_transactions_factory.py +++ b/multiversx_sdk/core/transactions_factories/account_transactions_factory.py @@ -1,10 +1,11 @@ from typing import Dict, List, Protocol -from multiversx_sdk.core.interfaces import IAddress from multiversx_sdk.core.transaction import Transaction from multiversx_sdk.core.transactions_factories.transaction_builder import \ TransactionBuilder +from multiversx_sdk.core.address import Address + class IConfig(Protocol): chain_id: str @@ -24,7 +25,7 @@ def __init__(self, config: IConfig) -> None: def create_transaction_for_saving_key_value( self, - sender: IAddress, + sender: Address, key_value_pairs: Dict[bytes, bytes] ) -> Transaction: function = "SaveKeyValue" @@ -45,8 +46,8 @@ def create_transaction_for_saving_key_value( def create_transaction_for_setting_guardian( self, - sender: IAddress, - guardian_address: IAddress, + sender: Address, + guardian_address: Address, service_id: str ) -> Transaction: data_parts = [ @@ -64,7 +65,7 @@ def create_transaction_for_setting_guardian( add_data_movement_gas=True ).build() - def create_transaction_for_guarding_account(self, sender: IAddress) -> Transaction: + def create_transaction_for_guarding_account(self, sender: Address) -> Transaction: data_parts = ["GuardAccount"] return TransactionBuilder( @@ -76,7 +77,7 @@ def create_transaction_for_guarding_account(self, sender: IAddress) -> Transacti add_data_movement_gas=True ).build() - def create_transaction_for_unguarding_account(self, sender: IAddress) -> Transaction: + def create_transaction_for_unguarding_account(self, sender: Address) -> Transaction: data_parts = ["UnGuardAccount"] transaction = TransactionBuilder( diff --git a/multiversx_sdk/core/transactions_factories/delegation_transactions_factory.py b/multiversx_sdk/core/transactions_factories/delegation_transactions_factory.py index a189704c..0091d60d 100644 --- a/multiversx_sdk/core/transactions_factories/delegation_transactions_factory.py +++ b/multiversx_sdk/core/transactions_factories/delegation_transactions_factory.py @@ -3,7 +3,7 @@ from multiversx_sdk.core.address import Address from multiversx_sdk.core.constants import DELEGATION_MANAGER_SC_ADDRESS from multiversx_sdk.core.errors import ErrListsLengthMismatch -from multiversx_sdk.core.interfaces import IAddress, IValidatorPublicKey +from multiversx_sdk.core.interfaces import IValidatorPublicKey from multiversx_sdk.core.serializer import arg_to_string from multiversx_sdk.core.transaction import Transaction from multiversx_sdk.core.transactions_factories.transaction_builder import \ @@ -28,7 +28,7 @@ def __init__(self, config: IConfig) -> None: self.config = config def create_transaction_for_new_delegation_contract(self, - sender: IAddress, + sender: Address, total_delegation_cap: int, service_fee: int, amount: int) -> Transaction: @@ -51,8 +51,8 @@ def create_transaction_for_new_delegation_contract(self, return transaction def create_transaction_for_adding_nodes(self, - sender: IAddress, - delegation_contract: IAddress, + sender: Address, + delegation_contract: Address, public_keys: Sequence[IValidatorPublicKey], signed_messages: Sequence[bytes]) -> Transaction: if len(public_keys) != len(signed_messages): @@ -80,8 +80,8 @@ def _compute_execution_gas_limit_for_nodes_management(self, num_nodes: int) -> i return self.config.gas_limit_delegation_operations + num_nodes * self.config.additional_gas_limit_per_validator_node def create_transaction_for_removing_nodes(self, - sender: IAddress, - delegation_contract: IAddress, + sender: Address, + delegation_contract: Address, public_keys: Sequence[IValidatorPublicKey]) -> Transaction: num_nodes = len(public_keys) @@ -101,8 +101,8 @@ def create_transaction_for_removing_nodes(self, return transaction def create_transaction_for_staking_nodes(self, - sender: IAddress, - delegation_contract: IAddress, + sender: Address, + delegation_contract: Address, public_keys: Sequence[IValidatorPublicKey]) -> Transaction: num_nodes = len(public_keys) @@ -122,8 +122,8 @@ def create_transaction_for_staking_nodes(self, return transaction def create_transaction_for_unbonding_nodes(self, - sender: IAddress, - delegation_contract: IAddress, + sender: Address, + delegation_contract: Address, public_keys: Sequence[IValidatorPublicKey]) -> Transaction: num_nodes = len(public_keys) @@ -143,8 +143,8 @@ def create_transaction_for_unbonding_nodes(self, return transaction def create_transaction_for_unstaking_nodes(self, - sender: IAddress, - delegation_contract: IAddress, + sender: Address, + delegation_contract: Address, public_keys: Sequence[IValidatorPublicKey]) -> Transaction: num_nodes = len(public_keys) @@ -164,8 +164,8 @@ def create_transaction_for_unstaking_nodes(self, return transaction def create_transaction_for_unjailing_nodes(self, - sender: IAddress, - delegation_contract: IAddress, + sender: Address, + delegation_contract: Address, public_keys: Sequence[IValidatorPublicKey], amount: int) -> Transaction: num_nodes = len(public_keys) @@ -187,8 +187,8 @@ def create_transaction_for_unjailing_nodes(self, return transaction def create_transaction_for_changing_service_fee(self, - sender: IAddress, - delegation_contract: IAddress, + sender: Address, + delegation_contract: Address, service_fee: int) -> Transaction: parts = [ "changeServiceFee", @@ -207,8 +207,8 @@ def create_transaction_for_changing_service_fee(self, return transaction def create_transaction_for_modifying_delegation_cap(self, - sender: IAddress, - delegation_contract: IAddress, + sender: Address, + delegation_contract: Address, delegation_cap: int) -> Transaction: parts = [ "modifyTotalDelegationCap", @@ -227,8 +227,8 @@ def create_transaction_for_modifying_delegation_cap(self, return transaction def create_transaction_for_setting_automatic_activation(self, - sender: IAddress, - delegation_contract: IAddress) -> Transaction: + sender: Address, + delegation_contract: Address) -> Transaction: parts = [ "setAutomaticActivation", arg_to_string('true') @@ -246,8 +246,8 @@ def create_transaction_for_setting_automatic_activation(self, return transaction def create_transaction_for_unsetting_automatic_activation(self, - sender: IAddress, - delegation_contract: IAddress) -> Transaction: + sender: Address, + delegation_contract: Address) -> Transaction: parts = [ "setAutomaticActivation", arg_to_string('false') @@ -265,8 +265,8 @@ def create_transaction_for_unsetting_automatic_activation(self, return transaction def create_transaction_for_setting_cap_check_on_redelegate_rewards(self, - sender: IAddress, - delegation_contract: IAddress) -> Transaction: + sender: Address, + delegation_contract: Address) -> Transaction: parts = [ "setCheckCapOnReDelegateRewards", arg_to_string('true') @@ -284,8 +284,8 @@ def create_transaction_for_setting_cap_check_on_redelegate_rewards(self, return transaction def create_transaction_for_unsetting_cap_check_on_redelegate_rewards(self, - sender: IAddress, - delegation_contract: IAddress) -> Transaction: + sender: Address, + delegation_contract: Address) -> Transaction: parts = [ "setCheckCapOnReDelegateRewards", arg_to_string('false') @@ -303,8 +303,8 @@ def create_transaction_for_unsetting_cap_check_on_redelegate_rewards(self, return transaction def create_transaction_for_setting_metadata(self, - sender: IAddress, - delegation_contract: IAddress, + sender: Address, + delegation_contract: Address, name: str, website: str, identifier: str) -> Transaction: @@ -327,8 +327,8 @@ def create_transaction_for_setting_metadata(self, return transaction def create_transaction_for_delegating(self, - sender: IAddress, - delegation_contract: IAddress, + sender: Address, + delegation_contract: Address, amount: int) -> Transaction: return TransactionBuilder( config=self.config, @@ -341,8 +341,8 @@ def create_transaction_for_delegating(self, ).build() def create_transaction_for_claiming_rewards(self, - sender: IAddress, - delegation_contract: IAddress) -> Transaction: + sender: Address, + delegation_contract: Address) -> Transaction: return TransactionBuilder( config=self.config, sender=sender, @@ -354,8 +354,8 @@ def create_transaction_for_claiming_rewards(self, ).build() def create_transaction_for_redelegating_rewards(self, - sender: IAddress, - delegation_contract: IAddress) -> Transaction: + sender: Address, + delegation_contract: Address) -> Transaction: return TransactionBuilder( config=self.config, sender=sender, @@ -367,8 +367,8 @@ def create_transaction_for_redelegating_rewards(self, ).build() def create_transaction_for_undelegating(self, - sender: IAddress, - delegation_contract: IAddress, + sender: Address, + delegation_contract: Address, amount: int) -> Transaction: return TransactionBuilder( config=self.config, @@ -381,8 +381,8 @@ def create_transaction_for_undelegating(self, ).build() def create_transaction_for_withdrawing(self, - sender: IAddress, - delegation_contract: IAddress) -> Transaction: + sender: Address, + delegation_contract: Address) -> Transaction: return TransactionBuilder( config=self.config, sender=sender, diff --git a/multiversx_sdk/core/transactions_factories/relayed_transactions_factory.py b/multiversx_sdk/core/transactions_factories/relayed_transactions_factory.py index 0bb840f7..6c5c1788 100644 --- a/multiversx_sdk/core/transactions_factories/relayed_transactions_factory.py +++ b/multiversx_sdk/core/transactions_factories/relayed_transactions_factory.py @@ -4,7 +4,6 @@ from multiversx_sdk.core.address import Address from multiversx_sdk.core.errors import InvalidInnerTransactionError -from multiversx_sdk.core.interfaces import IAddress, ITransaction from multiversx_sdk.core.serializer import args_to_string from multiversx_sdk.core.transaction import Transaction @@ -20,49 +19,56 @@ def __init__(self, config: IConfig) -> None: self._config = config def create_relayed_v1_transaction(self, - inner_transaction: ITransaction, - relayer_address: IAddress) -> Transaction: + inner_transaction: Transaction, + relayer_address: Address) -> Transaction: if not inner_transaction.gas_limit: - raise InvalidInnerTransactionError("The gas limit is not set for the inner transaction") + raise InvalidInnerTransactionError( + "The gas limit is not set for the inner transaction") if not inner_transaction.signature: - raise InvalidInnerTransactionError("The inner transaction is not signed") + raise InvalidInnerTransactionError( + "The inner transaction is not signed") - serialized_transaction = self._prepare_inner_transaction_for_relayed_v1(inner_transaction) + serialized_transaction = self._prepare_inner_transaction_for_relayed_v1( + inner_transaction) data = f"relayedTx@{serialized_transaction.encode().hex()}" - gas_limit = self._config.min_gas_limit + self._config.gas_limit_per_byte * len(data) + inner_transaction.gas_limit + gas_limit = self._config.min_gas_limit + self._config.gas_limit_per_byte * \ + len(data) + inner_transaction.gas_limit return Transaction( chain_id=self._config.chain_id, - sender=relayer_address.to_bech32(), + sender=relayer_address, receiver=inner_transaction.sender, gas_limit=gas_limit, data=data.encode() ) def create_relayed_v2_transaction(self, - inner_transaction: ITransaction, + inner_transaction: Transaction, inner_transaction_gas_limit: int, - relayer_address: IAddress) -> Transaction: + relayer_address: Address) -> Transaction: if inner_transaction.gas_limit: - raise InvalidInnerTransactionError("The gas limit should not be set for the inner transaction") + raise InvalidInnerTransactionError( + "The gas limit should not be set for the inner transaction") if not inner_transaction.signature: - raise InvalidInnerTransactionError("The inner transaction is not signed") + raise InvalidInnerTransactionError( + "The inner transaction is not signed") arguments: List[Any] = [ - Address.new_from_bech32(inner_transaction.receiver), + inner_transaction.receiver, inner_transaction.nonce, inner_transaction.data, inner_transaction.signature ] data = f"relayedTxV2@{args_to_string(arguments)}" - gas_limit = inner_transaction_gas_limit + self._config.min_gas_limit + self._config.gas_limit_per_byte * len(data) + gas_limit = inner_transaction_gas_limit + self._config.min_gas_limit + \ + self._config.gas_limit_per_byte * len(data) return Transaction( - sender=relayer_address.to_bech32(), + sender=relayer_address, receiver=inner_transaction.sender, value=0, gas_limit=gas_limit, @@ -72,9 +78,9 @@ def create_relayed_v2_transaction(self, options=inner_transaction.options ) - def _prepare_inner_transaction_for_relayed_v1(self, inner_transaction: ITransaction) -> str: - sender = Address.new_from_bech32(inner_transaction.sender).to_hex() - receiver = Address.new_from_bech32(inner_transaction.receiver).to_hex() + def _prepare_inner_transaction_for_relayed_v1(self, inner_transaction: Transaction) -> str: + sender = inner_transaction.sender.to_hex() + receiver = inner_transaction.receiver.to_hex() tx: Dict[str, Any] = { "nonce": inner_transaction.nonce, @@ -93,7 +99,7 @@ def _prepare_inner_transaction_for_relayed_v1(self, inner_transaction: ITransact tx["options"] = inner_transaction.options if inner_transaction.guardian: - guardian = Address.new_from_bech32(inner_transaction.guardian).to_hex() + guardian = inner_transaction.guardian.to_hex() tx["guardian"] = base64.b64encode(bytes.fromhex(guardian)).decode() if inner_transaction.guardian_signature: diff --git a/multiversx_sdk/core/transactions_factories/relayed_transactions_factory_test.py b/multiversx_sdk/core/transactions_factories/relayed_transactions_factory_test.py index 056cf1e9..1ccb7029 100644 --- a/multiversx_sdk/core/transactions_factories/relayed_transactions_factory_test.py +++ b/multiversx_sdk/core/transactions_factories/relayed_transactions_factory_test.py @@ -21,8 +21,8 @@ def test_create_relayed_v1_with_invalid_inner_tx(self): alice = self.wallets["alice"] inner_transaction = Transaction( - sender=alice.label, - receiver="erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u", + sender=Address.new_from_bech32(alice.label), + receiver=Address.new_from_bech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"), gas_limit=10000000, data="getContractConfig".encode(), chain_id=self.config.chain_id @@ -48,8 +48,8 @@ def test_create_relayed_v1_transaction(self): bob = self.wallets["bob"] inner_transaction = Transaction( - sender=bob.label, - receiver="erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u", + sender=Address.new_from_bech32(bob.label), + receiver=Address.new_from_bech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"), gas_limit=60000000, chain_id=self.config.chain_id, data=b"getContractConfig", @@ -77,8 +77,8 @@ def test_create_relayed_v1_transaction_with_usernames(self): frank = self.wallets["frank"] inner_transaction = Transaction( - sender=carol.label, - receiver=alice.label, + sender=Address.new_from_bech32(carol.label), + receiver=Address.new_from_bech32(alice.label), gas_limit=50000, chain_id=self.config.chain_id, nonce=208, @@ -108,15 +108,15 @@ def test_compute_relayed_v1_with_guarded_inner_tx(self): grace = self.wallets["grace"] inner_transaction = Transaction( - sender=bob.label, - receiver="erd1qqqqqqqqqqqqqpgq54tsxmej537z9leghvp69hfu4f8gg5eu396q83gnnz", + sender=Address.new_from_bech32(bob.label), + receiver=Address.new_from_bech32("erd1qqqqqqqqqqqqqpgq54tsxmej537z9leghvp69hfu4f8gg5eu396q83gnnz"), gas_limit=60000000, chain_id=self.config.chain_id, data=b"getContractConfig", nonce=198, version=2, options=2, - guardian=grace.label + guardian=Address.new_from_bech32(grace.label) ) inner_tx_bytes = self.transaction_computer.compute_bytes_for_signing(inner_transaction) @@ -142,15 +142,15 @@ def test_guarded_relayed_v1_with_guarded_inner_tx(self): frank = self.wallets["frank"] inner_transaction = Transaction( - sender=bob.label, - receiver="erd1qqqqqqqqqqqqqpgq54tsxmej537z9leghvp69hfu4f8gg5eu396q83gnnz", + sender=Address.new_from_bech32(bob.label), + receiver=Address.new_from_bech32("erd1qqqqqqqqqqqqqpgq54tsxmej537z9leghvp69hfu4f8gg5eu396q83gnnz"), gas_limit=60000000, chain_id=self.config.chain_id, data=b"addNumber", nonce=198, version=2, options=2, - guardian=grace.label + guardian=Address.new_from_bech32(grace.label) ) inner_tx_bytes = self.transaction_computer.compute_bytes_for_signing(inner_transaction) @@ -163,7 +163,7 @@ def test_guarded_relayed_v1_with_guarded_inner_tx(self): ) relayed_transaction.options = 2 relayed_transaction.nonce = 2627 - relayed_transaction.guardian = frank.label + relayed_transaction.guardian = Address.new_from_bech32(frank.label) relayed_tx_bytes = self.transaction_computer.compute_bytes_for_signing(relayed_transaction) relayed_transaction.signature = alice.secret_key.sign(relayed_tx_bytes) @@ -178,8 +178,8 @@ def test_create_relayed_v2_with_invalid_inner_tx(self): carol = self.wallets["carol"] inner_transaction = Transaction( - sender=alice.label, - receiver=bob.label, + sender=Address.new_from_bech32(alice.label), + receiver=Address.new_from_bech32(bob.label), gas_limit=50000, chain_id=self.config.chain_id ) @@ -204,8 +204,8 @@ def test_compute_relayed_v2_transaction(self): bob = self.wallets["bob"] inner_transaction = Transaction( - sender=bob.label, - receiver="erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u", + sender=Address.new_from_bech32(bob.label), + receiver=Address.new_from_bech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"), gas_limit=0, chain_id=self.config.chain_id, data=b"getContractConfig", diff --git a/multiversx_sdk/core/transactions_factories/smart_contract_transactions_factory.py b/multiversx_sdk/core/transactions_factories/smart_contract_transactions_factory.py index 69920cf6..45e14255 100644 --- a/multiversx_sdk/core/transactions_factories/smart_contract_transactions_factory.py +++ b/multiversx_sdk/core/transactions_factories/smart_contract_transactions_factory.py @@ -8,7 +8,6 @@ from multiversx_sdk.core.constants import (ARGS_SEPARATOR, CONTRACT_DEPLOY_ADDRESS, VM_TYPE_WASM_VM) -from multiversx_sdk.core.interfaces import IAddress from multiversx_sdk.core.serializer import arg_to_string, args_to_buffers from multiversx_sdk.core.tokens import TokenComputer, TokenTransfer from multiversx_sdk.core.transaction import Transaction @@ -46,7 +45,7 @@ def __init__(self, config: IConfig, abi: Optional[IAbi] = None) -> None: self._data_args_builder = TokenTransfersDataBuilder(self.token_computer) def create_transaction_for_deploy(self, - sender: IAddress, + sender: Address, bytecode: Union[Path, bytes], gas_limit: int, arguments: Sequence[Any] = [], @@ -80,8 +79,8 @@ def create_transaction_for_deploy(self, ).build() def create_transaction_for_execute(self, - sender: IAddress, - contract: IAddress, + sender: Address, + contract: Address, function: str, gas_limit: int, arguments: Sequence[Any] = [], @@ -129,8 +128,8 @@ def create_transaction_for_execute(self, ).build() def create_transaction_for_upgrade(self, - sender: IAddress, - contract: IAddress, + sender: Address, + contract: Address, bytecode: Union[Path, bytes], gas_limit: int, arguments: Sequence[Any] = [], @@ -164,8 +163,8 @@ def create_transaction_for_upgrade(self, ).build() def create_transaction_for_claiming_developer_rewards(self, - sender: IAddress, - contract: IAddress) -> Transaction: + sender: Address, + contract: Address) -> Transaction: data_parts = ["ClaimDeveloperRewards"] return TransactionBuilder( @@ -178,9 +177,9 @@ def create_transaction_for_claiming_developer_rewards(self, ).build() def create_transaction_for_changing_owner_address(self, - sender: IAddress, - contract: IAddress, - new_owner: IAddress) -> Transaction: + sender: Address, + contract: Address, + new_owner: Address) -> Transaction: data_parts = ["ChangeOwnerAddress", new_owner.to_hex()] return TransactionBuilder( diff --git a/multiversx_sdk/core/transactions_factories/token_management_transactions_factory.py b/multiversx_sdk/core/transactions_factories/token_management_transactions_factory.py index 7605f0e6..79ad5fac 100644 --- a/multiversx_sdk/core/transactions_factories/token_management_transactions_factory.py +++ b/multiversx_sdk/core/transactions_factories/token_management_transactions_factory.py @@ -3,12 +3,13 @@ from typing import Optional, Protocol from multiversx_sdk.core.errors import BadUsageError -from multiversx_sdk.core.interfaces import IAddress from multiversx_sdk.core.serializer import arg_to_string from multiversx_sdk.core.transaction import Transaction from multiversx_sdk.core.transactions_factories.transaction_builder import \ TransactionBuilder +from multiversx_sdk.core.address import Address + logger = logging.getLogger(__name__) @@ -38,7 +39,7 @@ class IConfig(Protocol): gas_limit_update_token_id: int gas_limit_register_dynamic: int issue_cost: int - esdt_contract_address: IAddress + esdt_contract_address: Address class TokenType(Enum): @@ -56,7 +57,7 @@ def __init__(self, config: IConfig): def create_transaction_for_issuing_fungible( self, - sender: IAddress, + sender: Address, token_name: str, token_ticker: str, initial_supply: int, @@ -104,7 +105,7 @@ def _notify_about_unsetting_burn_role_globally(self) -> None: def create_transaction_for_issuing_semi_fungible( self, - sender: IAddress, + sender: Address, token_name: str, token_ticker: str, can_freeze: bool, @@ -142,7 +143,7 @@ def create_transaction_for_issuing_semi_fungible( def create_transaction_for_issuing_non_fungible( self, - sender: IAddress, + sender: Address, token_name: str, token_ticker: str, can_freeze: bool, @@ -180,7 +181,7 @@ def create_transaction_for_issuing_non_fungible( def create_transaction_for_registering_meta_esdt( self, - sender: IAddress, + sender: Address, token_name: str, token_ticker: str, num_decimals: int, @@ -220,7 +221,7 @@ def create_transaction_for_registering_meta_esdt( def create_transaction_for_registering_and_setting_roles( self, - sender: IAddress, + sender: Address, token_name: str, token_ticker: str, token_type: TokenType, @@ -248,7 +249,7 @@ def create_transaction_for_registering_and_setting_roles( def create_transaction_for_setting_burn_role_globally( self, - sender: IAddress, + sender: Address, token_identifier: str ) -> Transaction: parts: list[str] = [ @@ -268,7 +269,7 @@ def create_transaction_for_setting_burn_role_globally( def create_transaction_for_unsetting_burn_role_globally( self, - sender: IAddress, + sender: Address, token_identifier: str ) -> Transaction: parts: list[str] = [ @@ -288,8 +289,8 @@ def create_transaction_for_unsetting_burn_role_globally( def create_transaction_for_setting_special_role_on_fungible_token( self, - sender: IAddress, - user: IAddress, + sender: Address, + user: Address, token_identifier: str, add_role_local_mint: bool, add_role_local_burn: bool, @@ -316,8 +317,8 @@ def create_transaction_for_setting_special_role_on_fungible_token( def create_transaction_for_unsetting_special_role_on_fungible_token( self, - sender: IAddress, - user: IAddress, + sender: Address, + user: Address, token_identifier: str, remove_role_local_mint: bool, remove_role_local_burn: bool, @@ -344,8 +345,8 @@ def create_transaction_for_unsetting_special_role_on_fungible_token( def create_transaction_for_setting_special_role_on_semi_fungible_token( self, - sender: IAddress, - user: IAddress, + sender: Address, + user: Address, token_identifier: str, add_role_nft_create: bool = False, add_role_nft_burn: bool = False, @@ -384,8 +385,8 @@ def create_transaction_for_setting_special_role_on_semi_fungible_token( def create_transaction_for_unsetting_special_role_on_semi_fungible_token( self, - sender: IAddress, - user: IAddress, + sender: Address, + user: Address, token_identifier: str, remove_role_nft_burn: bool = False, remove_role_nft_add_quantity: bool = False, @@ -422,8 +423,8 @@ def create_transaction_for_unsetting_special_role_on_semi_fungible_token( def create_transaction_for_setting_special_role_on_non_fungible_token( self, - sender: IAddress, - user: IAddress, + sender: Address, + user: Address, token_identifier: str, add_role_nft_create: bool = False, add_role_nft_burn: bool = False, @@ -464,8 +465,8 @@ def create_transaction_for_setting_special_role_on_non_fungible_token( def create_transaction_for_unsetting_special_role_on_non_fungible_token( self, - sender: IAddress, - user: IAddress, + sender: Address, + user: Address, token_identifier: str, remove_role_nft_burn: bool = False, remove_role_nft_update_attributes: bool = False, @@ -504,7 +505,7 @@ def create_transaction_for_unsetting_special_role_on_non_fungible_token( def create_transaction_for_creating_nft( self, - sender: IAddress, + sender: Address, token_identifier: str, initial_quantity: int, name: str, @@ -543,7 +544,7 @@ def create_transaction_for_creating_nft( def create_transaction_for_pausing( self, - sender: IAddress, + sender: Address, token_identifier: str ) -> Transaction: parts: list[str] = [ @@ -563,7 +564,7 @@ def create_transaction_for_pausing( def create_transaction_for_unpausing( self, - sender: IAddress, + sender: Address, token_identifier: str ) -> Transaction: parts: list[str] = [ @@ -583,8 +584,8 @@ def create_transaction_for_unpausing( def create_transaction_for_freezing( self, - sender: IAddress, - user: IAddress, + sender: Address, + user: Address, token_identifier: str ) -> Transaction: parts: list[str] = [ @@ -605,8 +606,8 @@ def create_transaction_for_freezing( def create_transaction_for_unfreezing( self, - sender: IAddress, - user: IAddress, + sender: Address, + user: Address, token_identifier: str ) -> Transaction: parts: list[str] = [ @@ -627,8 +628,8 @@ def create_transaction_for_unfreezing( def create_transaction_for_wiping( self, - sender: IAddress, - user: IAddress, + sender: Address, + user: Address, token_identifier: str ) -> Transaction: parts: list[str] = [ @@ -649,7 +650,7 @@ def create_transaction_for_wiping( def create_transaction_for_local_minting( self, - sender: IAddress, + sender: Address, token_identifier: str, supply_to_mint: int ) -> Transaction: @@ -671,7 +672,7 @@ def create_transaction_for_local_minting( def create_transaction_for_local_burning( self, - sender: IAddress, + sender: Address, token_identifier: str, supply_to_burn: int ) -> Transaction: @@ -693,7 +694,7 @@ def create_transaction_for_local_burning( def create_transaction_for_updating_attributes( self, - sender: IAddress, + sender: Address, token_identifier: str, token_nonce: int, attributes: bytes @@ -717,7 +718,7 @@ def create_transaction_for_updating_attributes( def create_transaction_for_adding_quantity( self, - sender: IAddress, + sender: Address, token_identifier: str, token_nonce: int, quantity_to_add: int @@ -741,7 +742,7 @@ def create_transaction_for_adding_quantity( def create_transaction_for_burning_quantity( self, - sender: IAddress, + sender: Address, token_identifier: str, token_nonce: int, quantity_to_burn: int @@ -764,7 +765,7 @@ def create_transaction_for_burning_quantity( ).build() def create_transaction_for_modifying_royalties(self, - sender: IAddress, + sender: Address, token_identifier: str, token_nonce: int, new_royalties: int) -> Transaction: @@ -786,7 +787,7 @@ def create_transaction_for_modifying_royalties(self, ).build() def create_transaction_for_setting_new_uris(self, - sender: IAddress, + sender: Address, token_identifier: str, token_nonce: int, new_uris: list[str]) -> Transaction: @@ -811,7 +812,7 @@ def create_transaction_for_setting_new_uris(self, ).build() def create_transaction_for_modifying_creator(self, - sender: IAddress, + sender: Address, token_identifier: str, token_nonce: int) -> Transaction: parts: list[str] = [ @@ -831,7 +832,7 @@ def create_transaction_for_modifying_creator(self, ).build() def create_transaction_for_updating_metadata(self, - sender: IAddress, + sender: Address, token_identifier: str, token_nonce: int, new_token_name: str, @@ -861,7 +862,7 @@ def create_transaction_for_updating_metadata(self, ).build() def create_transaction_for_nft_metadata_recreate(self, - sender: IAddress, + sender: Address, token_identifier: str, token_nonce: int, new_token_name: str, @@ -891,7 +892,7 @@ def create_transaction_for_nft_metadata_recreate(self, ).build() def create_transaction_for_changing_token_to_dynamic(self, - sender: IAddress, + sender: Address, token_identifier: str) -> Transaction: """The following token types cannot be changed to dynamic: FungibleESDT, NonFungibleESDT, NonFungibleESDTv2""" parts: list[str] = [ @@ -910,7 +911,7 @@ def create_transaction_for_changing_token_to_dynamic(self, ).build() def create_transaction_for_updating_token_id(self, - sender: IAddress, + sender: Address, token_identifier: str) -> Transaction: parts: list[str] = [ "updateTokenID", @@ -928,7 +929,7 @@ def create_transaction_for_updating_token_id(self, ).build() def create_transaction_for_registering_dynamic_token(self, - sender: IAddress, + sender: Address, token_name: str, token_ticker: str, token_type: TokenType, @@ -957,7 +958,7 @@ def create_transaction_for_registering_dynamic_token(self, ).build() def create_transaction_for_registering_dynamic_and_setting_roles(self, - sender: IAddress, + sender: Address, token_name: str, token_ticker: str, token_type: TokenType, diff --git a/multiversx_sdk/core/transactions_factories/token_transfers_data_builder.py b/multiversx_sdk/core/transactions_factories/token_transfers_data_builder.py index bd2f9f1b..eb68fcdf 100644 --- a/multiversx_sdk/core/transactions_factories/token_transfers_data_builder.py +++ b/multiversx_sdk/core/transactions_factories/token_transfers_data_builder.py @@ -1,9 +1,10 @@ from typing import List, Protocol -from multiversx_sdk.core.interfaces import IAddress from multiversx_sdk.core.serializer import arg_to_string, args_to_strings from multiversx_sdk.core.tokens import TokenTransfer +from multiversx_sdk.core.address import Address + class ITokenComputer(Protocol): def extract_identifier_from_extended_identifier(self, identifier: str) -> str: @@ -20,7 +21,7 @@ def build_args_for_esdt_transfer(self, transfer: TokenTransfer) -> List[str]: return args - def build_args_for_single_esdt_nft_transfer(self, transfer: TokenTransfer, receiver: IAddress) -> List[str]: + def build_args_for_single_esdt_nft_transfer(self, transfer: TokenTransfer, receiver: Address) -> List[str]: args = ["ESDTNFTTransfer"] token = transfer.token identifier = self.token_computer.extract_identifier_from_extended_identifier(token.identifier) @@ -29,7 +30,7 @@ def build_args_for_single_esdt_nft_transfer(self, transfer: TokenTransfer, recei return args - def build_args_for_multi_esdt_nft_transfer(self, receiver: IAddress, transfers: List[TokenTransfer]) -> List[str]: + def build_args_for_multi_esdt_nft_transfer(self, receiver: Address, transfers: List[TokenTransfer]) -> List[str]: args = ["MultiESDTNFTTransfer", receiver.to_hex(), arg_to_string(len(transfers))] for transfer in transfers: diff --git a/multiversx_sdk/core/transactions_factories/transaction_builder.py b/multiversx_sdk/core/transactions_factories/transaction_builder.py index d09a6a58..02afb643 100644 --- a/multiversx_sdk/core/transactions_factories/transaction_builder.py +++ b/multiversx_sdk/core/transactions_factories/transaction_builder.py @@ -1,7 +1,7 @@ from typing import List, Optional, Protocol +from multiversx_sdk.core.address import Address from multiversx_sdk.core.constants import ARGS_SEPARATOR -from multiversx_sdk.core.interfaces import IAddress from multiversx_sdk.core.transaction import Transaction @@ -14,8 +14,8 @@ class IConfig(Protocol): class TransactionBuilder: def __init__(self, config: IConfig, - sender: IAddress, - receiver: IAddress, + sender: Address, + receiver: Address, data_parts: List[str], gas_limit: int, add_data_movement_gas: bool, @@ -46,8 +46,8 @@ def build(self) -> Transaction: gas_limit = self.compute_gas_limit(data) transaction = Transaction( - sender=self.sender.to_bech32(), - receiver=self.receiver.to_bech32(), + sender=self.sender, + receiver=self.receiver, gas_limit=gas_limit, chain_id=self.config.chain_id, data=data, diff --git a/multiversx_sdk/core/transactions_factories/transactions_factory_config.py b/multiversx_sdk/core/transactions_factories/transactions_factory_config.py index 966681ac..9a43e2d5 100644 --- a/multiversx_sdk/core/transactions_factories/transactions_factory_config.py +++ b/multiversx_sdk/core/transactions_factories/transactions_factory_config.py @@ -1,6 +1,5 @@ from multiversx_sdk.core.address import Address from multiversx_sdk.core.constants import DEFAULT_HRP -from multiversx_sdk.core.interfaces import IAddress class TransactionsFactoryConfig: @@ -34,7 +33,7 @@ def __init__(self, chain_id: str) -> None: self.gas_limit_update_token_id = 60_000_000 self.gas_limit_register_dynamic = 60_000_000 self.issue_cost = 50_000_000_000_000_000 - self.esdt_contract_address: IAddress = Address.new_from_bech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u") + self.esdt_contract_address = Address.new_from_bech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u") # Configuration for delegation operations self.gas_limit_stake = 5_000_000 diff --git a/multiversx_sdk/core/transactions_factories/transfer_transactions_factory.py b/multiversx_sdk/core/transactions_factories/transfer_transactions_factory.py index 4a87301b..34f41fc6 100644 --- a/multiversx_sdk/core/transactions_factories/transfer_transactions_factory.py +++ b/multiversx_sdk/core/transactions_factories/transfer_transactions_factory.py @@ -3,7 +3,6 @@ from multiversx_sdk.core.constants import \ EGLD_IDENTIFIER_FOR_MULTI_ESDTNFT_TRANSFER from multiversx_sdk.core.errors import BadUsageError -from multiversx_sdk.core.interfaces import IAddress from multiversx_sdk.core.tokens import TokenComputer, TokenTransfer from multiversx_sdk.core.transaction import Transaction from multiversx_sdk.core.transactions_factories.token_transfers_data_builder import \ @@ -11,6 +10,8 @@ from multiversx_sdk.core.transactions_factories.transaction_builder import \ TransactionBuilder +from multiversx_sdk.core.address import Address + ADDITIONAL_GAS_FOR_ESDT_TRANSFER = 100000 ADDITIONAL_GAS_FOR_ESDT_NFT_TRANSFER = 800000 @@ -31,8 +32,8 @@ def __init__(self, config: IConfig) -> None: self._data_args_builder = TokenTransfersDataBuilder(self.token_computer) def create_transaction_for_native_token_transfer(self, - sender: IAddress, - receiver: IAddress, + sender: Address, + receiver: Address, native_amount: int, data: Optional[str] = None) -> Transaction: transaction_data = data if data else "" @@ -47,8 +48,8 @@ def create_transaction_for_native_token_transfer(self, ).build() def create_transaction_for_esdt_token_transfer(self, - sender: IAddress, - receiver: IAddress, + sender: Address, + receiver: Address, token_transfers: list[TokenTransfer]) -> Transaction: if not token_transfers: raise BadUsageError("No token transfer has been provided") @@ -68,9 +69,9 @@ def create_transaction_for_esdt_token_transfer(self, ).build() def _single_transfer(self, - sender: IAddress, - receiver: IAddress, - transfer: TokenTransfer) -> tuple[list[str], int, IAddress]: + sender: Address, + receiver: Address, + transfer: TokenTransfer) -> tuple[list[str], int, Address]: if self.token_computer.is_fungible(transfer.token): if transfer.token.identifier == EGLD_IDENTIFIER_FOR_MULTI_ESDTNFT_TRANSFER: data_parts = self._data_args_builder.build_args_for_multi_esdt_nft_transfer(receiver, [transfer]) @@ -86,17 +87,17 @@ def _single_transfer(self, return data_parts, gas, sender def _multi_transfer(self, - sender: IAddress, - receiver: IAddress, - token_transfers: list[TokenTransfer]) -> tuple[list[str], int, IAddress]: + sender: Address, + receiver: Address, + token_transfers: list[TokenTransfer]) -> tuple[list[str], int, Address]: data_parts = self._data_args_builder.build_args_for_multi_esdt_nft_transfer(receiver, token_transfers) gas = self.config.gas_limit_multi_esdt_nft_transfer * len( token_transfers) + ADDITIONAL_GAS_FOR_ESDT_NFT_TRANSFER return data_parts, gas, sender def create_transaction_for_transfer(self, - sender: IAddress, - receiver: IAddress, + sender: Address, + receiver: Address, native_amount: Optional[int] = None, token_transfers: Optional[list[TokenTransfer]] = None, data: Optional[bytes] = None) -> Transaction: diff --git a/multiversx_sdk/facades/entrypoints.py b/multiversx_sdk/facades/entrypoints.py index acdc3f84..ada906ba 100644 --- a/multiversx_sdk/facades/entrypoints.py +++ b/multiversx_sdk/facades/entrypoints.py @@ -60,7 +60,7 @@ def sign_transaction(self, transaction: Transaction, account: Account): transaction.signature = account.sign(tx_computer.compute_bytes_for_signing(transaction)) def verify_transaction_signature(self, transaction: Transaction) -> bool: - verifier = UserVerifier.from_address(Address.new_from_bech32(transaction.sender)) + verifier = UserVerifier.from_address(transaction.sender) tx_computer = TransactionComputer() return verifier.verify( diff --git a/multiversx_sdk/network_providers/api_network_provider_test.py b/multiversx_sdk/network_providers/api_network_provider_test.py index 87f493ed..c757df06 100644 --- a/multiversx_sdk/network_providers/api_network_provider_test.py +++ b/multiversx_sdk/network_providers/api_network_provider_test.py @@ -100,8 +100,8 @@ def test_get_account_storage_entry(self): def test_send_transaction(self): transaction = Transaction( - sender="erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl", - receiver="erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl", + sender=Address.new_from_bech32("erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl"), + receiver=Address.new_from_bech32("erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl"), gas_limit=50000, chain_id="D", value=5000000000000000000, @@ -120,8 +120,8 @@ def test_send_transaction(self): def test_send_transaction_with_data(self): transaction = Transaction( - sender="erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl", - receiver="erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl", + sender=Address.new_from_bech32("erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl"), + receiver=Address.new_from_bech32("erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl"), gas_limit=70000, chain_id="D", nonce=105, @@ -137,8 +137,8 @@ def test_send_transaction_with_data(self): def test_send_transactions(self): first_tx = Transaction( - sender="erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl", - receiver="erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl", + sender=Address.new_from_bech32("erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl"), + receiver=Address.new_from_bech32("erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl"), gas_limit=50000, chain_id="D", nonce=103, @@ -150,16 +150,16 @@ def test_send_transactions(self): ) invalid_tx = Transaction( - sender="erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl", - receiver="erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl", + sender=Address.new_from_bech32("erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl"), + receiver=Address.new_from_bech32("erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl"), gas_limit=50000, chain_id="D", nonce=77 ) last_tx = Transaction( - sender="erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl", - receiver="erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl", + sender=Address.new_from_bech32("erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl"), + receiver=Address.new_from_bech32("erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl"), gas_limit=50000, chain_id="D", nonce=104, @@ -187,8 +187,8 @@ def test_simulate_transaction(self): tx_computer = TransactionComputer() transaction = Transaction( - sender=bob.label, - receiver=bob.label, + sender=Address.new_from_bech32(bob.label), + receiver=Address.new_from_bech32(bob.label), gas_limit=50000, chain_id="D", ) @@ -202,8 +202,8 @@ def test_simulate_transaction(self): assert tx_on_network.status == TransactionStatus("success") transaction = Transaction( - sender=bob.label, - receiver="erd1qqqqqqqqqqqqqpgq076flgeualrdu5jyyj60snvrh7zu4qrg05vqez5jen", + sender=Address.new_from_bech32(bob.label), + receiver=Address.new_from_bech32("erd1qqqqqqqqqqqqqpgq076flgeualrdu5jyyj60snvrh7zu4qrg05vqez5jen"), gas_limit=10000000, chain_id="D", data=b"add@07" @@ -225,8 +225,8 @@ def test_estimate_transaction_cost(self): tx_computer = TransactionComputer() transaction = Transaction( - sender=bob.label, - receiver=bob.label, + sender=Address.new_from_bech32(bob.label), + receiver=Address.new_from_bech32(bob.label), gas_limit=50000, chain_id="D", data="test transaction".encode() @@ -280,8 +280,8 @@ def test_send_and_await_for_completed_transaction(self): tx_computer = TransactionComputer() transaction = Transaction( - sender=bob.label, - receiver=bob.label, + sender=Address.new_from_bech32(bob.label), + receiver=Address.new_from_bech32(bob.label), gas_limit=50000, chain_id="D", ) @@ -296,8 +296,8 @@ def test_send_and_await_for_completed_transaction(self): assert tx_on_network.status.is_completed transaction = Transaction( - sender=bob.label, - receiver="erd1qqqqqqqqqqqqqpgqhdqz9j3zgpl8fg2z0jzx9n605gwxx4djd8ssruw094", + sender=Address.new_from_bech32(bob.label), + receiver=Address.new_from_bech32("erd1qqqqqqqqqqqqqpgqhdqz9j3zgpl8fg2z0jzx9n605gwxx4djd8ssruw094"), gas_limit=5000000, chain_id="D", data="dummy@05".encode() @@ -317,8 +317,8 @@ def test_send_and_await_transaction_on_condition(self): tx_computer = TransactionComputer() transaction = Transaction( - sender=alice.label, - receiver=alice.label, + sender=Address.new_from_bech32(alice.label), + receiver=Address.new_from_bech32(alice.label), gas_limit=50000, chain_id="D", ) @@ -334,8 +334,8 @@ def test_send_and_await_transaction_on_condition(self): assert tx_on_network.status.is_completed transaction = Transaction( - sender=alice.label, - receiver="erd1qqqqqqqqqqqqqpgqhdqz9j3zgpl8fg2z0jzx9n605gwxx4djd8ssruw094", + sender=Address.new_from_bech32(alice.label), + receiver=Address.new_from_bech32("erd1qqqqqqqqqqqqqpgqhdqz9j3zgpl8fg2z0jzx9n605gwxx4djd8ssruw094"), gas_limit=5000000, chain_id="D", data="dummy@05".encode() diff --git a/multiversx_sdk/network_providers/http_resources.py b/multiversx_sdk/network_providers/http_resources.py index bee9db1a..2bdcb967 100644 --- a/multiversx_sdk/network_providers/http_resources.py +++ b/multiversx_sdk/network_providers/http_resources.py @@ -13,9 +13,8 @@ from multiversx_sdk.core.transaction_status import TransactionStatus from multiversx_sdk.network_providers.resources import ( AccountOnNetwork, AccountStorage, AccountStorageEntry, BlockCoordinates, - BlockOnNetwork, EmptyAddress, FungibleTokenMetadata, NetworkConfig, - NetworkStatus, TokenAmountOnNetwork, TokensCollectionMetadata, - TransactionCostResponse) + BlockOnNetwork, FungibleTokenMetadata, NetworkConfig, NetworkStatus, + TokenAmountOnNetwork, TokensCollectionMetadata, TransactionCostResponse) def smart_contract_query_to_vm_query_request(query: SmartContractQuery) -> dict[str, Any]: @@ -83,10 +82,12 @@ def _transaction_from_network_response(tx_hash: str, response: dict[str, Any]) - result.value = response.get("value", 0) sender = response.get("sender", "") - result.sender = Address.new_from_bech32(sender) if sender else EmptyAddress() + if sender: + result.sender = Address.new_from_bech32(sender) receiver = response.get("receiver", "") - result.receiver = Address.new_from_bech32(receiver) if receiver else EmptyAddress() + if receiver: + result.receiver = Address.new_from_bech32(receiver) result.gas_price = response.get("gasPrice", 0) result.gas_limit = response.get("gasLimit", 0) diff --git a/multiversx_sdk/network_providers/proxy_network_provider_test.py b/multiversx_sdk/network_providers/proxy_network_provider_test.py index 118edd45..378d3f71 100644 --- a/multiversx_sdk/network_providers/proxy_network_provider_test.py +++ b/multiversx_sdk/network_providers/proxy_network_provider_test.py @@ -213,8 +213,8 @@ def test_get_sc_invoking_tx(self): def test_send_transaction(self): transaction = Transaction( - sender="erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl", - receiver="erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl", + sender=Address.new_from_bech32("erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl"), + receiver=Address.new_from_bech32("erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl"), gas_limit=50000, chain_id="D", value=5000000000000000000, @@ -230,8 +230,8 @@ def test_send_transaction(self): def test_send_transaction_with_data(self): transaction = Transaction( - sender="erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl", - receiver="erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl", + sender=Address.new_from_bech32("erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl"), + receiver=Address.new_from_bech32("erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl"), gas_limit=70000, chain_id="D", nonce=105, @@ -247,8 +247,8 @@ def test_send_transaction_with_data(self): def test_send_transactions(self): first_tx = Transaction( - sender="erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl", - receiver="erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl", + sender=Address.new_from_bech32("erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl"), + receiver=Address.new_from_bech32("erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl"), gas_limit=50000, chain_id="D", nonce=103, @@ -260,16 +260,16 @@ def test_send_transactions(self): ) invalid_tx = Transaction( - sender="erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl", - receiver="erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl", + sender=Address.new_from_bech32("erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl"), + receiver=Address.new_from_bech32("erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl"), gas_limit=50000, chain_id="D", nonce=77 ) last_tx = Transaction( - sender="erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl", - receiver="erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl", + sender=Address.new_from_bech32("erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl"), + receiver=Address.new_from_bech32("erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl"), gas_limit=50000, chain_id="D", nonce=104, @@ -297,8 +297,8 @@ def test_simulate_transaction(self): tx_computer = TransactionComputer() transaction = Transaction( - sender=bob.label, - receiver=bob.label, + sender=Address.new_from_bech32(bob.label), + receiver=Address.new_from_bech32(bob.label), gas_limit=50000, chain_id="D", ) @@ -312,8 +312,8 @@ def test_simulate_transaction(self): assert tx_on_network.status == TransactionStatus("success") transaction = Transaction( - sender=bob.label, - receiver="erd1qqqqqqqqqqqqqpgq076flgeualrdu5jyyj60snvrh7zu4qrg05vqez5jen", + sender=Address.new_from_bech32(bob.label), + receiver=Address.new_from_bech32("erd1qqqqqqqqqqqqqpgq076flgeualrdu5jyyj60snvrh7zu4qrg05vqez5jen"), gas_limit=10000000, chain_id="D", data=b"add@07" @@ -335,8 +335,8 @@ def test_estimate_transaction_cost(self): tx_computer = TransactionComputer() transaction = Transaction( - sender=bob.label, - receiver=bob.label, + sender=Address.new_from_bech32(bob.label), + receiver=Address.new_from_bech32(bob.label), gas_limit=50000, chain_id="D", data="test transaction".encode() @@ -353,8 +353,8 @@ def test_send_and_await_for_completed_transaction(self): tx_computer = TransactionComputer() transaction = Transaction( - sender=bob.label, - receiver=bob.label, + sender=Address.new_from_bech32(bob.label), + receiver=Address.new_from_bech32(bob.label), gas_limit=50000, chain_id="D", ) @@ -369,8 +369,8 @@ def test_send_and_await_for_completed_transaction(self): assert tx_on_network.status.is_completed transaction = Transaction( - sender=bob.label, - receiver="erd1qqqqqqqqqqqqqpgqhdqz9j3zgpl8fg2z0jzx9n605gwxx4djd8ssruw094", + sender=Address.new_from_bech32(bob.label), + receiver=Address.new_from_bech32("erd1qqqqqqqqqqqqqpgqhdqz9j3zgpl8fg2z0jzx9n605gwxx4djd8ssruw094"), gas_limit=5000000, chain_id="D", data="dummy@05".encode() diff --git a/multiversx_sdk/network_providers/resources.py b/multiversx_sdk/network_providers/resources.py index 312aad09..997f8829 100644 --- a/multiversx_sdk/network_providers/resources.py +++ b/multiversx_sdk/network_providers/resources.py @@ -20,14 +20,6 @@ def to_dictionary(self) -> Dict[str, Any]: return self.__dict__ -class EmptyAddress: - def to_bech32(self) -> str: - return "" - - def to_hex(self) -> str: - return "" - - @dataclass class NetworkConfig: raw: dict[str, Any] diff --git a/multiversx_sdk/testutils/mock_network_provider.py b/multiversx_sdk/testutils/mock_network_provider.py index 3f51aed1..1e7a8560 100644 --- a/multiversx_sdk/testutils/mock_network_provider.py +++ b/multiversx_sdk/testutils/mock_network_provider.py @@ -3,7 +3,6 @@ from typing import Any, Callable, Dict, List, Union from multiversx_sdk.core.address import Address -from multiversx_sdk.core.interfaces import IAddress from multiversx_sdk.core.smart_contract_query import ( SmartContractQuery, SmartContractQueryResponse) from multiversx_sdk.core.transaction import Transaction @@ -114,7 +113,7 @@ def mark_tx_as_completed(transaction: TransactionOnNetwork): thread = threading.Thread(target=fn) thread.start() - def get_account(self, address: IAddress) -> AccountOnNetwork: + def get_account(self, address: Address) -> AccountOnNetwork: account = self.accounts.get(address.to_bech32(), None) if account: From cd5691a778f0e21825bf65313948142c13daa381 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Tue, 5 Nov 2024 14:47:04 +0200 Subject: [PATCH 2/7] change type from str to Address --- multiversx_sdk/core/transaction.py | 17 +-- multiversx_sdk/core/transaction_computer.py | 6 +- multiversx_sdk/core/transaction_test.py | 87 ++++++------- .../account_transactions_factory_test.py | 16 +-- .../delegation_transactions_factory_test.py | 76 ++++++------ ...smart_contract_transaction_factory_test.py | 44 +++---- ...en_management_transactions_factory_test.py | 114 +++++++++--------- .../transfer_transactions_factory_test.py | 40 +++--- multiversx_sdk/facades/entrypoints_test.py | 2 +- .../network_providers/api_network_provider.py | 6 +- multiversx_sdk/wallet/user_test.py | 4 +- 11 files changed, 208 insertions(+), 204 deletions(-) diff --git a/multiversx_sdk/core/transaction.py b/multiversx_sdk/core/transaction.py index a8764a1e..a263e166 100644 --- a/multiversx_sdk/core/transaction.py +++ b/multiversx_sdk/core/transaction.py @@ -48,8 +48,8 @@ def to_dictionary(self) -> dict[str, Any]: return { "nonce": self.nonce, "value": str(self.value), - "receiver": self.receiver, - "sender": self.sender, + "receiver": self.receiver.to_bech32(), + "sender": self.sender.to_bech32(), "senderUsername": self._value_to_b64_or_empty(self.sender_username), "receiverUsername": self._value_to_b64_or_empty(self.receiver_username), "gasPrice": self.gas_price, @@ -58,7 +58,7 @@ def to_dictionary(self) -> dict[str, Any]: "chainID": self.chain_id, "version": self.version, "options": self.options, - "guardian": self.guardian, + "guardian": self.guardian.to_bech32() if self.guardian else "", "signature": self._value_to_hex_or_empty(self.signature), "guardianSignature": self._value_to_hex_or_empty(self.guardian_signature) } @@ -67,14 +67,18 @@ def to_dictionary(self) -> dict[str, Any]: def new_from_dictionary(dictionary: dict[str, Any]) -> "Transaction": _ensure_mandatory_fields_for_transaction(dictionary) + guardian = dictionary.get("guardian") or None + if guardian: + guardian = Address.new_from_bech32(guardian) + return Transaction( nonce=dictionary.get("nonce", None), value=int(dictionary.get("value", None)), - receiver=dictionary["receiver"], + receiver=Address.new_from_bech32(dictionary["receiver"]), receiver_username=_bytes_from_b64(dictionary.get("receiverUsername", "")).decode(), - sender=dictionary["sender"], + sender=Address.new_from_bech32(dictionary["sender"]), sender_username=_bytes_from_b64(dictionary.get("senderUsername", "")).decode(), - guardian=dictionary.get("guardian", None), + guardian=guardian, gas_price=dictionary.get("gasPrice", None), gas_limit=dictionary["gasLimit"], data=_bytes_from_b64(dictionary.get("data", "")), @@ -98,7 +102,6 @@ def _value_to_hex_or_empty(self, value: bytes) -> str: return "" def __eq__(self, other: object) -> bool: - # don;t think this is properly working if not isinstance(other, Transaction): return False diff --git a/multiversx_sdk/core/transaction_computer.py b/multiversx_sdk/core/transaction_computer.py index 94ef1ba4..005466ad 100644 --- a/multiversx_sdk/core/transaction_computer.py +++ b/multiversx_sdk/core/transaction_computer.py @@ -100,8 +100,8 @@ def _to_dictionary(self, transaction: Transaction, with_signature: bool = False) dictionary["nonce"] = transaction.nonce dictionary["value"] = str(transaction.value) - dictionary["receiver"] = transaction.receiver - dictionary["sender"] = transaction.sender + dictionary["receiver"] = transaction.receiver.to_bech32() + dictionary["sender"] = transaction.sender.to_bech32() if transaction.sender_username: dictionary["senderUsername"] = b64encode(transaction.sender_username.encode()).decode() @@ -128,7 +128,7 @@ def _to_dictionary(self, transaction: Transaction, with_signature: bool = False) dictionary["options"] = transaction.options if transaction.guardian: - dictionary["guardian"] = transaction.guardian + dictionary["guardian"] = transaction.guardian.to_bech32() return dictionary diff --git a/multiversx_sdk/core/transaction_test.py b/multiversx_sdk/core/transaction_test.py index e0d3408e..4f47068b 100644 --- a/multiversx_sdk/core/transaction_test.py +++ b/multiversx_sdk/core/transaction_test.py @@ -13,6 +13,8 @@ from multiversx_sdk.wallet.user_pem import UserPEM from multiversx_sdk.wallet.user_verifer import UserVerifier +from multiversx_sdk.core.address import Address + class NetworkConfig: def __init__(self, min_gas_limit: int = 50000) -> None: @@ -30,8 +32,8 @@ class TestTransaction: transaction_computer = TransactionComputer() def test_serialize_for_signing(self): - sender = "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" - receiver = "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx" + sender = Address.new_from_bech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th") + receiver = Address.new_from_bech32("erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx") transaction = Transaction( nonce=89, @@ -63,8 +65,8 @@ def test_serialize_for_signing(self): def test_with_usernames(self): transaction = Transaction( chain_id="T", - sender=self.carol.label, - receiver=self.alice.label, + sender=Address.new_from_bech32(self.carol.label), + receiver=Address.new_from_bech32(self.alice.label), nonce=204, gas_limit=50000, sender_username="carol", @@ -77,8 +79,8 @@ def test_with_usernames(self): def test_compute_transaction_hash(self): transaction = Transaction( - sender="erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th", - receiver="erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th", + sender=Address.new_from_bech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"), + receiver=Address.new_from_bech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"), gas_limit=100000, chain_id="D", nonce=17243, @@ -92,8 +94,8 @@ def test_compute_transaction_hash(self): def test_compute_transaction_hash_with_usernames(self): transaction = Transaction( - sender="erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th", - receiver="erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th", + sender=Address.new_from_bech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"), + receiver=Address.new_from_bech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"), gas_limit=100000, chain_id="D", nonce=17244, @@ -109,8 +111,8 @@ def test_compute_transaction_hash_with_usernames(self): def test_compute_transaction_fee_insufficient(self): transaction = Transaction( - sender="erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th", - receiver="erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th", + sender=Address.new_from_bech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"), + receiver=Address.new_from_bech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"), gas_limit=50000, chain_id="D", data=b"toolittlegaslimit", @@ -121,8 +123,8 @@ def test_compute_transaction_fee_insufficient(self): def test_compute_transaction_fee(self): transaction = Transaction( - sender="erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th", - receiver="erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th", + sender=Address.new_from_bech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"), + receiver=Address.new_from_bech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"), gas_price=500, gas_limit=20, chain_id="D", @@ -133,8 +135,8 @@ def test_compute_transaction_fee(self): def test_compute_transaction_fee_with_data_field(self): transaction = Transaction( - sender="erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th", - receiver="erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th", + sender=Address.new_from_bech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"), + receiver=Address.new_from_bech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"), gas_price=500, gas_limit=12010, chain_id="D", @@ -150,8 +152,8 @@ def test_compute_transaction_with_guardian_fields(self): sender_secret_key = UserSecretKey(bytes.fromhex(sender_secret_key_hex)) transaction = Transaction( - sender="erd1fp4zaxvyc8jh99vauwns99kvs9tn0k6cwrr0zpyz2jvyurcepuhsfzvlar", - receiver="erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th", + sender=Address.new_from_bech32("erd1fp4zaxvyc8jh99vauwns99kvs9tn0k6cwrr0zpyz2jvyurcepuhsfzvlar"), + receiver=Address.new_from_bech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"), gas_limit=139000, gas_price=1000000000, chain_id="D", @@ -160,7 +162,7 @@ def test_compute_transaction_with_guardian_fields(self): data=b"this is a test transaction", version=2, options=2, - guardian="erd1nn8apn09vmf72l7kzr3nd90rr5r2q74he7hseghs3v68c5p7ud2qhhwf96", + guardian=Address.new_from_bech32("erd1nn8apn09vmf72l7kzr3nd90rr5r2q74he7hseghs3v68c5p7ud2qhhwf96"), guardian_signature=bytes.fromhex("487150c26d38a01fe19fbe26dac20ec2b42ec3abf5763a47a508e62bcd6ad3437c4d404684442e864a1dbad446dc0f852889a09f0650b5fdb55f4ee18147920d") ) @@ -176,8 +178,8 @@ def test_compute_transaction_with_dummy_guardian(self): alice_secret_key = UserSecretKey(bytes.fromhex(alice_private_key_hex)) transaction = Transaction( - sender="erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th", - receiver="erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx", + sender=Address.new_from_bech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"), + receiver=Address.new_from_bech32("erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx"), gas_limit=150000, chain_id="local-testnet", gas_price=1000000000, @@ -186,7 +188,7 @@ def test_compute_transaction_with_dummy_guardian(self): options=2, nonce=92, value=123456789000000000000000000000, - guardian="erd1x23lzn8483xs2su4fak0r0dqx6w38enpmmqf2yrkylwq7mfnvyhsxqw57y", + guardian=Address.new_from_bech32("erd1x23lzn8483xs2su4fak0r0dqx6w38enpmmqf2yrkylwq7mfnvyhsxqw57y"), guardian_signature=bytes([0] * 64) ) @@ -202,8 +204,8 @@ def test_compute_transaction_with_dummy_guardian(self): def test_tx_computer_has_options_set(self): tx = Transaction( - sender="erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th", - receiver="erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th", + sender=Address.new_from_bech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"), + receiver=Address.new_from_bech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"), gas_limit=50000, chain_id="D", options=3 @@ -214,8 +216,8 @@ def test_tx_computer_has_options_set(self): def test_tx_computer_apply_guardian(self): tx = Transaction( - sender="erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th", - receiver="erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th", + sender=Address.new_from_bech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"), + receiver=Address.new_from_bech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"), gas_limit=200000, chain_id="D", version=1, @@ -224,20 +226,20 @@ def test_tx_computer_apply_guardian(self): self.transaction_computer.apply_guardian( transaction=tx, - guardian="erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx" + guardian=Address.new_from_bech32("erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx") ) assert tx.version == 2 assert tx.options == 3 - assert tx.guardian == "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx" + assert str(tx.guardian) == "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx" def test_sign_transaction_by_hash(self): parent = Path(__file__).parent.parent pem = UserPEM.from_file(parent / "testutils" / "testwallets" / "alice.pem") tx = Transaction( - sender="erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th", - receiver="erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx", + sender=Address.new_from_bech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"), + receiver=Address.new_from_bech32("erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx"), value=0, gas_limit=50000, version=2, @@ -252,8 +254,8 @@ def test_sign_transaction_by_hash(self): def test_apply_guardian_with_hash_signing(self): tx = Transaction( - sender="erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th", - receiver="erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx", + sender=Address.new_from_bech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"), + receiver=Address.new_from_bech32("erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx"), value=0, gas_limit=50000, version=1, @@ -265,22 +267,18 @@ def test_apply_guardian_with_hash_signing(self): assert tx.version == 2 assert tx.options == 1 - self.transaction_computer.apply_guardian(transaction=tx, guardian=self.carol.label) + self.transaction_computer.apply_guardian(transaction=tx, guardian=Address.new_from_bech32(self.carol.label)) assert tx.version == 2 assert tx.options == 3 def test_ensure_transaction_is_valid(self): tx = Transaction( - sender="invalid_sender", - receiver=self.bob.label, + sender=Address.new_from_bech32(self.bob.label), + receiver=Address.new_from_bech32(self.bob.label), gas_limit=50000, chain_id="" ) - with pytest.raises(BadUsageError, match="Invalid `sender` field. Should be the bech32 address of the sender."): - self.transaction_computer.compute_bytes_for_signing(tx) - - tx.sender = self.alice.label with pytest.raises(BadUsageError, match="The `chainID` field is not set"): self.transaction_computer.compute_bytes_for_signing(tx) @@ -296,8 +294,8 @@ def test_ensure_transaction_is_valid(self): def test_compute_bytes_for_verifying_signature(self): tx = Transaction( - sender=self.alice.label, - receiver=self.bob.label, + sender=Address.new_from_bech32(self.alice.label), + receiver=Address.new_from_bech32(self.bob.label), gas_limit=50000, chain_id="D", nonce=7 @@ -322,8 +320,8 @@ def test_compute_bytes_for_verifying_signature(self): def test_compute_bytes_for_verifying_transaction_signed_by_hash(self): tx = Transaction( - sender=self.alice.label, - receiver=self.bob.label, + sender=Address.new_from_bech32(self.alice.label), + receiver=Address.new_from_bech32(self.bob.label), gas_limit=50000, chain_id="D", nonce=7 @@ -350,8 +348,8 @@ def test_transaction_converter(self): transaction = Transaction( nonce=90, value=123456789000000000000000000000, - sender="erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th", - receiver="erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx", + sender=Address.new_from_bech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"), + receiver=Address.new_from_bech32("erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx"), sender_username="alice", receiver_username="bob", gas_price=1000000000, @@ -361,6 +359,9 @@ def test_transaction_converter(self): ) tx_as_dict = transaction.to_dictionary() + print(transaction.__dict__) restored_tx = Transaction.new_from_dictionary(tx_as_dict) + print("------------") + print(restored_tx.__dict__) assert transaction == restored_tx diff --git a/multiversx_sdk/core/transactions_factories/account_transactions_factory_test.py b/multiversx_sdk/core/transactions_factories/account_transactions_factory_test.py index 368ea944..b2bd92fc 100644 --- a/multiversx_sdk/core/transactions_factories/account_transactions_factory_test.py +++ b/multiversx_sdk/core/transactions_factories/account_transactions_factory_test.py @@ -23,8 +23,8 @@ def test_save_key_value(self): key_value_pairs=pairs ) - assert tx.sender == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" - assert tx.receiver == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert tx.sender.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert tx.receiver.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" assert tx.data.decode() == "SaveKeyValue@6b657930@76616c756530" assert tx.gas_limit == 271000 @@ -39,8 +39,8 @@ def test_set_guardian(self): service_id=service_id ) - assert tx.sender == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" - assert tx.receiver == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert tx.sender.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert tx.receiver.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" assert tx.data.decode() == "SetGuardian@8049d639e5a6980d1cd2392abcce41029cda74a1563523a202f09641cc2618f8@4d756c7469766572735854435353657276696365" assert tx.gas_limit == 475500 @@ -48,8 +48,8 @@ def test_guard_account(self): sender = Address.new_from_bech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th") tx = self.factory.create_transaction_for_guarding_account(sender) - assert tx.sender == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" - assert tx.receiver == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert tx.sender.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert tx.receiver.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" assert tx.data.decode() == "GuardAccount" assert tx.gas_limit == 318000 @@ -57,7 +57,7 @@ def test_unguard_account(self): sender = Address.new_from_bech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th") tx = self.factory.create_transaction_for_unguarding_account(sender) - assert tx.sender == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" - assert tx.receiver == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert tx.sender.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert tx.receiver.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" assert tx.data.decode() == "UnGuardAccount" assert tx.gas_limit == 321000 diff --git a/multiversx_sdk/core/transactions_factories/delegation_transactions_factory_test.py b/multiversx_sdk/core/transactions_factories/delegation_transactions_factory_test.py index 4da77d2e..289d2d85 100644 --- a/multiversx_sdk/core/transactions_factories/delegation_transactions_factory_test.py +++ b/multiversx_sdk/core/transactions_factories/delegation_transactions_factory_test.py @@ -19,8 +19,8 @@ def test_create_transaction_for_new_delegation_contract(self): amount=1250000000000000000000 ) - assert transaction.sender == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" - assert transaction.receiver == DELEGATION_MANAGER_SC_ADDRESS + assert transaction.sender.to_bech32() == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" + assert transaction.receiver.to_bech32() == DELEGATION_MANAGER_SC_ADDRESS assert transaction.data assert transaction.data.decode() == "createNewDelegationContract@010f0cf064dd59200000@0a" assert transaction.gas_limit == 60126500 @@ -46,8 +46,8 @@ def test_create_transaction_for_adding_nodes(self): signed_messages=signed_messages ) - assert transaction.sender == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" + assert transaction.sender.to_bech32() == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" assert transaction.data assert transaction.data.decode() == "addNodes@e7beaa95b3877f47348df4dd1cb578a4f7cabf7a20bfeefe5cdd263878ff132b765e04fef6f40c93512b666c47ed7719b8902f6c922c04247989b7137e837cc81a62e54712471c97a2ddab75aa9c2f58f813ed4c0fa722bde0ab718bff382208@81109fa1c8d3dc7b6c2d6e65206cc0bc1a83c9b2d1eb91a601d66ad32def430827d5eb52917bd2b0d04ce195738db216" assert transaction.value == 0 @@ -64,8 +64,8 @@ def test_create_transaction_for_removing_nodes(self): public_keys=public_keys ) - assert transaction.sender == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" + assert transaction.sender.to_bech32() == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" assert transaction.data assert transaction.data.decode() == "removeNodes@6e6f746176616c6964626c736b6579686578656e636f646564" assert transaction.value == 0 @@ -82,8 +82,8 @@ def test_create_transaction_for_staking_nodes(self): public_keys=public_keys ) - assert transaction.sender == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" + assert transaction.sender.to_bech32() == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" assert transaction.data assert transaction.data.decode() == "stakeNodes@6e6f746176616c6964626c736b6579686578656e636f646564" assert transaction.value == 0 @@ -100,8 +100,8 @@ def test_create_transaction_for_unbonding_nodes(self): public_keys=public_keys ) - assert transaction.sender == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" + assert transaction.sender.to_bech32() == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" assert transaction.data assert transaction.data.decode() == "unBondNodes@6e6f746176616c6964626c736b6579686578656e636f646564" assert transaction.value == 0 @@ -118,8 +118,8 @@ def test_create_transaction_for_unstaking_nodes(self): public_keys=public_keys ) - assert transaction.sender == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" + assert transaction.sender.to_bech32() == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" assert transaction.data assert transaction.data.decode() == "unStakeNodes@6e6f746176616c6964626c736b6579686578656e636f646564" assert transaction.value == 0 @@ -137,8 +137,8 @@ def test_create_transaction_for_unjailing_nodes(self): amount=25000000000000000000 # 2.5 egld ) - assert transaction.sender == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" + assert transaction.sender.to_bech32() == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" assert transaction.data assert transaction.data.decode() == "unJailNodes@6e6f746176616c6964626c736b6579686578656e636f646564" assert transaction.value == 25000000000000000000 @@ -153,8 +153,8 @@ def test_create_transaction_for_changing_service_fee(self): service_fee=10 ) - assert transaction.sender == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" + assert transaction.sender.to_bech32() == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" assert transaction.data assert transaction.data.decode() == "changeServiceFee@0a" assert transaction.value == 0 @@ -169,8 +169,8 @@ def test_create_transaction_for_modifying_delegation_cap(self): delegation_cap=5000000000000000000000 ) - assert transaction.sender == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" + assert transaction.sender.to_bech32() == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" assert transaction.data assert transaction.data.decode() == "modifyTotalDelegationCap@010f0cf064dd59200000" assert transaction.value == 0 @@ -184,8 +184,8 @@ def test_create_transaction_for_setting_automatic_activation(self): delegation_contract=delegation_contract ) - assert transaction.sender == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" + assert transaction.sender.to_bech32() == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" assert transaction.data assert transaction.data.decode() == "setAutomaticActivation@74727565" assert transaction.value == 0 @@ -199,8 +199,8 @@ def test_create_transaction_for_unsetting_automatic_activation(self): delegation_contract=delegation_contract ) - assert transaction.sender == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" + assert transaction.sender.to_bech32() == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" assert transaction.data assert transaction.data.decode() == "setAutomaticActivation@66616c7365" assert transaction.value == 0 @@ -214,8 +214,8 @@ def test_create_transaction_for_setting_cap_check_on_redelegate_rewards(self): delegation_contract=delegation_contract ) - assert transaction.sender == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" + assert transaction.sender.to_bech32() == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" assert transaction.data assert transaction.data.decode() == "setCheckCapOnReDelegateRewards@74727565" assert transaction.value == 0 @@ -229,8 +229,8 @@ def test_create_transaction_for_unsetting_cap_check_on_redelegate_rewards(self): delegation_contract=delegation_contract ) - assert transaction.sender == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" + assert transaction.sender.to_bech32() == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" assert transaction.data assert transaction.data.decode() == "setCheckCapOnReDelegateRewards@66616c7365" assert transaction.value == 0 @@ -247,8 +247,8 @@ def test_create_transaction_for_setting_metadata(self): identifier="identifier" ) - assert transaction.sender == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" + assert transaction.sender.to_bech32() == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" assert transaction.data assert transaction.data.decode() == "setMetaData@6e616d65@77656273697465@6964656e746966696572" assert transaction.value == 0 @@ -263,8 +263,8 @@ def test_create_transaction_for_delegating(self): amount=1000000000000000000 ) - assert transaction.sender == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" + assert transaction.sender.to_bech32() == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" assert transaction.data assert transaction.data.decode() == "delegate" assert transaction.value == 1000000000000000000 @@ -279,8 +279,8 @@ def test_create_transaction_for_claiming_rewards(self): delegation_contract=delegation_contract ) - assert transaction.sender == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" + assert transaction.sender.to_bech32() == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" assert transaction.data assert transaction.data.decode() == "claimRewards" assert transaction.value == 0 @@ -295,8 +295,8 @@ def test_create_transaction_for_redelegating_rewards(self): delegation_contract=delegation_contract ) - assert transaction.sender == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" + assert transaction.sender.to_bech32() == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" assert transaction.data assert transaction.data.decode() == "reDelegateRewards" assert transaction.value == 0 @@ -312,8 +312,8 @@ def test_create_transaction_for_undelegating(self): amount=1000000000000000000 ) - assert transaction.sender == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" + assert transaction.sender.to_bech32() == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" assert transaction.data assert transaction.data.decode() == "unDelegate@0de0b6b3a7640000" assert transaction.value == 0 @@ -328,8 +328,8 @@ def test_create_transaction_for_withdrawing(self): delegation_contract=delegation_contract ) - assert transaction.sender == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" + assert transaction.sender.to_bech32() == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2" + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc" assert transaction.data assert transaction.data.decode() == "withdraw" assert transaction.value == 0 diff --git a/multiversx_sdk/core/transactions_factories/smart_contract_transaction_factory_test.py b/multiversx_sdk/core/transactions_factories/smart_contract_transaction_factory_test.py index 8d56b18d..9539d8ad 100644 --- a/multiversx_sdk/core/transactions_factories/smart_contract_transaction_factory_test.py +++ b/multiversx_sdk/core/transactions_factories/smart_contract_transaction_factory_test.py @@ -54,8 +54,8 @@ def test_create_transaction_for_deploy(self): arguments=[BigUIntValue(1)] ) - assert transaction.sender == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" - assert transaction.receiver == CONTRACT_DEPLOY_ADDRESS + assert transaction.sender.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert transaction.receiver.to_bech32() == CONTRACT_DEPLOY_ADDRESS assert transaction.data == f"{self.bytecode.hex()}@0500@0504@01".encode() assert transaction.gas_limit == gas_limit assert transaction.value == 0 @@ -103,8 +103,8 @@ def test_create_transaction_for_execute_no_transfer(self): arguments=[U32Value(7)] ) - assert transaction.sender == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" - assert transaction.receiver == "erd1qqqqqqqqqqqqqpgqhy6nl6zq07rnzry8uyh6rtyq0uzgtk3e69fqgtz9l4" + assert transaction.sender.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqpgqhy6nl6zq07rnzry8uyh6rtyq0uzgtk3e69fqgtz9l4" assert transaction.gas_limit == gas_limit assert transaction.data assert transaction.data.decode() == "add@07" @@ -131,8 +131,8 @@ def test_create_transaction_for_execute_and_tranfer_native_token(self): native_transfer_amount=egld_amount ) - assert transaction.sender == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" - assert transaction.receiver == "erd1qqqqqqqqqqqqqpgqhy6nl6zq07rnzry8uyh6rtyq0uzgtk3e69fqgtz9l4" + assert transaction.sender.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqpgqhy6nl6zq07rnzry8uyh6rtyq0uzgtk3e69fqgtz9l4" assert transaction.gas_limit == gas_limit assert transaction.data assert transaction.data.decode() == "add@07" @@ -156,8 +156,8 @@ def test_create_transaction_for_execute_and_send_single_esdt(self): token_transfers=[transfer] ) - assert transaction.sender == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" - assert transaction.receiver == "erd1qqqqqqqqqqqqqpgqhy6nl6zq07rnzry8uyh6rtyq0uzgtk3e69fqgtz9l4" + assert transaction.sender.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqpgqhy6nl6zq07rnzry8uyh6rtyq0uzgtk3e69fqgtz9l4" assert transaction.gas_limit == gas_limit assert transaction.data assert transaction.data.decode() == "ESDTTransfer@464f4f2d366365313762@0a@64756d6d79@07" @@ -185,8 +185,8 @@ def test_create_transaction_for_execute_and_send_multiple_esdts(self): token_transfers=[foo_transfer, bar_transfer] ) - assert transaction.sender == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" - assert transaction.receiver == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert transaction.sender.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert transaction.receiver.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" assert transaction.gas_limit == gas_limit assert transaction.data assert transaction.data.decode() == "MultiESDTNFTTransfer@00000000000000000500ed8e25a94efa837aae0e593112cfbb01b448755069e1@02@464f4f2d366365313762@@0a@4241522d356263303866@@0c44@64756d6d79@07" @@ -210,8 +210,8 @@ def test_create_transaction_for_execute_and_send_single_nft(self): token_transfers=[transfer] ) - assert transaction.sender == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" - assert transaction.receiver == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert transaction.sender.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert transaction.receiver.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" assert transaction.gas_limit == gas_limit assert transaction.data assert transaction.data.decode( @@ -239,8 +239,8 @@ def test_create_transaction_for_execute_and_send_multiple_nfts(self): token_transfers=[first_transfer, second_transfer] ) - assert transaction.sender == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" - assert transaction.receiver == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert transaction.sender.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert transaction.receiver.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" assert transaction.gas_limit == gas_limit assert transaction.data assert transaction.data.decode() == "MultiESDTNFTTransfer@00000000000000000500b9353fe8407f87310c87e12fa1ac807f0485da39d152@02@4e46542d313233343536@01@01@4e46542d313233343536@2a@01@64756d6d79@07" @@ -268,8 +268,8 @@ def test_create_transaction_for_execute_and_send_native_and_nfts(self): token_transfers=[first_transfer, second_transfer] ) - assert transaction.sender == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" - assert transaction.receiver == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert transaction.sender.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert transaction.receiver.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" assert transaction.gas_limit == gas_limit assert transaction.data assert transaction.data.decode() == "MultiESDTNFTTransfer@00000000000000000500b9353fe8407f87310c87e12fa1ac807f0485da39d152@03@4e46542d313233343536@01@01@4e46542d313233343536@2a@01@45474c442d303030303030@@0de0b6b3a7640000@64756d6d79@07" @@ -314,8 +314,8 @@ def test_create_transaction_for_upgrade(self): arguments=[BigUIntValue(7)] ) - assert transaction.sender == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" - assert transaction.receiver == "erd1qqqqqqqqqqqqqpgqhy6nl6zq07rnzry8uyh6rtyq0uzgtk3e69fqgtz9l4" + assert transaction.sender.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqpgqhy6nl6zq07rnzry8uyh6rtyq0uzgtk3e69fqgtz9l4" assert transaction.data == f"upgradeContract@{self.bytecode.hex()}@0504@07".encode() assert transaction.data.decode().startswith("upgradeContract@") assert transaction.gas_limit == gas_limit @@ -334,8 +334,8 @@ def test_create_transaction_for_claiming_developer_rewards(self): contract=contract_address ) - assert transaction.sender == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" - assert transaction.receiver == "erd1qqqqqqqqqqqqqpgqhy6nl6zq07rnzry8uyh6rtyq0uzgtk3e69fqgtz9l4" + assert transaction.sender.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqpgqhy6nl6zq07rnzry8uyh6rtyq0uzgtk3e69fqgtz9l4" assert transaction.data.decode() == "ClaimDeveloperRewards" assert transaction.gas_limit == 6_000_000 @@ -350,7 +350,7 @@ def test_create_transaction_for_changing_owner_address(self): new_owner=new_owner ) - assert transaction.sender == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" - assert transaction.receiver == "erd1qqqqqqqqqqqqqpgqhy6nl6zq07rnzry8uyh6rtyq0uzgtk3e69fqgtz9l4" + assert transaction.sender.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqpgqhy6nl6zq07rnzry8uyh6rtyq0uzgtk3e69fqgtz9l4" assert transaction.data.decode() == "ChangeOwnerAddress@8049d639e5a6980d1cd2392abcce41029cda74a1563523a202f09641cc2618f8" assert transaction.gas_limit == 6_000_000 diff --git a/multiversx_sdk/core/transactions_factories/token_management_transactions_factory_test.py b/multiversx_sdk/core/transactions_factories/token_management_transactions_factory_test.py index aad68b63..05780f6d 100644 --- a/multiversx_sdk/core/transactions_factories/token_management_transactions_factory_test.py +++ b/multiversx_sdk/core/transactions_factories/token_management_transactions_factory_test.py @@ -24,8 +24,8 @@ def test_create_transaction_for_registering_and_setting_roles(): assert transaction.data assert transaction.data.decode() == "registerAndSetAllRoles@54455354@54455354@464e47@02" - assert transaction.sender == frank.to_bech32() - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" + assert transaction.sender == frank + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" assert transaction.value == 50000000000000000 @@ -46,8 +46,8 @@ def test_create_transaction_for_issuing_fungible(): assert transaction.data assert transaction.data.decode() == "issue@4652414e4b@4652414e4b@64@@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@66616c7365@63616e4164645370656369616c526f6c6573@66616c7365" - assert transaction.sender == frank.to_bech32() - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" + assert transaction.sender == frank + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" assert transaction.value == 50000000000000000 @@ -67,8 +67,8 @@ def test_create_transaction_for_issuing_semi_fungible(): assert transaction.data assert transaction.data.decode() == "issueSemiFungible@4652414e4b@4652414e4b@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e5472616e736665724e4654437265617465526f6c65@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@66616c7365@63616e4164645370656369616c526f6c6573@66616c7365" - assert transaction.sender == frank.to_bech32() - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" + assert transaction.sender == frank + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" assert transaction.value == 50000000000000000 @@ -88,8 +88,8 @@ def test_create_transaction_for_issuing_non_fungible(): assert transaction.data assert transaction.data.decode() == "issueNonFungible@4652414e4b@4652414e4b@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e5472616e736665724e4654437265617465526f6c65@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@66616c7365@63616e4164645370656369616c526f6c6573@66616c7365" - assert transaction.sender == frank.to_bech32() - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" + assert transaction.sender == frank + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" assert transaction.value == 50000000000000000 @@ -110,8 +110,8 @@ def test_create_transaction_for_registering_meta_esdt(): assert transaction.data assert transaction.data.decode() == "registerMetaESDT@4652414e4b@4652414e4b@0a@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e5472616e736665724e4654437265617465526f6c65@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@66616c7365@63616e4164645370656369616c526f6c6573@66616c7365" - assert transaction.sender == frank.to_bech32() - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" + assert transaction.sender == frank + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" assert transaction.value == 50000000000000000 @@ -131,8 +131,8 @@ def test_create_transaction_for_setting_special_role_on_non_fungible_token(): assert transaction.data assert transaction.data.decode() == "setSpecialRole@4652414e4b2d313163653365@1e8a8b6b49de5b7be10aaa158a5a6a4abb4b56cc08f524bb5e6cd5f211ad3e13@45534454526f6c654e4654437265617465@45534454526f6c654e465455706461746541747472696275746573@45534454526f6c654e4654416464555249@45534454526f6c654d6f6469667943726561746f72@45534454526f6c654e46545265637265617465" - assert transaction.sender == frank.to_bech32() - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" + assert transaction.sender == frank + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" assert transaction.value == 0 @@ -151,8 +151,8 @@ def test_create_transaction_for_unsetting_special_role_on_non_fungible_token(): assert transaction.data assert transaction.data.decode() == "unSetSpecialRole@4652414e4b2d313163653365@1e8a8b6b49de5b7be10aaa158a5a6a4abb4b56cc08f524bb5e6cd5f211ad3e13@45534454526f6c654e465455706461746541747472696275746573@45534454526f6c654e4654416464555249@45534454526f6c654d6f6469667943726561746f72@45534454526f6c654e46545265637265617465" - assert transaction.sender == frank.to_bech32() - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" + assert transaction.sender == frank + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" assert transaction.value == 0 @@ -166,8 +166,8 @@ def test_set_roles_on_nft(): assert transaction.data assert transaction.data.decode() == "setSpecialRole@4652414e4b2d313163653365@1e8a8b6b49de5b7be10aaa158a5a6a4abb4b56cc08f524bb5e6cd5f211ad3e13@455344545472616e73666572526f6c65" - assert transaction.sender == frank.to_bech32() - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" + assert transaction.sender == frank + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" assert transaction.value == 0 transaction = factory.create_transaction_for_setting_special_role_on_non_fungible_token( @@ -202,8 +202,8 @@ def test_create_transaction_for_creating_nft(): assert transaction.data assert transaction.data.decode() == "ESDTNFTCreate@4652414e4b2d616139653864@01@74657374@03e8@61626261@74657374@61@62" - assert transaction.sender == grace.to_bech32() - assert transaction.receiver == grace.to_bech32() + assert transaction.sender.to_bech32() == grace.to_bech32() + assert transaction.receiver.to_bech32() == grace.to_bech32() assert transaction.value == 0 @@ -221,7 +221,7 @@ def test_create_transaction_for_setting_special_role_on_fungible_token(): assert transaction.data assert transaction.data.decode() == f"setSpecialRole@4652414e4b2d313163653365@1e8a8b6b49de5b7be10aaa158a5a6a4abb4b56cc08f524bb5e6cd5f211ad3e13@{mint_role_as_hex}" - assert transaction.sender == frank.to_bech32() + assert transaction.sender == frank assert transaction.value == 0 @@ -239,7 +239,7 @@ def test_create_transaction_for_unsetting_special_role_on_fungible_token(): assert transaction.data assert transaction.data.decode() == f"unSetSpecialRole@4652414e4b2d313163653365@1e8a8b6b49de5b7be10aaa158a5a6a4abb4b56cc08f524bb5e6cd5f211ad3e13@{mint_role_as_hex}" - assert transaction.sender == frank.to_bech32() + assert transaction.sender == frank assert transaction.value == 0 @@ -259,7 +259,7 @@ def test_set_all_roles_on_fungible_token(): assert transaction.data assert transaction.data.decode() == f"setSpecialRole@4652414e4b2d313163653365@1e8a8b6b49de5b7be10aaa158a5a6a4abb4b56cc08f524bb5e6cd5f211ad3e13@{mint_role_as_hex}@{burn_role_as_hex}@{transfer_role_as_hex}" - assert transaction.sender == frank.to_bech32() + assert transaction.sender == frank assert transaction.value == 0 @@ -276,7 +276,7 @@ def test_create_transaction_for_setting_special_role_on_semi_fungible_token(): assert transaction.data assert transaction.data.decode() == "setSpecialRole@4652414e4b2d313163653365@1e8a8b6b49de5b7be10aaa158a5a6a4abb4b56cc08f524bb5e6cd5f211ad3e13@45534454526f6c654e4654437265617465@45534454526f6c654e46544275726e@45534454526f6c654e46544164645175616e74697479@455344545472616e73666572526f6c65" - assert transaction.sender == frank.to_bech32() + assert transaction.sender == frank assert transaction.value == 0 @@ -292,7 +292,7 @@ def test_create_transaction_for_unsetting_special_role_on_semi_fungible_token(): assert transaction.data assert transaction.data.decode() == "unSetSpecialRole@4652414e4b2d313163653365@1e8a8b6b49de5b7be10aaa158a5a6a4abb4b56cc08f524bb5e6cd5f211ad3e13@45534454526f6c654e46544275726e@45534454526f6c654e46544164645175616e74697479@455344545472616e73666572526f6c65" - assert transaction.sender == frank.to_bech32() + assert transaction.sender == frank assert transaction.value == 0 @@ -304,7 +304,7 @@ def test_create_transaction_for_pausing(): assert transaction.data assert transaction.data.decode() == "pause@4652414e4b2d313163653365" - assert transaction.sender == frank.to_bech32() + assert transaction.sender == frank assert transaction.value == 0 @@ -316,7 +316,7 @@ def test_create_transaction_for_unpausing(): assert transaction.data assert transaction.data.decode() == "unPause@4652414e4b2d313163653365" - assert transaction.sender == frank.to_bech32() + assert transaction.sender == frank assert transaction.value == 0 @@ -329,7 +329,7 @@ def test_create_transaction_for_freezing(): assert transaction.data assert transaction.data.decode() == "freeze@4652414e4b2d313163653365@1e8a8b6b49de5b7be10aaa158a5a6a4abb4b56cc08f524bb5e6cd5f211ad3e13" - assert transaction.sender == frank.to_bech32() + assert transaction.sender == frank assert transaction.value == 0 @@ -342,7 +342,7 @@ def test_create_transaction_for_unfreezing(): assert transaction.data assert transaction.data.decode() == "unFreeze@4652414e4b2d313163653365@1e8a8b6b49de5b7be10aaa158a5a6a4abb4b56cc08f524bb5e6cd5f211ad3e13" - assert transaction.sender == frank.to_bech32() + assert transaction.sender == frank assert transaction.value == 0 @@ -355,7 +355,7 @@ def test_create_transaction_for_local_minting(): assert transaction.data assert transaction.data.decode() == "ESDTLocalMint@4652414e4b2d313163653365@0a" - assert transaction.sender == frank.to_bech32() + assert transaction.sender == frank assert transaction.value == 0 @@ -368,7 +368,7 @@ def test_create_transaction_for_local_burning(): assert transaction.data assert transaction.data.decode() == "ESDTLocalBurn@4652414e4b2d313163653365@0a" - assert transaction.sender == frank.to_bech32() + assert transaction.sender == frank assert transaction.value == 0 @@ -382,7 +382,7 @@ def test_create_transaction_for_updating_attributes(): assert transaction.data assert transaction.data.decode() == "ESDTNFTUpdateAttributes@4652414e4b2d313163653365@0a@74657374" - assert transaction.sender == frank.to_bech32() + assert transaction.sender == frank assert transaction.value == 0 @@ -396,7 +396,7 @@ def test_create_transaction_for_adding_quantity(): assert transaction.data assert transaction.data.decode() == "ESDTNFTAddQuantity@4652414e4b2d313163653365@0a@0a" - assert transaction.sender == frank.to_bech32() + assert transaction.sender == frank assert transaction.value == 0 @@ -410,7 +410,7 @@ def test_create_transaction_for_burning_quantity(): assert transaction.data assert transaction.data.decode() == "ESDTNFTBurn@4652414e4b2d313163653365@0a@0a" - assert transaction.sender == frank.to_bech32() + assert transaction.sender == frank assert transaction.value == 0 @@ -422,7 +422,7 @@ def test_create_transaction_for_setting_burn_role_globally(): assert transaction.data assert transaction.data.decode() == "setBurnRoleGlobally@4652414e4b2d313163653365" - assert transaction.sender == frank.to_bech32() + assert transaction.sender == frank assert transaction.value == 0 @@ -434,7 +434,7 @@ def test_create_transaction_for_unsetting_burn_role_globally(): assert transaction.data assert transaction.data.decode() == "unsetBurnRoleGlobally@4652414e4b2d313163653365" - assert transaction.sender == frank.to_bech32() + assert transaction.sender == frank assert transaction.value == 0 @@ -447,7 +447,7 @@ def test_create_transaction_for_wiping(): assert transaction.data assert transaction.data.decode() == "wipe@4652414e4b2d313163653365@1e8a8b6b49de5b7be10aaa158a5a6a4abb4b56cc08f524bb5e6cd5f211ad3e13" - assert transaction.sender == frank.to_bech32() + assert transaction.sender == frank assert transaction.value == 0 @@ -460,8 +460,8 @@ def test_create_transaction_for_modifying_royalties(): ) assert transaction.data.decode() == "ESDTModifyRoyalties@544553542d313233343536@01@04d2" - assert transaction.sender == alice.to_bech32() - assert transaction.receiver == alice.to_bech32() + assert transaction.sender == alice + assert transaction.receiver.to_bech32() == alice.to_bech32() assert transaction.value == 0 assert transaction.gas_limit == 60_125_000 @@ -475,8 +475,8 @@ def test_create_transaction_for_setting_new_uris(): ) assert transaction.data.decode() == "ESDTSetNewURIs@544553542d313233343536@01@6669727374555249@7365636f6e64555249" - assert transaction.sender == alice.to_bech32() - assert transaction.receiver == alice.to_bech32() + assert transaction.sender == alice + assert transaction.receiver.to_bech32() == alice.to_bech32() assert transaction.value == 0 assert transaction.gas_limit == 60_164_000 @@ -489,8 +489,8 @@ def test_create_transaction_for_modifying_creator(): ) assert transaction.data.decode() == "ESDTModifyCreator@544553542d313233343536@01" - assert transaction.sender == alice.to_bech32() - assert transaction.receiver == alice.to_bech32() + assert transaction.sender == alice + assert transaction.receiver.to_bech32() == alice.to_bech32() assert transaction.value == 0 assert transaction.gas_limit == 60_114_500 @@ -508,8 +508,8 @@ def test_create_transaction_for_updating_metadata(): ) assert transaction.data.decode() == "ESDTMetaDataUpdate@544553542d313233343536@01@54657374@04d2@61626261@74657374@6669727374555249@7365636f6e64555249" - assert transaction.sender == alice.to_bech32() - assert transaction.receiver == alice.to_bech32() + assert transaction.sender == alice + assert transaction.receiver.to_bech32() == alice.to_bech32() assert transaction.value == 0 assert transaction.gas_limit == 60_218_000 @@ -527,8 +527,8 @@ def test_create_transaction_for_recreating_metadata(): ) assert transaction.data.decode() == "ESDTMetaDataRecreate@544553542d313233343536@01@54657374@04d2@61626261@74657374@6669727374555249@7365636f6e64555249" - assert transaction.sender == alice.to_bech32() - assert transaction.receiver == alice.to_bech32() + assert transaction.sender == alice + assert transaction.receiver.to_bech32() == alice.to_bech32() assert transaction.value == 0 assert transaction.gas_limit == 60_221_000 @@ -540,8 +540,8 @@ def test_create_transaction_for_changing_to_dynamic(): ) assert transaction.data.decode() == "changeToDynamic@544553542d313233343536" - assert transaction.sender == alice.to_bech32() - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" + assert transaction.sender == alice + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" assert transaction.value == 0 assert transaction.gas_limit == 60_107_000 @@ -553,8 +553,8 @@ def test_create_transaction_for_updating_token_id(): ) assert transaction.data.decode() == "updateTokenID@544553542d313233343536" - assert transaction.sender == alice.to_bech32() - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" + assert transaction.sender == alice + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" assert transaction.value == 0 assert transaction.gas_limit == 60_104_000 @@ -568,8 +568,8 @@ def test_create_transaction_for_registering_dynamic(): ) assert transaction.data.decode() == "registerDynamic@54657374@544553542d313233343536@534654" - assert transaction.sender == alice.to_bech32() - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" + assert transaction.sender == alice + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" assert transaction.value == 50000000000000000 assert transaction.gas_limit == 60_131_000 @@ -583,8 +583,8 @@ def test_create_transaction_for_registering_and_setting_all_roles(): ) assert transaction.data.decode() == "registerAndSetAllRolesDynamic@54657374@544553542d313233343536@534654" - assert transaction.sender == alice.to_bech32() - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" + assert transaction.sender == alice + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" assert transaction.value == 50000000000000000 assert transaction.gas_limit == 60_152_000 @@ -617,8 +617,8 @@ def test_register_dynamic_meta(): ) assert transaction.data.decode() == "registerDynamic@54657374@544553542d393837363534@4d455441@12" - assert transaction.sender == alice.to_bech32() - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" + assert transaction.sender == alice + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" assert transaction.value == 50000000000000000 assert transaction.gas_limit == 60_138_500 @@ -633,7 +633,7 @@ def test_register_dynamic_and_set_all_roles_meta(): ) assert transaction.data.decode() == "registerAndSetAllRolesDynamic@54657374@544553542d393837363534@4d455441@12" - assert transaction.sender == alice.to_bech32() - assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" + assert transaction.sender == alice + assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" assert transaction.value == 50000000000000000 assert transaction.gas_limit == 60_159_500 diff --git a/multiversx_sdk/core/transactions_factories/transfer_transactions_factory_test.py b/multiversx_sdk/core/transactions_factories/transfer_transactions_factory_test.py index 0af64df8..5f3d48c1 100644 --- a/multiversx_sdk/core/transactions_factories/transfer_transactions_factory_test.py +++ b/multiversx_sdk/core/transactions_factories/transfer_transactions_factory_test.py @@ -21,8 +21,8 @@ def test_create_transaction_for_native_token_transfer_no_data(self): native_amount=1000000000000000000 ) - assert transaction.sender == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" - assert transaction.receiver == "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx" + assert transaction.sender.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert transaction.receiver.to_bech32() == "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx" assert transaction.value == 1000000000000000000 assert transaction.chain_id == "D" assert transaction.gas_limit == 50_000 @@ -36,8 +36,8 @@ def test_create_transaction_for_native_token_transfer_with_data(self): data="test data" ) - assert transaction.sender == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" - assert transaction.receiver == "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx" + assert transaction.sender.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert transaction.receiver.to_bech32() == "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx" assert transaction.value == 1000000000000000000 assert transaction.chain_id == "D" assert transaction.gas_limit == 63_500 @@ -53,8 +53,8 @@ def test_create_transaction_for_esdt_transfer(self): token_transfers=[token_transfer] ) - assert transaction.sender == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" - assert transaction.receiver == "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx" + assert transaction.sender.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert transaction.receiver.to_bech32() == "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx" assert transaction.value == 0 assert transaction.chain_id == "D" assert transaction.data.decode() == "ESDTTransfer@464f4f2d313233343536@0f4240" @@ -70,8 +70,8 @@ def test_create_transaction_for_nft_transfer(self): token_transfers=[token_transfer] ) - assert transaction.sender == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" - assert transaction.receiver == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert transaction.sender.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert transaction.receiver.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" assert transaction.value == 0 assert transaction.chain_id == "D" assert transaction.data.decode() == "ESDTNFTTransfer@4e46542d313233343536@0a@01@8049d639e5a6980d1cd2392abcce41029cda74a1563523a202f09641cc2618f8" @@ -90,8 +90,8 @@ def test_create_transaction_for_multiple_nft_transfers(self): token_transfers=[first_transfer, second_transfer] ) - assert transaction.sender == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" - assert transaction.receiver == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert transaction.sender.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert transaction.receiver.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" assert transaction.value == 0 assert transaction.chain_id == "D" assert transaction.data.decode() == "MultiESDTNFTTransfer@8049d639e5a6980d1cd2392abcce41029cda74a1563523a202f09641cc2618f8@02@4e46542d313233343536@0a@01@544553542d393837363534@01@01" @@ -123,8 +123,8 @@ def test_create_transaction_for_native_transfer(self): native_amount=1000000000000000000, ) - assert transaction.sender == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" - assert transaction.receiver == "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx" + assert transaction.sender.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert transaction.receiver.to_bech32() == "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx" assert transaction.value == 1000000000000000000 assert transaction.chain_id == "D" assert transaction.gas_limit == 50_000 @@ -137,8 +137,8 @@ def test_create_transaction_for_native_transfer_and_set_data_field(self): data="hello".encode() ) - assert transaction.sender == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" - assert transaction.receiver == "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx" + assert transaction.sender.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert transaction.receiver.to_bech32() == "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx" assert transaction.value == 1000000000000000000 assert transaction.chain_id == "D" assert transaction.gas_limit == 57_500 @@ -150,8 +150,8 @@ def test_create_transaction_for_notarizing(self): data="hello".encode() ) - assert transaction.sender == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" - assert transaction.receiver == "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx" + assert transaction.sender.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert transaction.receiver.to_bech32() == "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx" assert transaction.value == 0 assert transaction.chain_id == "D" assert transaction.gas_limit == 57_500 @@ -170,8 +170,8 @@ def test_create_transaction_for_token_transfer(self): token_transfers=[first_transfer, second_transfer] ) - assert transaction.sender == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" - assert transaction.receiver == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert transaction.sender.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert transaction.receiver.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" assert transaction.value == 0 assert transaction.chain_id == "D" assert transaction.data.decode() == "MultiESDTNFTTransfer@8049d639e5a6980d1cd2392abcce41029cda74a1563523a202f09641cc2618f8@03@4e46542d313233343536@0a@01@544553542d393837363534@01@01@45474c442d303030303030@@0de0b6b3a7640000" @@ -187,8 +187,8 @@ def test_egld_as_single_token_transfer(self): token_transfers=[transfer] ) - assert transaction.sender == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" - assert transaction.receiver == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert transaction.sender.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert transaction.receiver.to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" assert transaction.value == 0 assert transaction.chain_id == "D" assert transaction.data.decode() == "MultiESDTNFTTransfer@8049d639e5a6980d1cd2392abcce41029cda74a1563523a202f09641cc2618f8@01@45474c442d303030303030@@0de0b6b3a7640000" diff --git a/multiversx_sdk/facades/entrypoints_test.py b/multiversx_sdk/facades/entrypoints_test.py index ba565aa2..bb86640f 100644 --- a/multiversx_sdk/facades/entrypoints_test.py +++ b/multiversx_sdk/facades/entrypoints_test.py @@ -4,7 +4,7 @@ from multiversx_sdk.abi.abi import Abi from multiversx_sdk.core.address import Address -from multiversx_sdk.facades.account import Account +from multiversx_sdk.core.account import Account from multiversx_sdk.facades.entrypoints import DevnetEntrypoint testutils = Path(__file__).parent.parent / "testutils" diff --git a/multiversx_sdk/network_providers/api_network_provider.py b/multiversx_sdk/network_providers/api_network_provider.py index 3098bfa0..b4500e40 100644 --- a/multiversx_sdk/network_providers/api_network_provider.py +++ b/multiversx_sdk/network_providers/api_network_provider.py @@ -1,5 +1,5 @@ import urllib.parse -from typing import Any, Callable, Dict, Optional, Union, cast +from typing import Any, Callable, Optional, Union, cast import requests @@ -245,12 +245,12 @@ def _do_get(self, url: str) -> Any: except Exception as err: raise GenericError(url, err) - def _do_post(self, url: str, payload: Any) -> Dict[str, Any]: + def _do_post(self, url: str, payload: Any) -> dict[str, Any]: try: response = requests.post(url, json=payload, **self.config.requests_options) response.raise_for_status() parsed = response.json() - return cast(Dict[str, Any], self._get_data(parsed, url)) + return cast(dict[str, Any], self._get_data(parsed, url)) except requests.HTTPError as err: error_data = self._extract_error_from_response(err.response) raise GenericError(url, error_data) diff --git a/multiversx_sdk/wallet/user_test.py b/multiversx_sdk/wallet/user_test.py index ab8a5117..5cc8cbd9 100644 --- a/multiversx_sdk/wallet/user_test.py +++ b/multiversx_sdk/wallet/user_test.py @@ -119,8 +119,8 @@ def test_sign_transaction(): tx = Transaction( nonce=89, value=0, - receiver="erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx", - sender="erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th", + receiver=Address.new_from_bech32("erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx"), + sender=Address.new_from_bech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"), data=None, gas_price=1000000000, gas_limit=50000, From 42893aa9515518a58c388682e46e5f9a101d463a Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Tue, 5 Nov 2024 15:12:41 +0200 Subject: [PATCH 3/7] move Account to core --- multiversx_sdk/__init__.py | 7 ++--- multiversx_sdk/core/__init__.py | 4 +-- multiversx_sdk/core/account.py | 31 +++--------------- multiversx_sdk/core/account_test.py | 14 ++++++--- multiversx_sdk/facades/__init__.py | 3 +- multiversx_sdk/facades/account.py | 45 --------------------------- multiversx_sdk/facades/entrypoints.py | 2 +- 7 files changed, 20 insertions(+), 86 deletions(-) delete mode 100644 multiversx_sdk/facades/account.py diff --git a/multiversx_sdk/__init__.py b/multiversx_sdk/__init__.py index 234be295..9435093e 100644 --- a/multiversx_sdk/__init__.py +++ b/multiversx_sdk/__init__.py @@ -7,7 +7,7 @@ from multiversx_sdk.controllers.token_management_controller import \ TokenManagementController from multiversx_sdk.controllers.transfers_controller import TransfersController -from multiversx_sdk.core.account import AccountNonceHolder +from multiversx_sdk.core.account import Account from multiversx_sdk.core.address import (Address, AddressComputer, AddressFactory) from multiversx_sdk.core.code_metadata import CodeMetadata @@ -57,7 +57,6 @@ UnPauseOutcome, UpdateAttributesOutcome, WipeOutcome) from multiversx_sdk.core.transactions_outcome_parsers.transaction_events_parser import \ TransactionEventsParser -from multiversx_sdk.facades.account import Account from multiversx_sdk.facades.entrypoints import (DevnetEntrypoint, MainnetEntrypoint, NetworkEntrypoint, @@ -86,7 +85,7 @@ from multiversx_sdk.wallet.validator_verifier import ValidatorVerifier __all__ = [ - "AccountNonceHolder", "Address", "AddressFactory", "AddressComputer", "Transaction", "TransactionComputer", + "Account", "Address", "AddressFactory", "AddressComputer", "Transaction", "TransactionComputer", "Message", "MessageComputer", "CodeMetadata", "Token", "TokenComputer", "TokenTransfer", "TokenIdentifierParts", "TokenManagementTransactionsOutcomeParser", "SmartContractResult", "TransactionEvent", "TransactionLogs", "DelegationTransactionsFactory", "TokenManagementTransactionsFactory", "TransactionsFactoryConfig", "TokenType", @@ -97,7 +96,7 @@ "DelegationTransactionsOutcomeParser", "find_events_by_identifier", "find_events_by_first_topic", "SmartContractTransactionsOutcomeParser", "TransactionAwaiter", "SmartContractQueriesController", "SmartContractQuery", "SmartContractQueryResponse", "TransactionDecoder", - "TransactionMetadata", "TransactionEventsParser", "NetworkProviderConfig", "Account", "DevnetEntrypoint", + "TransactionMetadata", "TransactionEventsParser", "NetworkProviderConfig", "DevnetEntrypoint", "MainnetEntrypoint", "NetworkEntrypoint", "TestnetEntrypoint", "AccountController", "DelegationController", "RelayedController", "SmartContractController", "TokenManagementController", "TransfersController", "CreateNewDelegationContractOutcome", "SmartContractDeployOutcome", "DeployedSmartContract", "IssueFungibleOutcome", diff --git a/multiversx_sdk/core/__init__.py b/multiversx_sdk/core/__init__.py index 7805ce36..b3d9141f 100644 --- a/multiversx_sdk/core/__init__.py +++ b/multiversx_sdk/core/__init__.py @@ -1,4 +1,4 @@ -from multiversx_sdk.core.account import AccountNonceHolder +from multiversx_sdk.core.account import Account from multiversx_sdk.core.address import (Address, AddressComputer, AddressFactory) from multiversx_sdk.core.code_metadata import CodeMetadata @@ -33,7 +33,7 @@ UnFreezeOutcome, UnPauseOutcome, UpdateAttributesOutcome, WipeOutcome) __all__ = [ - "AccountNonceHolder", "Address", "AddressFactory", "AddressComputer", + "Account", "Address", "AddressFactory", "AddressComputer", "Transaction", "TransactionComputer", "Message", "MessageComputer", "CodeMetadata", "Token", "TokenComputer", "TokenTransfer", "TokenIdentifierParts", diff --git a/multiversx_sdk/core/account.py b/multiversx_sdk/core/account.py index f74d0e22..7571cf37 100644 --- a/multiversx_sdk/core/account.py +++ b/multiversx_sdk/core/account.py @@ -1,32 +1,9 @@ -from multiversx_sdk.wallet.user_wallet import UserWallet -from multiversx_sdk.wallet.user_signer import UserSigner -from multiversx_sdk.wallet.mnemonic import Mnemonic -from multiversx_sdk.core.constants import DEFAULT_HRP from pathlib import Path - -class AccountNonceHolder(): - """An abstraction representing an account's nonce on the Network.""" - - def __init__(self, initial_nonce: int = 0): - """Creates an acount nonce holder object from an initial nonce. - - Args: - initial_nonce (int): the current nonce of the account""" - self.nonce = initial_nonce - - def get_nonce_then_increment(self) -> int: - """Returns the current nonce then increments it - - Returns: - int: the current nonce""" - nonce = self.nonce - self.increment_nonce() - return nonce - - def increment_nonce(self): - """Increments the current nonce""" - self.nonce += 1 +from multiversx_sdk.core.constants import DEFAULT_HRP +from multiversx_sdk.wallet.mnemonic import Mnemonic +from multiversx_sdk.wallet.user_signer import UserSigner +from multiversx_sdk.wallet.user_wallet import UserWallet class Account: diff --git a/multiversx_sdk/core/account_test.py b/multiversx_sdk/core/account_test.py index 6c099638..ade3529f 100644 --- a/multiversx_sdk/core/account_test.py +++ b/multiversx_sdk/core/account_test.py @@ -1,14 +1,18 @@ -from multiversx_sdk.core.account import AccountNonceHolder +from pathlib import Path + +from multiversx_sdk.core.account import Account + +alice = Path(__file__).parent.parent / "testutils" / "testwallets" / "alice.pem" def test_account_nonce_holder(): - account = AccountNonceHolder(41) + account = Account.new_from_pem(alice) account.nonce = 42 assert account.get_nonce_then_increment() == 42 assert account.get_nonce_then_increment() == 43 - account.increment_nonce() - account.increment_nonce() - account.increment_nonce() + account.get_nonce_then_increment() + account.get_nonce_then_increment() + account.get_nonce_then_increment() assert account.nonce == 47 diff --git a/multiversx_sdk/facades/__init__.py b/multiversx_sdk/facades/__init__.py index 021da50c..755929d6 100644 --- a/multiversx_sdk/facades/__init__.py +++ b/multiversx_sdk/facades/__init__.py @@ -1,9 +1,8 @@ -from multiversx_sdk.facades.account import Account from multiversx_sdk.facades.entrypoints import (DevnetEntrypoint, MainnetEntrypoint, NetworkEntrypoint, TestnetEntrypoint) __all__ = [ - "Account", "DevnetEntrypoint", "MainnetEntrypoint", "NetworkEntrypoint", "TestnetEntrypoint" + "DevnetEntrypoint", "MainnetEntrypoint", "NetworkEntrypoint", "TestnetEntrypoint" ] diff --git a/multiversx_sdk/facades/account.py b/multiversx_sdk/facades/account.py deleted file mode 100644 index 57caedc0..00000000 --- a/multiversx_sdk/facades/account.py +++ /dev/null @@ -1,45 +0,0 @@ -from pathlib import Path - -from multiversx_sdk.core.constants import DEFAULT_HRP -from multiversx_sdk.wallet.mnemonic import Mnemonic -from multiversx_sdk.wallet.user_signer import UserSigner -from multiversx_sdk.wallet.user_wallet import UserWallet - - -class Account: - def __init__(self, signer: UserSigner, hrp: str = DEFAULT_HRP) -> None: - self.signer = signer - self.address = signer.get_pubkey().to_address(hrp) - self.nonce = 0 - - @classmethod - def new_from_pem(cls, file_path: Path, index: int = 0, hrp: str = DEFAULT_HRP) -> "Account": - signer = UserSigner.from_pem_file(file_path, index) - return Account(signer, hrp) - - @classmethod - def new_from_keystore(cls, - file_path: Path, - password: str, - address_index: int = 0, - hrp: str = DEFAULT_HRP) -> "Account": - secret_key = UserWallet.load_secret_key(file_path, password, address_index) - signer = UserSigner(secret_key) - return Account(signer, hrp) - - @classmethod - def new_from_mnemonic(cls, - mnemonic: str, - address_index: int = 0, - hrp: str = DEFAULT_HRP) -> "Account": - mnemonic_handler = Mnemonic(mnemonic) - secret_key = mnemonic_handler.derive_key(address_index) - return Account(UserSigner(secret_key), hrp) - - def sign(self, data: bytes) -> bytes: - return self.signer.sign(data) - - def get_nonce_then_increment(self) -> int: - nonce = self.nonce - self.nonce += 1 - return nonce diff --git a/multiversx_sdk/facades/entrypoints.py b/multiversx_sdk/facades/entrypoints.py index ada906ba..093d58dd 100644 --- a/multiversx_sdk/facades/entrypoints.py +++ b/multiversx_sdk/facades/entrypoints.py @@ -14,7 +14,7 @@ from multiversx_sdk.core.transaction import Transaction from multiversx_sdk.core.transaction_computer import TransactionComputer from multiversx_sdk.core.transaction_on_network import TransactionOnNetwork -from multiversx_sdk.facades.account import Account +from multiversx_sdk.core.account import Account from multiversx_sdk.facades.config import (DevnetEntrypointConfig, MainnetEntrypointConfig, TestnetEntrypointConfig) From 243b0c6857d8f4e5cf4b23a6c50c58abc5a3f1f2 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Tue, 5 Nov 2024 15:16:21 +0200 Subject: [PATCH 4/7] fix linter issues --- multiversx_sdk/network_providers/transaction_awaiter_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/multiversx_sdk/network_providers/transaction_awaiter_test.py b/multiversx_sdk/network_providers/transaction_awaiter_test.py index 3f7a2b64..53f12fb0 100644 --- a/multiversx_sdk/network_providers/transaction_awaiter_test.py +++ b/multiversx_sdk/network_providers/transaction_awaiter_test.py @@ -46,8 +46,8 @@ def test_on_network(self): tx_computer = TransactionComputer() transaction = Transaction( - sender=alice.label, - receiver=alice.label, + sender=Address.new_from_bech32(alice.label), + receiver=Address.new_from_bech32(alice.label), gas_limit=50000, chain_id="D", ) From b0405d0497b4caf89c2fd4b9b544601e72c5e135 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Tue, 5 Nov 2024 16:39:53 +0200 Subject: [PATCH 5/7] fixes after review --- multiversx_sdk/controllers/interfaces.py | 17 ----------------- .../controllers/smart_contract_controller.py | 5 ++--- multiversx_sdk/core/account.py | 3 +-- multiversx_sdk/core/transaction_computer.py | 6 ++---- multiversx_sdk/core/transaction_test.py | 6 +----- multiversx_sdk/facades/entrypoints.py | 2 +- 6 files changed, 7 insertions(+), 32 deletions(-) diff --git a/multiversx_sdk/controllers/interfaces.py b/multiversx_sdk/controllers/interfaces.py index 86f37f93..25bad3ba 100644 --- a/multiversx_sdk/controllers/interfaces.py +++ b/multiversx_sdk/controllers/interfaces.py @@ -6,23 +6,6 @@ from multiversx_sdk.network_providers.resources import AwaitingOptions -class IAddress(Protocol): - def to_bech32(self) -> str: - ... - - def to_hex(self) -> str: - ... - - -class IAccount(Protocol): - @property - def address(self) -> IAddress: - ... - - def sign(self, data: bytes) -> bytes: - ... - - class INetworkProvider(Protocol): def query_contract(self, query: SmartContractQuery) -> SmartContractQueryResponse: ... diff --git a/multiversx_sdk/controllers/smart_contract_controller.py b/multiversx_sdk/controllers/smart_contract_controller.py index a5f65bd3..9bb409c7 100644 --- a/multiversx_sdk/controllers/smart_contract_controller.py +++ b/multiversx_sdk/controllers/smart_contract_controller.py @@ -2,6 +2,7 @@ from typing import Any, List, Optional, Sequence, Union from multiversx_sdk.controllers.interfaces import IAbi, INetworkProvider +from multiversx_sdk.core.account import Account from multiversx_sdk.core.address import Address from multiversx_sdk.core.smart_contract_queries_controller import \ SmartContractQueriesController @@ -13,7 +14,6 @@ SmartContractTransactionsFactory, TransactionsFactoryConfig) from multiversx_sdk.core.transactions_outcome_parsers import ( SmartContractDeployOutcome, SmartContractTransactionsOutcomeParser) -from multiversx_sdk.core.account import Account class SmartContractController: @@ -53,8 +53,7 @@ def create_transaction_for_deploy(self, ) transaction.nonce = nonce - transaction.signature = sender.sign( - self.tx_computer.compute_bytes_for_signing(transaction)) + transaction.signature = sender.sign(self.tx_computer.compute_bytes_for_signing(transaction)) return transaction diff --git a/multiversx_sdk/core/account.py b/multiversx_sdk/core/account.py index 7571cf37..57caedc0 100644 --- a/multiversx_sdk/core/account.py +++ b/multiversx_sdk/core/account.py @@ -23,8 +23,7 @@ def new_from_keystore(cls, password: str, address_index: int = 0, hrp: str = DEFAULT_HRP) -> "Account": - secret_key = UserWallet.load_secret_key( - file_path, password, address_index) + secret_key = UserWallet.load_secret_key(file_path, password, address_index) signer = UserSigner(secret_key) return Account(signer, hrp) diff --git a/multiversx_sdk/core/transaction_computer.py b/multiversx_sdk/core/transaction_computer.py index 005466ad..e7674018 100644 --- a/multiversx_sdk/core/transaction_computer.py +++ b/multiversx_sdk/core/transaction_computer.py @@ -6,6 +6,7 @@ from Cryptodome.Hash import keccak +from multiversx_sdk.core.address import Address from multiversx_sdk.core.constants import ( BECH32_ADDRESS_LENGTH, DIGEST_SIZE, MIN_TRANSACTION_VERSION_THAT_SUPPORTS_OPTIONS, @@ -15,16 +16,13 @@ from multiversx_sdk.core.proto.transaction_serializer import ProtoSerializer from multiversx_sdk.core.transaction import Transaction -from multiversx_sdk.core.address import Address - class TransactionComputer: def __init__(self) -> None: pass def compute_transaction_fee(self, transaction: Transaction, network_config: INetworkConfig) -> int: - move_balance_gas = network_config.min_gas_limit + \ - len(transaction.data) * network_config.gas_per_data_byte + move_balance_gas = network_config.min_gas_limit + len(transaction.data) * network_config.gas_per_data_byte if move_balance_gas > transaction.gas_limit: raise NotEnoughGasError(transaction.gas_limit) diff --git a/multiversx_sdk/core/transaction_test.py b/multiversx_sdk/core/transaction_test.py index 4f47068b..06074914 100644 --- a/multiversx_sdk/core/transaction_test.py +++ b/multiversx_sdk/core/transaction_test.py @@ -2,6 +2,7 @@ import pytest +from multiversx_sdk.core.address import Address from multiversx_sdk.core.constants import \ MIN_TRANSACTION_VERSION_THAT_SUPPORTS_OPTIONS from multiversx_sdk.core.errors import BadUsageError, NotEnoughGasError @@ -13,8 +14,6 @@ from multiversx_sdk.wallet.user_pem import UserPEM from multiversx_sdk.wallet.user_verifer import UserVerifier -from multiversx_sdk.core.address import Address - class NetworkConfig: def __init__(self, min_gas_limit: int = 50000) -> None: @@ -359,9 +358,6 @@ def test_transaction_converter(self): ) tx_as_dict = transaction.to_dictionary() - print(transaction.__dict__) restored_tx = Transaction.new_from_dictionary(tx_as_dict) - print("------------") - print(restored_tx.__dict__) assert transaction == restored_tx diff --git a/multiversx_sdk/facades/entrypoints.py b/multiversx_sdk/facades/entrypoints.py index 093d58dd..bb0d152f 100644 --- a/multiversx_sdk/facades/entrypoints.py +++ b/multiversx_sdk/facades/entrypoints.py @@ -9,12 +9,12 @@ from multiversx_sdk.controllers.token_management_controller import \ TokenManagementController from multiversx_sdk.controllers.transfers_controller import TransfersController +from multiversx_sdk.core.account import Account from multiversx_sdk.core.address import Address from multiversx_sdk.core.message import Message, MessageComputer from multiversx_sdk.core.transaction import Transaction from multiversx_sdk.core.transaction_computer import TransactionComputer from multiversx_sdk.core.transaction_on_network import TransactionOnNetwork -from multiversx_sdk.core.account import Account from multiversx_sdk.facades.config import (DevnetEntrypointConfig, MainnetEntrypointConfig, TestnetEntrypointConfig) From 7a8b1f13b0cf5b5959c5391c4788d2a1543be6ca Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Wed, 6 Nov 2024 10:07:05 +0200 Subject: [PATCH 6/7] move account to separate package --- multiversx_sdk/__init__.py | 2 +- multiversx_sdk/accounts/__init__.py | 3 + multiversx_sdk/{core => accounts}/account.py | 0 .../{core => accounts}/account_test.py | 2 +- .../controllers/account_controller.py | 10 +- .../controllers/delegation_controller.py | 41 ++++---- multiversx_sdk/controllers/interfaces.py | 10 ++ .../controllers/relayed_controller.py | 7 +- .../controllers/smart_contract_controller.py | 9 +- .../token_management_controller.py | 95 ++++++++++--------- .../controllers/transfers_controller.py | 12 +-- multiversx_sdk/core/__init__.py | 3 +- multiversx_sdk/facades/entrypoints.py | 2 +- multiversx_sdk/facades/entrypoints_test.py | 2 +- multiversx_sdk/network_providers/interface.py | 16 ---- 15 files changed, 103 insertions(+), 111 deletions(-) create mode 100644 multiversx_sdk/accounts/__init__.py rename multiversx_sdk/{core => accounts}/account.py (100%) rename multiversx_sdk/{core => accounts}/account_test.py (89%) diff --git a/multiversx_sdk/__init__.py b/multiversx_sdk/__init__.py index 9435093e..185418dc 100644 --- a/multiversx_sdk/__init__.py +++ b/multiversx_sdk/__init__.py @@ -1,3 +1,4 @@ +from multiversx_sdk.accounts import Account from multiversx_sdk.controllers.account_controller import AccountController from multiversx_sdk.controllers.delegation_controller import \ DelegationController @@ -7,7 +8,6 @@ from multiversx_sdk.controllers.token_management_controller import \ TokenManagementController from multiversx_sdk.controllers.transfers_controller import TransfersController -from multiversx_sdk.core.account import Account from multiversx_sdk.core.address import (Address, AddressComputer, AddressFactory) from multiversx_sdk.core.code_metadata import CodeMetadata diff --git a/multiversx_sdk/accounts/__init__.py b/multiversx_sdk/accounts/__init__.py new file mode 100644 index 00000000..f3d74fd5 --- /dev/null +++ b/multiversx_sdk/accounts/__init__.py @@ -0,0 +1,3 @@ +from multiversx_sdk.accounts.account import Account + +__all__ = ["Account"] diff --git a/multiversx_sdk/core/account.py b/multiversx_sdk/accounts/account.py similarity index 100% rename from multiversx_sdk/core/account.py rename to multiversx_sdk/accounts/account.py diff --git a/multiversx_sdk/core/account_test.py b/multiversx_sdk/accounts/account_test.py similarity index 89% rename from multiversx_sdk/core/account_test.py rename to multiversx_sdk/accounts/account_test.py index ade3529f..eead8c68 100644 --- a/multiversx_sdk/core/account_test.py +++ b/multiversx_sdk/accounts/account_test.py @@ -1,7 +1,7 @@ from pathlib import Path -from multiversx_sdk.core.account import Account +from multiversx_sdk.accounts.account import Account alice = Path(__file__).parent.parent / "testutils" / "testwallets" / "alice.pem" diff --git a/multiversx_sdk/controllers/account_controller.py b/multiversx_sdk/controllers/account_controller.py index 40c75604..aaadd735 100644 --- a/multiversx_sdk/controllers/account_controller.py +++ b/multiversx_sdk/controllers/account_controller.py @@ -1,6 +1,6 @@ from typing import Dict -from multiversx_sdk.core.account import Account +from multiversx_sdk.controllers.interfaces import IAccount from multiversx_sdk.core.address import Address from multiversx_sdk.core.transaction import Transaction from multiversx_sdk.core.transaction_computer import TransactionComputer @@ -15,7 +15,7 @@ def __init__(self, chain_id: str) -> None: self.tx_computer = TransactionComputer() def create_transaction_for_saving_key_value(self, - sender: Account, + sender: IAccount, nonce: int, key_value_pairs: Dict[bytes, bytes]) -> Transaction: transaction = self.factory.create_transaction_for_saving_key_value( @@ -29,7 +29,7 @@ def create_transaction_for_saving_key_value(self, return transaction def create_transaction_for_setting_guardian(self, - sender: Account, + sender: IAccount, nonce: int, guardian_address: Address, service_id: str) -> Transaction: @@ -45,7 +45,7 @@ def create_transaction_for_setting_guardian(self, return transaction def create_transaction_for_guarding_account(self, - sender: Account, + sender: IAccount, nonce: int) -> Transaction: transaction = self.factory.create_transaction_for_guarding_account( sender=sender.address @@ -58,7 +58,7 @@ def create_transaction_for_guarding_account(self, return transaction def create_transaction_for_unguarding_account(self, - sender: Account, + sender: IAccount, nonce: int) -> Transaction: transaction = self.factory.create_transaction_for_unguarding_account( sender=sender.address diff --git a/multiversx_sdk/controllers/delegation_controller.py b/multiversx_sdk/controllers/delegation_controller.py index 0783b469..8935db77 100644 --- a/multiversx_sdk/controllers/delegation_controller.py +++ b/multiversx_sdk/controllers/delegation_controller.py @@ -1,6 +1,6 @@ from typing import List, Sequence -from multiversx_sdk.controllers.interfaces import INetworkProvider +from multiversx_sdk.controllers.interfaces import IAccount, INetworkProvider from multiversx_sdk.core.address import Address from multiversx_sdk.core.interfaces import IValidatorPublicKey from multiversx_sdk.core.transaction import Transaction @@ -10,7 +10,6 @@ DelegationTransactionsFactory, TransactionsFactoryConfig) from multiversx_sdk.core.transactions_outcome_parsers.delegation_transactions_outcome_parser import ( CreateNewDelegationContractOutcome, DelegationTransactionsOutcomeParser) -from multiversx_sdk.core.account import Account class DelegationController: @@ -21,7 +20,7 @@ def __init__(self, chain_id: str, network_provider: INetworkProvider) -> None: self.tx_computer = TransactionComputer() def create_transaction_for_new_delegation_contract(self, - sender: Account, + sender: IAccount, nonce: int, total_delegation_cap: int, service_fee: int, @@ -48,7 +47,7 @@ def await_completed_create_new_delegation_contract( return self.parse_create_new_delegation_contract(transaction) def create_transaction_for_adding_nodes(self, - sender: Account, + sender: IAccount, nonce: int, delegation_contract: Address, public_keys: Sequence[IValidatorPublicKey], @@ -66,7 +65,7 @@ def create_transaction_for_adding_nodes(self, return transaction def create_transaction_for_removing_nodes(self, - sender: Account, + sender: IAccount, nonce: int, delegation_contract: Address, public_keys: Sequence[IValidatorPublicKey]) -> Transaction: @@ -82,7 +81,7 @@ def create_transaction_for_removing_nodes(self, return transaction def create_transaction_for_staking_nodes(self, - sender: Account, + sender: IAccount, nonce: int, delegation_contract: Address, public_keys: Sequence[IValidatorPublicKey]) -> Transaction: @@ -98,7 +97,7 @@ def create_transaction_for_staking_nodes(self, return transaction def create_transaction_for_unbonding_nodes(self, - sender: Account, + sender: IAccount, nonce: int, delegation_contract: Address, public_keys: Sequence[IValidatorPublicKey]) -> Transaction: @@ -114,7 +113,7 @@ def create_transaction_for_unbonding_nodes(self, return transaction def create_transaction_for_unstaking_nodes(self, - sender: Account, + sender: IAccount, nonce: int, delegation_contract: Address, public_keys: Sequence[IValidatorPublicKey]) -> Transaction: @@ -130,7 +129,7 @@ def create_transaction_for_unstaking_nodes(self, return transaction def create_transaction_for_unjailing_nodes(self, - sender: Account, + sender: IAccount, nonce: int, delegation_contract: Address, public_keys: Sequence[IValidatorPublicKey], @@ -148,7 +147,7 @@ def create_transaction_for_unjailing_nodes(self, return transaction def create_transaction_for_changing_service_fee(self, - sender: Account, + sender: IAccount, nonce: int, delegation_contract: Address, service_fee: int) -> Transaction: @@ -164,7 +163,7 @@ def create_transaction_for_changing_service_fee(self, return transaction def create_transaction_for_modifying_delegation_cap(self, - sender: Account, + sender: IAccount, nonce: int, delegation_contract: Address, delegation_cap: int) -> Transaction: @@ -180,7 +179,7 @@ def create_transaction_for_modifying_delegation_cap(self, return transaction def create_transaction_for_setting_automatic_activation(self, - sender: Account, + sender: IAccount, nonce: int, delegation_contract: Address) -> Transaction: transaction = self.factory.create_transaction_for_setting_automatic_activation( @@ -194,7 +193,7 @@ def create_transaction_for_setting_automatic_activation(self, return transaction def create_transaction_for_unsetting_automatic_activation(self, - sender: Account, + sender: IAccount, nonce: int, delegation_contract: Address) -> Transaction: transaction = self.factory.create_transaction_for_unsetting_automatic_activation( @@ -208,7 +207,7 @@ def create_transaction_for_unsetting_automatic_activation(self, return transaction def create_transaction_for_setting_cap_check_on_redelegate_rewards(self, - sender: Account, + sender: IAccount, nonce: int, delegation_contract: Address) -> Transaction: transaction = self.factory.create_transaction_for_setting_cap_check_on_redelegate_rewards( @@ -222,7 +221,7 @@ def create_transaction_for_setting_cap_check_on_redelegate_rewards(self, return transaction def create_transaction_for_unsetting_cap_check_on_redelegate_rewards(self, - sender: Account, + sender: IAccount, nonce: int, delegation_contract: Address) -> Transaction: transaction = self.factory.create_transaction_for_unsetting_cap_check_on_redelegate_rewards( @@ -236,7 +235,7 @@ def create_transaction_for_unsetting_cap_check_on_redelegate_rewards(self, return transaction def create_transaction_for_setting_metadata(self, - sender: Account, + sender: IAccount, nonce: int, delegation_contract: Address, name: str, @@ -256,7 +255,7 @@ def create_transaction_for_setting_metadata(self, return transaction def create_transaction_for_delegating(self, - sender: Account, + sender: IAccount, nonce: int, delegation_contract: Address, amount: int) -> Transaction: @@ -272,7 +271,7 @@ def create_transaction_for_delegating(self, return transaction def create_transaction_for_claiming_rewards(self, - sender: Account, + sender: IAccount, nonce: int, delegation_contract: Address) -> Transaction: transaction = self.factory.create_transaction_for_claiming_rewards( @@ -286,7 +285,7 @@ def create_transaction_for_claiming_rewards(self, return transaction def create_transaction_for_redelegating_rewards(self, - sender: Account, + sender: IAccount, nonce: int, delegation_contract: Address) -> Transaction: transaction = self.factory.create_transaction_for_redelegating_rewards( @@ -300,7 +299,7 @@ def create_transaction_for_redelegating_rewards(self, return transaction def create_transaction_for_undelegating(self, - sender: Account, + sender: IAccount, nonce: int, delegation_contract: Address, amount: int) -> Transaction: @@ -316,7 +315,7 @@ def create_transaction_for_undelegating(self, return transaction def create_transaction_for_withdrawing(self, - sender: Account, + sender: IAccount, nonce: int, delegation_contract: Address) -> Transaction: transaction = self.factory.create_transaction_for_withdrawing( diff --git a/multiversx_sdk/controllers/interfaces.py b/multiversx_sdk/controllers/interfaces.py index 25bad3ba..19e1c640 100644 --- a/multiversx_sdk/controllers/interfaces.py +++ b/multiversx_sdk/controllers/interfaces.py @@ -1,11 +1,21 @@ from typing import Any, List, Optional, Protocol, Union +from multiversx_sdk.core.address import Address from multiversx_sdk.core.smart_contract_query import ( SmartContractQuery, SmartContractQueryResponse) from multiversx_sdk.core.transaction_on_network import TransactionOnNetwork from multiversx_sdk.network_providers.resources import AwaitingOptions +class IAccount(Protocol): + @property + def address(self) -> Address: + ... + + def sign(self, data: bytes) -> bytes: + ... + + class INetworkProvider(Protocol): def query_contract(self, query: SmartContractQuery) -> SmartContractQueryResponse: ... diff --git a/multiversx_sdk/controllers/relayed_controller.py b/multiversx_sdk/controllers/relayed_controller.py index 4e36948a..87d69452 100644 --- a/multiversx_sdk/controllers/relayed_controller.py +++ b/multiversx_sdk/controllers/relayed_controller.py @@ -1,10 +1,9 @@ +from multiversx_sdk.controllers.interfaces import IAccount from multiversx_sdk.core.transaction import Transaction from multiversx_sdk.core.transaction_computer import TransactionComputer from multiversx_sdk.core.transactions_factories import ( RelayedTransactionsFactory, TransactionsFactoryConfig) -from multiversx_sdk.core.account import Account - class RelayedController: """The transactions are created from the perspective of the relayer. The 'sender' represents the relayer.""" @@ -14,7 +13,7 @@ def __init__(self, chain_id: str) -> None: self.tx_computer = TransactionComputer() def create_relayed_v1_transaction(self, - sender: Account, + sender: IAccount, nonce: int, inner_transaction: Transaction) -> Transaction: transaction = self.factory.create_relayed_v1_transaction( @@ -28,7 +27,7 @@ def create_relayed_v1_transaction(self, return transaction def create_relayed_v2_transaction(self, - sender: Account, + sender: IAccount, nonce: int, inner_transaction: Transaction, inner_transaction_gas_limit: int) -> Transaction: diff --git a/multiversx_sdk/controllers/smart_contract_controller.py b/multiversx_sdk/controllers/smart_contract_controller.py index 9bb409c7..e362c100 100644 --- a/multiversx_sdk/controllers/smart_contract_controller.py +++ b/multiversx_sdk/controllers/smart_contract_controller.py @@ -1,8 +1,7 @@ from pathlib import Path from typing import Any, List, Optional, Sequence, Union -from multiversx_sdk.controllers.interfaces import IAbi, INetworkProvider -from multiversx_sdk.core.account import Account +from multiversx_sdk.controllers.interfaces import IAbi, IAccount, INetworkProvider from multiversx_sdk.core.address import Address from multiversx_sdk.core.smart_contract_queries_controller import \ SmartContractQueriesController @@ -30,7 +29,7 @@ def __init__(self, chain_id: str, network_provider: INetworkProvider, abi: Optio self.tx_computer = TransactionComputer() def create_transaction_for_deploy(self, - sender: Account, + sender: IAccount, nonce: int, bytecode: Union[Path, bytes], gas_limit: int, @@ -66,7 +65,7 @@ def await_completed_deploy(self, transaction_hash: Union[str, bytes]) -> SmartCo return self.parse_deploy(transaction) def create_transaction_for_upgrade(self, - sender: Account, + sender: IAccount, nonce: int, contract: Address, bytecode: Union[Path, bytes], @@ -96,7 +95,7 @@ def create_transaction_for_upgrade(self, return transaction def create_transaction_for_execute(self, - sender: Account, + sender: IAccount, nonce: int, contract: Address, gas_limit: int, diff --git a/multiversx_sdk/controllers/token_management_controller.py b/multiversx_sdk/controllers/token_management_controller.py index 0dbee1f1..7ddd0f53 100644 --- a/multiversx_sdk/controllers/token_management_controller.py +++ b/multiversx_sdk/controllers/token_management_controller.py @@ -1,6 +1,7 @@ from typing import List, Union -from multiversx_sdk.controllers.interfaces import INetworkProvider +from multiversx_sdk.controllers.interfaces import IAccount, INetworkProvider +from multiversx_sdk.core.address import Address from multiversx_sdk.core.transaction import Transaction from multiversx_sdk.core.transaction_computer import TransactionComputer from multiversx_sdk.core.transaction_on_network import TransactionOnNetwork @@ -14,10 +15,6 @@ TokenManagementTransactionsOutcomeParser, UnFreezeOutcome, UnPauseOutcome, UpdateAttributesOutcome, WipeOutcome) -from multiversx_sdk.core.account import Account - -from multiversx_sdk.core.address import Address - class TokenManagementController: def __init__(self, chain_id: str, network_provider: INetworkProvider) -> None: @@ -27,7 +24,7 @@ def __init__(self, chain_id: str, network_provider: INetworkProvider) -> None: self.parser = TokenManagementTransactionsOutcomeParser() def create_transaction_for_issuing_fungible(self, - sender: Account, + sender: IAccount, nonce: int, token_name: str, token_ticker: str, @@ -66,7 +63,7 @@ def await_completed_issue_fungible(self, transaction_hash: Union[str, bytes]) -> return self.parse_issue_fungible(transaction) def create_transaction_for_issuing_semi_fungible(self, - sender: Account, + sender: IAccount, nonce: int, token_name: str, token_ticker: str, @@ -104,7 +101,7 @@ def await_completed_issue_semi_fungible( return self.parse_issue_semi_fungible(transaction) def create_transaction_for_issuing_non_fungible(self, - sender: Account, + sender: IAccount, nonce: int, token_name: str, token_ticker: str, @@ -141,7 +138,7 @@ def await_completed_issue_non_fungible(self, transaction_hash: Union[str, bytes] return self.parse_issue_non_fungible(transaction) def create_transaction_for_registering_meta_esdt(self, - sender: Account, + sender: IAccount, nonce: int, token_name: str, token_ticker: str, @@ -180,7 +177,7 @@ def await_completed_register_meta_esdt(self, transaction_hash: Union[str, bytes] return self.parse_register_meta_esdt(transaction) def create_transaction_for_registering_and_setting_roles(self, - sender: Account, + sender: IAccount, nonce: int, token_name: str, token_ticker: str, @@ -199,17 +196,15 @@ def create_transaction_for_registering_and_setting_roles(self, return transaction - def parse_register_and_set_all_roles( - self, transaction_on_network: TransactionOnNetwork) -> List[RegisterAndSetAllRolesOutcome]: + def parse_register_and_set_all_roles(self, transaction_on_network: TransactionOnNetwork) -> List[RegisterAndSetAllRolesOutcome]: return self.parser.parse_register_and_set_all_roles(transaction_on_network) - def await_completed_register_and_set_all_roles( - self, transaction_hash: Union[str, bytes]) -> List[RegisterAndSetAllRolesOutcome]: + def await_completed_register_and_set_all_roles(self, transaction_hash: Union[str, bytes]) -> List[RegisterAndSetAllRolesOutcome]: transaction = self.network_provider.await_transaction_completed(transaction_hash) return self.parse_register_and_set_all_roles(transaction) def create_transaction_for_setting_burn_role_globally(self, - sender: Account, + sender: IAccount, nonce: int, token_identifier: str) -> Transaction: transaction = self.factory.create_transaction_for_setting_burn_role_globally( @@ -230,7 +225,7 @@ def await_completed_set_burn_role_globally(self, transaction_hash: Union[str, by return self.parse_set_burn_role_globally(transaction) def create_transaction_for_unsetting_burn_role_globally(self, - sender: Account, + sender: IAccount, nonce: int, token_identifier: str) -> Transaction: transaction = self.factory.create_transaction_for_unsetting_burn_role_globally( @@ -251,7 +246,7 @@ def await_completed_unset_burn_role_globally(self, transaction_hash: Union[str, return self.parse_unset_burn_role_globally(transaction) def create_transaction_for_setting_special_role_on_fungible_token(self, - sender: Account, + sender: IAccount, nonce: int, user: Address, token_identifier: str, @@ -272,18 +267,22 @@ def create_transaction_for_setting_special_role_on_fungible_token(self, return transaction - def parse_set_special_role_on_fungible_token( - self, transaction_on_network: TransactionOnNetwork) -> List[SetSpecialRoleOutcome]: + def parse_set_special_role_on_fungible_token(self, transaction_on_network: TransactionOnNetwork) -> List[SetSpecialRoleOutcome]: return self.parser.parse_set_special_role(transaction_on_network) - def await_completed_set_special_role_on_fungible_token( - self, transaction_hash: Union[str, bytes]) -> List[SetSpecialRoleOutcome]: + def await_completed_set_special_role_on_fungible_token(self, transaction_hash: Union[str, bytes]) -> List[SetSpecialRoleOutcome]: transaction = self.network_provider.await_transaction_completed(transaction_hash) return self.parse_set_special_role_on_fungible_token(transaction) - def create_transaction_for_setting_special_role_on_semi_fungible_token( - self, sender: Account, nonce: int, user: Address, token_identifier: str, add_role_nft_create: bool, - add_role_nft_burn: bool, add_role_nft_add_quantity: bool, add_role_esdt_transfer_role: bool) -> Transaction: + def create_transaction_for_setting_special_role_on_semi_fungible_token(self, + sender: IAccount, + nonce: int, + user: Address, + token_identifier: str, + add_role_nft_create: bool, + add_role_nft_burn: bool, + add_role_nft_add_quantity: bool, + add_role_esdt_transfer_role: bool) -> Transaction: transaction = self.factory.create_transaction_for_setting_special_role_on_semi_fungible_token( sender=sender.address, user=user, @@ -299,19 +298,23 @@ def create_transaction_for_setting_special_role_on_semi_fungible_token( return transaction - def parse_set_special_role_on_semi_fungible_token( - self, transaction_on_network: TransactionOnNetwork) -> List[SetSpecialRoleOutcome]: + def parse_set_special_role_on_semi_fungible_token(self, transaction_on_network: TransactionOnNetwork) -> List[SetSpecialRoleOutcome]: return self.parser.parse_set_special_role(transaction_on_network) - def await_completed_set_special_role_on_semi_fungible_token( - self, transaction_hash: Union[str, bytes]) -> List[SetSpecialRoleOutcome]: + def await_completed_set_special_role_on_semi_fungible_token(self, transaction_hash: Union[str, bytes]) -> List[SetSpecialRoleOutcome]: transaction = self.network_provider.await_transaction_completed(transaction_hash) return self.parse_set_special_role_on_semi_fungible_token(transaction) - def create_transaction_for_setting_special_role_on_non_fungible_token( - self, sender: Account, nonce: int, user: Address, token_identifier: str, add_role_nft_create: bool, - add_role_nft_burn: bool, add_role_nft_update_attributes: bool, add_role_nft_add_uri: bool, - add_role_esdt_transfer_role: bool) -> Transaction: + def create_transaction_for_setting_special_role_on_non_fungible_token(self, + sender: IAccount, + nonce: int, + user: Address, + token_identifier: str, + add_role_nft_create: bool, + add_role_nft_burn: bool, + add_role_nft_update_attributes: bool, + add_role_nft_add_uri: bool, + add_role_esdt_transfer_role: bool) -> Transaction: transaction = self.factory.create_transaction_for_setting_special_role_on_non_fungible_token( sender=sender.address, user=user, @@ -328,17 +331,15 @@ def create_transaction_for_setting_special_role_on_non_fungible_token( return transaction - def parse_set_special_role_on_non_fungible_token( - self, transaction_on_network: TransactionOnNetwork) -> List[SetSpecialRoleOutcome]: + def parse_set_special_role_on_non_fungible_token(self, transaction_on_network: TransactionOnNetwork) -> List[SetSpecialRoleOutcome]: return self.parser.parse_set_special_role(transaction_on_network) - def await_completed_set_special_role_on_non_fungible_token( - self, transaction_hash: Union[str, bytes]) -> List[SetSpecialRoleOutcome]: + def await_completed_set_special_role_on_non_fungible_token(self, transaction_hash: Union[str, bytes]) -> List[SetSpecialRoleOutcome]: transaction = self.network_provider.await_transaction_completed(transaction_hash) return self.parse_set_special_role_on_non_fungible_token(transaction) def create_transaction_for_creating_nft(self, - sender: Account, + sender: IAccount, nonce: int, token_identifier: str, initial_quantity: int, @@ -371,7 +372,7 @@ def await_completed_create_nft(self, transaction_hash: Union[str, bytes]) -> Lis return self.parse_create_nft(transaction) def create_transaction_for_pausing(self, - sender: Account, + sender: IAccount, nonce: int, token_identifier: str) -> Transaction: transaction = self.factory.create_transaction_for_pausing( @@ -392,7 +393,7 @@ def await_completed_pause(self, transaction_hash: Union[str, bytes]) -> List[Pau return self.parse_pause(transaction) def create_transaction_for_unpausing(self, - sender: Account, + sender: IAccount, nonce: int, token_identifier: str) -> Transaction: transaction = self.factory.create_transaction_for_unpausing( @@ -413,7 +414,7 @@ def await_completed_unpause(self, transaction_hash: Union[str, bytes]) -> List[U return self.parse_unpause(transaction) def create_transaction_for_freezing(self, - sender: Account, + sender: IAccount, nonce: int, user: Address, token_identifier: str) -> Transaction: @@ -436,7 +437,7 @@ def await_completed_freeze(self, transaction_hash: Union[str, bytes]) -> List[Fr return self.parse_freeze(transaction) def create_transaction_for_unfreezing(self, - sender: Account, + sender: IAccount, nonce: int, user: Address, token_identifier: str) -> Transaction: @@ -459,7 +460,7 @@ def await_completed_unfreeze(self, transaction_hash: Union[str, bytes]) -> List[ return self.parse_unfreeze(transaction) def create_transaction_for_wiping(self, - sender: Account, + sender: IAccount, nonce: int, user: Address, token_identifier: str) -> Transaction: @@ -482,7 +483,7 @@ def await_completed_wipe(self, transaction_hash: Union[str, bytes]) -> List[Wipe return self.parse_wipe(transaction) def create_transaction_for_local_minting(self, - sender: Account, + sender: IAccount, nonce: int, token_identifier: str, supply_to_mint: int) -> Transaction: @@ -505,7 +506,7 @@ def await_completed_local_mint(self, transaction_hash: Union[str, bytes]) -> Lis return self.parse_local_mint(transaction) def create_transaction_for_local_burning(self, - sender: Account, + sender: IAccount, nonce: int, token_identifier: str, supply_to_burn: int) -> Transaction: @@ -528,7 +529,7 @@ def await_completed_local_burn(self, transaction_hash: Union[str, bytes]) -> Lis return self.parse_local_burn(transaction) def create_transaction_for_updating_attributes(self, - sender: Account, + sender: IAccount, nonce: int, token_identifier: str, token_nonce: int, @@ -553,7 +554,7 @@ def await_completed_update_attributes(self, transaction_hash: Union[str, bytes]) return self.parse_update_attributes(transaction) def create_transaction_for_adding_quantity(self, - sender: Account, + sender: IAccount, nonce: int, token_identifier: str, token_nonce: int, @@ -578,7 +579,7 @@ def await_completed_add_quantity(self, transaction_hash: Union[str, bytes]) -> L return self.parse_add_quantity(transaction) def create_transaction_for_burning_quantity(self, - sender: Account, + sender: IAccount, nonce: int, token_identifier: str, token_nonce: int, diff --git a/multiversx_sdk/controllers/transfers_controller.py b/multiversx_sdk/controllers/transfers_controller.py index d9a5f36d..a93747a7 100644 --- a/multiversx_sdk/controllers/transfers_controller.py +++ b/multiversx_sdk/controllers/transfers_controller.py @@ -1,15 +1,13 @@ from typing import List, Optional +from multiversx_sdk.controllers.interfaces import IAccount +from multiversx_sdk.core.address import Address from multiversx_sdk.core.tokens import TokenTransfer from multiversx_sdk.core.transaction import Transaction from multiversx_sdk.core.transaction_computer import TransactionComputer from multiversx_sdk.core.transactions_factories import ( TransactionsFactoryConfig, TransferTransactionsFactory) -from multiversx_sdk.core.account import Account - -from multiversx_sdk.core.address import Address - class TransfersController: def __init__(self, chain_id: str) -> None: @@ -17,7 +15,7 @@ def __init__(self, chain_id: str) -> None: self.tx_computer = TransactionComputer() def create_transaction_for_native_token_transfer(self, - sender: Account, + sender: IAccount, nonce: int, receiver: Address, native_transfer_amount: int = 0, @@ -35,7 +33,7 @@ def create_transaction_for_native_token_transfer(self, return transaction def create_transaction_for_esdt_token_transfer(self, - sender: Account, + sender: IAccount, nonce: int, receiver: Address, token_transfers: List[TokenTransfer]) -> Transaction: @@ -51,7 +49,7 @@ def create_transaction_for_esdt_token_transfer(self, return transaction def create_transaction_for_transfer(self, - sender: Account, + sender: IAccount, nonce: int, receiver: Address, native_transfer_amount: Optional[int] = None, diff --git a/multiversx_sdk/core/__init__.py b/multiversx_sdk/core/__init__.py index b3d9141f..d441c7ca 100644 --- a/multiversx_sdk/core/__init__.py +++ b/multiversx_sdk/core/__init__.py @@ -1,4 +1,3 @@ -from multiversx_sdk.core.account import Account from multiversx_sdk.core.address import (Address, AddressComputer, AddressFactory) from multiversx_sdk.core.code_metadata import CodeMetadata @@ -33,7 +32,7 @@ UnFreezeOutcome, UnPauseOutcome, UpdateAttributesOutcome, WipeOutcome) __all__ = [ - "Account", "Address", "AddressFactory", "AddressComputer", + "Address", "AddressFactory", "AddressComputer", "Transaction", "TransactionComputer", "Message", "MessageComputer", "CodeMetadata", "Token", "TokenComputer", "TokenTransfer", "TokenIdentifierParts", diff --git a/multiversx_sdk/facades/entrypoints.py b/multiversx_sdk/facades/entrypoints.py index bb0d152f..882c2a1c 100644 --- a/multiversx_sdk/facades/entrypoints.py +++ b/multiversx_sdk/facades/entrypoints.py @@ -1,5 +1,6 @@ from typing import Any, List, Optional, Protocol, Tuple, Union +from multiversx_sdk.accounts import Account from multiversx_sdk.controllers.account_controller import AccountController from multiversx_sdk.controllers.delegation_controller import \ DelegationController @@ -9,7 +10,6 @@ from multiversx_sdk.controllers.token_management_controller import \ TokenManagementController from multiversx_sdk.controllers.transfers_controller import TransfersController -from multiversx_sdk.core.account import Account from multiversx_sdk.core.address import Address from multiversx_sdk.core.message import Message, MessageComputer from multiversx_sdk.core.transaction import Transaction diff --git a/multiversx_sdk/facades/entrypoints_test.py b/multiversx_sdk/facades/entrypoints_test.py index bb86640f..a8eaad3c 100644 --- a/multiversx_sdk/facades/entrypoints_test.py +++ b/multiversx_sdk/facades/entrypoints_test.py @@ -3,8 +3,8 @@ import pytest from multiversx_sdk.abi.abi import Abi +from multiversx_sdk.accounts import Account from multiversx_sdk.core.address import Address -from multiversx_sdk.core.account import Account from multiversx_sdk.facades.entrypoints import DevnetEntrypoint testutils = Path(__file__).parent.parent / "testutils" diff --git a/multiversx_sdk/network_providers/interface.py b/multiversx_sdk/network_providers/interface.py index 059dc837..6f6daff7 100644 --- a/multiversx_sdk/network_providers/interface.py +++ b/multiversx_sdk/network_providers/interface.py @@ -13,14 +13,6 @@ TransactionCostResponse) -class IAddress(Protocol): - def to_bech32(self) -> str: - ... - - def to_hex(self) -> str: - ... - - class INetworkProvider(Protocol): def get_network_config(self) -> NetworkConfig: ... @@ -99,11 +91,3 @@ def do_get_generic(self, url: str, url_parameters: Optional[dict[str, Any]]) -> def do_post_generic(self, url: str, data: Any, url_parameters: Optional[dict[str, Any]]) -> Any: ... - - -class IPagination(Protocol): - def get_start(self) -> int: - ... - - def get_size(self) -> int: - ... From 2ebe9203688b8cc4a176df789a7dfcca0f6ed789 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Wed, 6 Nov 2024 10:12:12 +0200 Subject: [PATCH 7/7] add internal inteface for tx decoder --- .../network_providers/transaction_decoder.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/multiversx_sdk/network_providers/transaction_decoder.py b/multiversx_sdk/network_providers/transaction_decoder.py index e0561749..d535da60 100644 --- a/multiversx_sdk/network_providers/transaction_decoder.py +++ b/multiversx_sdk/network_providers/transaction_decoder.py @@ -1,15 +1,21 @@ import binascii -from typing import Any, Dict, List, Optional +from typing import Any, Dict, List, Optional, Protocol from multiversx_sdk.core import TokenTransfer from multiversx_sdk.core.address import Address from multiversx_sdk.core.tokens import Token from multiversx_sdk.core.transaction_on_network import TransactionOnNetwork -from multiversx_sdk.network_providers.interface import IAddress DEFAULT_HRP = "erd" +class IAddress(Protocol): + """For internal use only""" + + def to_bech32(self) -> str: + ... + + class TransactionMetadata: def __init__(self) -> None: self.sender: str = ""