Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change sender and receiver type #140

Merged
merged 8 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions multiversx_sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 AccountNonceHolder
from multiversx_sdk.core.address import (Address, AddressComputer,
AddressFactory)
from multiversx_sdk.core.code_metadata import CodeMetadata
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions multiversx_sdk/accounts/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from multiversx_sdk.accounts.account import Account

__all__ = ["Account"]
File renamed without changes.
18 changes: 18 additions & 0 deletions multiversx_sdk/accounts/account_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

from pathlib import Path

from multiversx_sdk.accounts.account import Account

alice = Path(__file__).parent.parent / "testutils" / "testwallets" / "alice.pem"


def test_account_nonce_holder():
account = Account.new_from_pem(alice)
account.nonce = 42
assert account.get_nonce_then_increment() == 42
assert account.get_nonce_then_increment() == 43

account.get_nonce_then_increment()
account.get_nonce_then_increment()
account.get_nonce_then_increment()
assert account.nonce == 47
13 changes: 8 additions & 5 deletions multiversx_sdk/controllers/account_controller.py
Original file line number Diff line number Diff line change
@@ -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.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 (
Expand All @@ -10,7 +10,8 @@

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,
Expand All @@ -30,7 +31,7 @@ def create_transaction_for_saving_key_value(self,
def create_transaction_for_setting_guardian(self,
sender: IAccount,
nonce: int,
guardian_address: IAddress,
guardian_address: Address,
service_id: str) -> Transaction:
transaction = self.factory.create_transaction_for_setting_guardian(
sender=sender.address,
Expand All @@ -51,7 +52,8 @@ def create_transaction_for_guarding_account(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

Expand All @@ -63,6 +65,7 @@ def create_transaction_for_unguarding_account(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
39 changes: 20 additions & 19 deletions multiversx_sdk/controllers/delegation_controller.py
Original file line number Diff line number Diff line change
@@ -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.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
Expand Down Expand Up @@ -48,7 +49,7 @@ def await_completed_create_new_delegation_contract(
def create_transaction_for_adding_nodes(self,
sender: IAccount,
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(
Expand All @@ -66,7 +67,7 @@ def create_transaction_for_adding_nodes(self,
def create_transaction_for_removing_nodes(self,
sender: IAccount,
nonce: int,
delegation_contract: IAddress,
delegation_contract: Address,
public_keys: Sequence[IValidatorPublicKey]) -> Transaction:
transaction = self.factory.create_transaction_for_removing_nodes(
sender=sender.address,
Expand All @@ -82,7 +83,7 @@ def create_transaction_for_removing_nodes(self,
def create_transaction_for_staking_nodes(self,
sender: IAccount,
nonce: int,
delegation_contract: IAddress,
delegation_contract: Address,
public_keys: Sequence[IValidatorPublicKey]) -> Transaction:
transaction = self.factory.create_transaction_for_staking_nodes(
sender=sender.address,
Expand All @@ -98,7 +99,7 @@ def create_transaction_for_staking_nodes(self,
def create_transaction_for_unbonding_nodes(self,
sender: IAccount,
nonce: int,
delegation_contract: IAddress,
delegation_contract: Address,
public_keys: Sequence[IValidatorPublicKey]) -> Transaction:
transaction = self.factory.create_transaction_for_unbonding_nodes(
sender=sender.address,
Expand All @@ -114,7 +115,7 @@ def create_transaction_for_unbonding_nodes(self,
def create_transaction_for_unstaking_nodes(self,
sender: IAccount,
nonce: int,
delegation_contract: IAddress,
delegation_contract: Address,
public_keys: Sequence[IValidatorPublicKey]) -> Transaction:
transaction = self.factory.create_transaction_for_unstaking_nodes(
sender=sender.address,
Expand All @@ -130,7 +131,7 @@ def create_transaction_for_unstaking_nodes(self,
def create_transaction_for_unjailing_nodes(self,
sender: IAccount,
nonce: int,
delegation_contract: IAddress,
delegation_contract: Address,
public_keys: Sequence[IValidatorPublicKey],
amount: int) -> Transaction:
transaction = self.factory.create_transaction_for_unjailing_nodes(
Expand All @@ -148,7 +149,7 @@ def create_transaction_for_unjailing_nodes(self,
def create_transaction_for_changing_service_fee(self,
sender: IAccount,
nonce: int,
delegation_contract: IAddress,
delegation_contract: Address,
service_fee: int) -> Transaction:
transaction = self.factory.create_transaction_for_changing_service_fee(
sender=sender.address,
Expand All @@ -164,7 +165,7 @@ def create_transaction_for_changing_service_fee(self,
def create_transaction_for_modifying_delegation_cap(self,
sender: IAccount,
nonce: int,
delegation_contract: IAddress,
delegation_contract: Address,
delegation_cap: int) -> Transaction:
transaction = self.factory.create_transaction_for_modifying_delegation_cap(
sender=sender.address,
Expand All @@ -180,7 +181,7 @@ def create_transaction_for_modifying_delegation_cap(self,
def create_transaction_for_setting_automatic_activation(self,
sender: IAccount,
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
Expand All @@ -194,7 +195,7 @@ def create_transaction_for_setting_automatic_activation(self,
def create_transaction_for_unsetting_automatic_activation(self,
sender: IAccount,
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
Expand All @@ -208,7 +209,7 @@ def create_transaction_for_unsetting_automatic_activation(self,
def create_transaction_for_setting_cap_check_on_redelegate_rewards(self,
sender: IAccount,
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
Expand All @@ -222,7 +223,7 @@ def create_transaction_for_setting_cap_check_on_redelegate_rewards(self,
def create_transaction_for_unsetting_cap_check_on_redelegate_rewards(self,
sender: IAccount,
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
Expand All @@ -236,7 +237,7 @@ def create_transaction_for_unsetting_cap_check_on_redelegate_rewards(self,
def create_transaction_for_setting_metadata(self,
sender: IAccount,
nonce: int,
delegation_contract: IAddress,
delegation_contract: Address,
name: str,
website: str,
identifier: str) -> Transaction:
Expand All @@ -256,7 +257,7 @@ def create_transaction_for_setting_metadata(self,
def create_transaction_for_delegating(self,
sender: IAccount,
nonce: int,
delegation_contract: IAddress,
delegation_contract: Address,
amount: int) -> Transaction:
transaction = self.factory.create_transaction_for_delegating(
sender=sender.address,
Expand All @@ -272,7 +273,7 @@ def create_transaction_for_delegating(self,
def create_transaction_for_claiming_rewards(self,
sender: IAccount,
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
Expand All @@ -286,7 +287,7 @@ def create_transaction_for_claiming_rewards(self,
def create_transaction_for_redelegating_rewards(self,
sender: IAccount,
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
Expand All @@ -300,7 +301,7 @@ def create_transaction_for_redelegating_rewards(self,
def create_transaction_for_undelegating(self,
sender: IAccount,
nonce: int,
delegation_contract: IAddress,
delegation_contract: Address,
amount: int) -> Transaction:
transaction = self.factory.create_transaction_for_undelegating(
sender=sender.address,
Expand All @@ -316,7 +317,7 @@ def create_transaction_for_undelegating(self,
def create_transaction_for_withdrawing(self,
sender: IAccount,
nonce: int,
delegation_contract: IAddress) -> Transaction:
delegation_contract: Address) -> Transaction:
transaction = self.factory.create_transaction_for_withdrawing(
sender=sender.address,
delegation_contract=delegation_contract
Expand Down
4 changes: 2 additions & 2 deletions multiversx_sdk/controllers/interfaces.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, List, Optional, Protocol, Union

from multiversx_sdk.core.interfaces import IAddress
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
Expand All @@ -9,7 +9,7 @@

class IAccount(Protocol):
@property
def address(self) -> IAddress:
def address(self) -> Address:
...

def sign(self, data: bytes) -> bytes:
Expand Down
5 changes: 2 additions & 3 deletions multiversx_sdk/controllers/relayed_controller.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
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 (
Expand All @@ -16,7 +15,7 @@ def __init__(self, chain_id: str) -> None:
def create_relayed_v1_transaction(self,
sender: IAccount,
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
Expand All @@ -30,7 +29,7 @@ def create_relayed_v1_transaction(self,
def create_relayed_v2_transaction(self,
sender: IAccount,
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,
Expand Down
Loading
Loading