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 16 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
22 changes: 11 additions & 11 deletions examples/Cookbook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1520,7 +1520,7 @@
},
{
"cell_type": "code",
"execution_count": 39,
"execution_count": 48,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -1542,7 +1542,7 @@
},
{
"cell_type": "code",
"execution_count": 40,
"execution_count": 49,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -1559,7 +1559,7 @@
},
{
"cell_type": "code",
"execution_count": 41,
"execution_count": 50,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -1589,7 +1589,7 @@
},
{
"cell_type": "code",
"execution_count": 42,
"execution_count": 51,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -1641,7 +1641,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"['output', 'border', 'position', 'book', 'series', 'crunch', 'matrix', 'seven', 'indicate', 'broom', 'olive', 'echo', 'trap', 'situate', 'exercise', 'inform', 'give', 'liberty', 'kidney', 'twelve', 'husband', 'object', 'unlock', 'spike']\n"
"['rich', 'solution', 'blue', 'ice', 'pass', 'clinic', 'beyond', 'chicken', 'people', 'field', 'release', 'planet', 'arrive', 'tornado', 'trip', 'math', 'circle', 'valley', 'describe', 'second', 'cool', 'range', 'devote', 'case']\n"
]
}
],
Expand Down Expand Up @@ -1697,8 +1697,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Secret key: b87ff17ae7c0a22ee6b0c60af14fc03988b8a42697043fc5c49566ffed0c0f83\n",
"Public key: 8d5e518432f4e158496bf5fb3e7a095d6b734bdece09cbd5f2eadca129e0aa98\n"
"Secret key: 2892696376fef33c5f2c76754e2f701073d524588c7a9cd6681bd6d32bea6650\n",
"Public key: f481465e5a676ddc0d73157470e61703abf779496fbc90dce2e97a382bc2871c\n"
]
}
],
Expand Down Expand Up @@ -2161,8 +2161,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Nonce: 1549\n",
"Balance: 2808163193196014407\n"
"Nonce: 1853\n",
"Balance: 3364970609086014407\n"
]
}
],
Expand Down Expand Up @@ -2226,7 +2226,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Transaction hash: abcc49a04ec5657c5a2eee73ec807407589d9c5153de1ca98b4583df7c73745d\n"
"Transaction hash: 999da2b84011ffd6aedb966c8262804bb5280064a77f543f841e4eae96af8013\n"
]
}
],
Expand Down Expand Up @@ -2266,7 +2266,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Transactions hashes: (3, {'0': 'abcc49a04ec5657c5a2eee73ec807407589d9c5153de1ca98b4583df7c73745d', '1': 'd42827b66e592abcef9ba27eba3817a4b990a57f669c4c800ba2443170b4503f', '2': '492c921667da454d7fdb09bd7a33bed6cfc58bccaa0ac0e0b97d639c428f97aa'})\n"
"Transactions hashes: (3, {'0': '999da2b84011ffd6aedb966c8262804bb5280064a77f543f841e4eae96af8013', '1': '0cf69d20c599334047fb1ec9e392086a5b00a42b688dbd9728d7e979a2555622', '2': 'b2e2c5fbb4fbf9be8ec539af4cb719c5b478067eb6772fa0a47a031ef4150b5b'})\n"
]
}
],
Expand Down
19 changes: 18 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 @@ -39,6 +48,11 @@
TokenManagementTransactionsOutcomeParser
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 +92,8 @@
"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"
]
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"
]
70 changes: 70 additions & 0 deletions multiversx_sdk/controllers/account_controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
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 AccountController:
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:
transaction = self.factory.create_transaction_for_saving_key_value(
sender=sender.address,
key_value_pairs=key_value_pairs
)

transaction.nonce = nonce
transaction.signature = sender.sign(self.tx_computer.compute_bytes_for_signing(transaction))

return transaction

def create_transaction_for_setting_guardian(self,
sender: IAccount,
nonce: int,
guardian_address: IAddress,
service_id: str) -> Transaction:
transaction = self.factory.create_transaction_for_setting_guardian(
sender=sender.address,
guardian_address=guardian_address,
service_id=service_id
)

transaction.nonce = nonce
transaction.signature = sender.sign(self.tx_computer.compute_bytes_for_signing(transaction))

return transaction

def create_transaction_for_guarding_account(self,
sender: IAccount,
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))

return transaction

def create_transaction_for_unguarding_account(self,
sender: IAccount,
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))

return transaction
Loading
Loading