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

Facade implementation #88

Merged
merged 20 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
34 changes: 33 additions & 1 deletion multiversx_sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
from multiversx_sdk.adapters.query_runner_adapter import QueryRunnerAdapter
from multiversx_sdk.controllers.account_controller import AccountController
from multiversx_sdk.controllers.delegation_controller import \
DelegationController
from multiversx_sdk.controllers.relayed_controller import RelayedController
from multiversx_sdk.controllers.smart_contract_controller import \
SmartContractController
from multiversx_sdk.controllers.token_management_controller import \
TokenManagementController
from multiversx_sdk.controllers.transfers_controller import TransfersController
from multiversx_sdk.converters.transactions_converter import \
TransactionsConverter
from multiversx_sdk.core.account import AccountNonceHolder
Expand Down Expand Up @@ -30,15 +39,30 @@
TransferTransactionsFactory
from multiversx_sdk.core.transactions_outcome_parsers.delegation_transactions_outcome_parser import \
DelegationTransactionsOutcomeParser
from multiversx_sdk.core.transactions_outcome_parsers.delegation_transactions_outcome_parser_types import \
CreateNewDelegationContractOutcome
from multiversx_sdk.core.transactions_outcome_parsers.resources import (
SmartContractResult, TransactionEvent, TransactionLogs, TransactionOutcome,
find_events_by_first_topic, find_events_by_identifier)
from multiversx_sdk.core.transactions_outcome_parsers.smart_contract_transactions_outcome_parser import \
SmartContractTransactionsOutcomeParser
from multiversx_sdk.core.transactions_outcome_parsers.smart_contract_transactions_outcome_parser_types import (
DeployedSmartContract, SmartContractDeployOutcome)
from multiversx_sdk.core.transactions_outcome_parsers.token_management_transactions_outcome_parser import \
TokenManagementTransactionsOutcomeParser
from multiversx_sdk.core.transactions_outcome_parsers.token_management_transactions_outcome_parser_types import (
AddQuantityOutcome, BurnOutcome, BurnQuantityOutcome, FreezeOutcome,
IssueFungibleOutcome, IssueNonFungibleOutcome, IssueSemiFungibleOutcome,
MintOutcome, NFTCreateOutcome, PauseOutcome, RegisterAndSetAllRolesOutcome,
RegisterMetaEsdtOutcome, SetSpecialRoleOutcome, UnFreezeOutcome,
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,
TestnetEntrypoint)
from multiversx_sdk.network_providers.api_network_provider import \
ApiNetworkProvider
from multiversx_sdk.network_providers.errors import GenericError
Expand Down Expand Up @@ -78,5 +102,13 @@
"UserWallet", "UserPEM", "QueryRunnerAdapter", "TransactionsConverter", "DelegationTransactionsOutcomeParser",
"find_events_by_identifier", "find_events_by_first_topic", "SmartContractTransactionsOutcomeParser", "TransactionAwaiter",
"SmartContractQueriesController", "SmartContractQuery", "SmartContractQueryResponse",
"TransactionDecoder", "TransactionMetadata", "TransactionEventsParser"
"TransactionDecoder", "TransactionMetadata", "TransactionEventsParser",
"Account", "DevnetEntrypoint", "MainnetEntrypoint", "NetworkEntrypoint", "TestnetEntrypoint",
"AccountController", "DelegationController", "RelayedController", "SmartContractController",
"TokenManagementController", "TransfersController",
"CreateNewDelegationContractOutcome", "SmartContractDeployOutcome", "DeployedSmartContract",
"IssueFungibleOutcome", "IssueNonFungibleOutcome", "IssueSemiFungibleOutcome", "RegisterMetaEsdtOutcome",
"RegisterAndSetAllRolesOutcome", "SetSpecialRoleOutcome", "NFTCreateOutcome", "MintOutcome", "BurnOutcome",
"PauseOutcome", "UnPauseOutcome", "FreezeOutcome", "UnFreezeOutcome", "WipeOutcome", "UpdateAttributesOutcome",
"AddQuantityOutcome", "BurnQuantityOutcome"
]
2 changes: 0 additions & 2 deletions multiversx_sdk/abi/optional_value_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import re

