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

Added methods to create factories from entrypoint #163

Merged
merged 2 commits into from
Dec 4, 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
32 changes: 32 additions & 0 deletions multiversx_sdk/entrypoints/entrypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,36 @@

from multiversx_sdk.abi.abi import Abi
from multiversx_sdk.account_management import AccountController
from multiversx_sdk.account_management.account_transactions_factory import \
AccountTransactionsFactory
from multiversx_sdk.accounts import Account
from multiversx_sdk.core import (Address, Message, MessageComputer,
Transaction, TransactionComputer,
TransactionOnNetwork)
from multiversx_sdk.core.transactions_factory_config import \
TransactionsFactoryConfig
from multiversx_sdk.delegation import DelegationController
from multiversx_sdk.delegation.delegation_transactions_factory import \
DelegationTransactionsFactory
from multiversx_sdk.entrypoints.config import (DevnetEntrypointConfig,
MainnetEntrypointConfig,
TestnetEntrypointConfig)
from multiversx_sdk.entrypoints.errors import InvalidNetworkProviderKindError
from multiversx_sdk.network_providers import (ApiNetworkProvider,
ProxyNetworkProvider)
from multiversx_sdk.relayed.relayed_controller import RelayedController
from multiversx_sdk.relayed.relayed_transactions_factory import \
RelayedTransactionsFactory
from multiversx_sdk.smart_contracts.smart_contract_controller import \
SmartContractController
from multiversx_sdk.smart_contracts.smart_contract_transactions_factory import \
SmartContractTransactionsFactory
from multiversx_sdk.token_management.token_management_controller import \
TokenManagementController
from multiversx_sdk.token_management.token_management_transactions_factory import \
TokenManagementTransactionsFactory
from multiversx_sdk.transfers.transfer_transactions_factory import \
TransferTransactionsFactory
from multiversx_sdk.transfers.transfers_controller import TransfersController
from multiversx_sdk.wallet.user_verifer import UserVerifier

Expand Down Expand Up @@ -94,21 +108,39 @@ def create_network_provider(self) -> Union[ApiNetworkProvider, ProxyNetworkProvi
def create_delegation_controller(self) -> DelegationController:
return DelegationController(self.chain_id, self.network_provider)

def create_delegation_transactions_factory(self) -> DelegationTransactionsFactory:
return DelegationTransactionsFactory(TransactionsFactoryConfig(self.chain_id))

def create_account_controller(self) -> AccountController:
return AccountController(self.chain_id)

def create_account_transactions_factory(self) -> AccountTransactionsFactory:
return AccountTransactionsFactory(TransactionsFactoryConfig(self.chain_id))

def create_relayed_controller(self) -> RelayedController:
return RelayedController(self.chain_id)

def create_relayed_transactions_factory(self) -> RelayedTransactionsFactory:
return RelayedTransactionsFactory(TransactionsFactoryConfig(self.chain_id))

def create_smart_contract_controller(self, abi: Optional[Abi] = None) -> SmartContractController:
return SmartContractController(self.chain_id, self.network_provider, abi)

def create_smart_contract_transactions_factory(self, abi: Optional[Abi] = None) -> SmartContractTransactionsFactory:
return SmartContractTransactionsFactory(config=TransactionsFactoryConfig(self.chain_id), abi=abi)

def create_token_management_controller(self) -> TokenManagementController:
return TokenManagementController(self.chain_id, self.network_provider)

def create_token_management_transactions_factory(self) -> TokenManagementTransactionsFactory:
return TokenManagementTransactionsFactory(TransactionsFactoryConfig(self.chain_id))

def create_transfers_controller(self) -> TransfersController:
return TransfersController(self.chain_id)

def create_transfers_transactions_factory(self) -> TransferTransactionsFactory:
return TransferTransactionsFactory(TransactionsFactoryConfig(self.chain_id))


class TestnetEntrypoint(NetworkEntrypoint):
def __init__(self, url: Optional[str] = None, kind: Optional[str] = None) -> None:
Expand Down
12 changes: 12 additions & 0 deletions multiversx_sdk/entrypoints/entrypoints_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,15 @@ def test_contract_flow(self):

assert len(query_result) == 1
assert query_result[0] == 7

def test_get_account_factory_and_create_transaction(self):
sender = Account.new_from_pem(self.alice_pem)
sender.nonce = self.entrypoint.recall_account_nonce(sender.address)

factory = self.entrypoint.create_account_transactions_factory()
transaction = factory.create_transaction_for_saving_key_value(
sender=sender.address,
key_value_pairs={"key".encode(): "pair".encode()}
)

assert transaction.chain_id == "D"
Loading