Skip to content

Commit

Permalink
fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
popenta committed Sep 9, 2024
1 parent 0501acf commit 8e0771f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 25 deletions.
14 changes: 8 additions & 6 deletions multiversx_sdk/controllers/delegation_controller.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, List, Sequence
from typing import List, Protocol, Sequence

from multiversx_sdk.controllers.interfaces import IAccount
from multiversx_sdk.controllers.network_provider_wrapper import ProviderWrapper
Expand All @@ -16,9 +16,13 @@
from multiversx_sdk.network_providers.transactions import TransactionOnNetwork


class INetworkProvider(Protocol):
...


class DelegationController:
def __init__(self, chain_id: str, network_provider: Any) -> None:
self.provider = network_provider
def __init__(self, chain_id: str, network_provider: INetworkProvider) -> None:
self.transaction_awaiter = TransactionAwaiter(ProviderWrapper(network_provider))
self.factory = DelegationTransactionsFactory(TransactionsFactoryConfig(chain_id))
self.parser = DelegationTransactionsOutcomeParser()
self.tx_computer = TransactionComputer()
Expand Down Expand Up @@ -49,9 +53,7 @@ def parse_create_new_delegation_contract(self,
return self.parser.parse_create_new_delegation_contract(tx_outcome)

def await_completed_create_new_delegation_contract(self, tx_hash: str) -> List[CreateNewDelegationContractOutcome]:
provider = ProviderWrapper(self.provider)
transaction_awaiter = TransactionAwaiter(provider)
transaction = transaction_awaiter.await_completed(tx_hash)
transaction = self.transaction_awaiter.await_completed(tx_hash)
return self.parse_create_new_delegation_contract(transaction)

def create_transaction_for_adding_nodes(self,
Expand Down
8 changes: 3 additions & 5 deletions multiversx_sdk/controllers/smart_contract_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ def decode_endpoint_output_parameters(self, endpoint_name: str, encoded_values:

class SmartContractController:
def __init__(self, chain_id: str, network_provider: INetworkProvider, abi: Optional[IAbi] = None) -> None:
self.provider = network_provider
self.abi = abi
self.factory = SmartContractTransactionsFactory(TransactionsFactoryConfig(chain_id))
self.parser = SmartContractTransactionsOutcomeParser()
self.query_controller = SmartContractQueriesController(
query_runner=QueryRunnerAdapter(self.provider),
query_runner=QueryRunnerAdapter(network_provider),
abi=self.abi
)
self.transaction_awaiter = TransactionAwaiter(ProviderWrapper(network_provider))
self.tx_computer = TransactionComputer()

def create_transaction_for_deploy(self,
Expand Down Expand Up @@ -114,9 +114,7 @@ def parse_deploy(self, transaction_on_network: TransactionOnNetwork) -> SmartCon
return self.parser.parse_deploy(tx_outcome)

def await_completed_deploy(self, tx_hash: str) -> SmartContractDeployOutcome:
provider = ProviderWrapper(self.provider)
transaction_awaiter = TransactionAwaiter(provider)
transaction = transaction_awaiter.await_completed(tx_hash)
transaction = self.transaction_awaiter.await_completed(tx_hash)
return self.parse_deploy(transaction)

def create_transaction_for_upgrade(self,
Expand Down
3 changes: 1 addition & 2 deletions multiversx_sdk/controllers/token_management_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ class INetworkProvider(Protocol):
class TokenManagementController:
def __init__(self, chain_id: str, network_provider: INetworkProvider) -> None:
self.factory = TokenManagementTransactionsFactory(TransactionsFactoryConfig(chain_id))
self.provider_wrapper = ProviderWrapper(network_provider)
self.transaction_awaiter = TransactionAwaiter(self.provider_wrapper)
self.transaction_awaiter = TransactionAwaiter(ProviderWrapper(network_provider))
self.tx_computer = TransactionComputer()
self.tx_converter = TransactionsConverter()
self.parser = TokenManagementTransactionsOutcomeParser()
Expand Down
6 changes: 3 additions & 3 deletions multiversx_sdk/facades/entrypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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.facades.account import Account
from multiversx_sdk.facades.config import (DevnetEntrypointConfig,
MainnetEntrypointConfig,
TestnetEntrypointConfig)
Expand All @@ -24,7 +25,6 @@
from multiversx_sdk.network_providers.transaction_awaiter import \
TransactionAwaiter
from multiversx_sdk.network_providers.transactions import TransactionOnNetwork
from multiversx_sdk.wallet.user_signer import UserSigner
from multiversx_sdk.wallet.user_verifer import UserVerifier


Expand Down Expand Up @@ -56,7 +56,7 @@ def __init__(self,

self.chain_id = chain_id

def sign_transaction(self, transaction: Transaction, account: UserSigner):
def sign_transaction(self, transaction: Transaction, account: Account):
"""Signs the transactions and applies the signature on the transaction."""
tx_computer = TransactionComputer()
transaction.signature = account.sign(tx_computer.compute_bytes_for_signing(transaction))
Expand All @@ -70,7 +70,7 @@ def verify_transaction_signature(self, transaction: Transaction) -> bool:
signature=transaction.signature
)

def sign_message(self, message: Message, account: UserSigner):
def sign_message(self, message: Message, account: Account):
"""Signs the message and applies the signature on the message."""
message_computer = MessageComputer()
message.signature = account.sign(message_computer.compute_bytes_for_signing(message))
Expand Down
11 changes: 2 additions & 9 deletions multiversx_sdk/facades/entrypoints_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,8 @@ def test_contract_flow(self):
)

tx_hash = self.entrypoint.send_transaction(transaction)

retries = 10
while retries:
time.sleep(0.5)
try:
self.entrypoint.await_completed_transaction(tx_hash)
break
except:
retries -= 1
time.sleep(1)
self.entrypoint.await_completed_transaction(tx_hash)

query_result = controller.query_contract(
contract=contract_address,
Expand Down

0 comments on commit 8e0771f

Please sign in to comment.