import pytest

from multiversx_sdk.abi.multi_value import MultiValue
Expand Down
14 changes: 14 additions & 0 deletions multiversx_sdk/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from multiversx_sdk.controllers.account_controller import AccountController
from multiversx_sdk.controllers.delegation_controller import \
DelegationController
from multiversx_sdk.controllers.relayed_controller import RelayedController
from multiversx_sdk.controllers.smart_contract_controller import \
SmartContractController
from multiversx_sdk.controllers.token_management_controller import \
TokenManagementController
from multiversx_sdk.controllers.transfers_controller import TransfersController

__all__ = [
"AccountController", "DelegationController", "RelayedController", "SmartContractController",
"TokenManagementController", "TransfersController"
]
Original file line number Diff line number Diff line change
@@ -1,44 +1,23 @@
from typing import Dict, Protocol, Union
from typing import Dict

from multiversx_sdk.controllers.interfaces import IAccount
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.transactions_factories.account_transactions_factory import \
AccountTransactionsFactory
from multiversx_sdk.core.transactions_factories.transactions_factory_config import \
TransactionsFactoryConfig


class INetworkConfig(Protocol):
chain_id: str


class INetworkProvider(Protocol):
def get_network_config(self) -> INetworkConfig:
...


class IAccount(Protocol):
address: IAddress

def sign(self, data: bytes) -> bytes:
...
from multiversx_sdk.core.transactions_factories import (
AccountTransactionsFactory, TransactionsFactoryConfig)


class AccountController:
def __init__(self, network_provider: INetworkProvider) -> None:
self.chain_id: Union[str, None] = None
self.factory: Union[AccountTransactionsFactory, None] = None
self.provider = network_provider
def __init__(self, chain_id: str) -> None:
self.factory = AccountTransactionsFactory(TransactionsFactoryConfig(chain_id))
self.tx_computer = TransactionComputer()

def create_transaction_for_saving_key_value(self,
sender: IAccount,
nonce: int,
key_value_pairs: Dict[bytes, bytes]) -> Transaction:
self._ensure_factory_is_initialized()

transaction = self.factory.create_transaction_for_saving_key_value( # type: ignore
transaction = self.factory.create_transaction_for_saving_key_value(
sender=sender.address,
key_value_pairs=key_value_pairs
)
Expand All @@ -53,9 +32,7 @@ def create_transaction_for_setting_guardian(self,
nonce: int,
guardian_address: IAddress,
service_id: str) -> Transaction:
self._ensure_factory_is_initialized()

transaction = self.factory.create_transaction_for_setting_guardian( # type: ignore
transaction = self.factory.create_transaction_for_setting_guardian(
sender=sender.address,
guardian_address=guardian_address,
service_id=service_id
Expand All @@ -69,9 +46,7 @@ def create_transaction_for_setting_guardian(self,
def create_transaction_for_guarding_account(self,
sender: IAccount,
nonce: int) -> Transaction:
self._ensure_factory_is_initialized()

transaction = self.factory.create_transaction_for_guarding_account( # type: ignore
transaction = self.factory.create_transaction_for_guarding_account(
sender=sender.address
)

Expand All @@ -83,19 +58,11 @@ def create_transaction_for_guarding_account(self,
def create_transaction_for_unguarding_account(self,
sender: IAccount,
nonce: int) -> Transaction:
self._ensure_factory_is_initialized()

transaction = self.factory.create_transaction_for_unguarding_account( # type: ignore
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))

return transaction

def _ensure_factory_is_initialized(self):
if self.factory is None:
self.chain_id = self.provider.get_network_config().chain_id
config = TransactionsFactoryConfig(self.chain_id)
self.factory = AccountTransactionsFactory(config)
Loading
Loading