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

Moved SC Query Controller to SC Controller #149

Merged
merged 2 commits into from
Nov 15, 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
2 changes: 0 additions & 2 deletions multiversx_sdk/abi/abi_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,6 @@ def __init__(self, name: str) -> None:

@classmethod
def from_dict(cls, data: Dict[str, Any]) -> "ExplicitEnumVariantDefinition":
fields = [FieldDefinition.from_dict(item) for item in data.get("fields", [])]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀


return cls(
name=data.get("name", "")
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Dict, List, Protocol
from typing import Dict, Protocol

from multiversx_sdk.builders.transaction_builder import TransactionBuilder
from multiversx_sdk.core.address import Address
from multiversx_sdk.core.transaction import Transaction
from multiversx_sdk.builders.transaction_builder import TransactionBuilder


class IConfig(Protocol):
Expand Down Expand Up @@ -86,8 +86,8 @@ def create_transaction_for_unguarding_account(self, sender: Address) -> Transact

return transaction

def _compute_data_parts_for_saving_key_value(self, key_value_pairs: Dict[bytes, bytes]) -> List[str]:
data_parts: List[str] = []
def _compute_data_parts_for_saving_key_value(self, key_value_pairs: Dict[bytes, bytes]) -> list[str]:
data_parts: list[str] = []

for key, value in key_value_pairs.items():
data_parts.extend([key.hex(), value.hex()])
Expand Down
21 changes: 0 additions & 21 deletions multiversx_sdk/core/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ def __init__(self, address: Any) -> None:
super().__init__(f"Bad address: {address}")


class ListsLengthMismatchError(Exception):
def __init__(self, message: str) -> None:
super().__init__(message)


class NotEnoughGasError(Exception):
def __init__(self, gas_limit: int) -> None:
super().__init__(f"Not enough gas provided: {gas_limit}")
Expand All @@ -31,22 +26,6 @@ def __init__(self, message: str) -> None:
super().__init__(message)


class InvalidInnerTransactionError(Exception):
def __init__(self, message: str) -> None:
super().__init__(message)


class ParseTransactionOnNetworkError(Exception):
def __init__(self, message: str) -> None:
super().__init__(message)


class SmartContractQueryError(Exception):
def __init__(self, return_code: str, message: str) -> None:
super().__init__(message)
self.return_code = return_code


class ArgumentSerializationError(Exception):
def __init__(self, message: str = "Unable to encode arguments: unsupported format or missing ABI file") -> None:
super().__init__(message)
9 changes: 2 additions & 7 deletions multiversx_sdk/core/transaction_events_parser.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
from types import SimpleNamespace
from typing import Protocol

from multiversx_sdk.abi.abi import Abi
from multiversx_sdk.core.transaction_on_network import TransactionEvent


class IAbi(Protocol):
def decode_event(self, event_name: str, topics: list[bytes], additional_data: list[bytes]) -> SimpleNamespace:
...


class TransactionEventsParser:
def __init__(self, abi: IAbi, first_topic_as_identifier: bool = True) -> None:
def __init__(self, abi: Abi, first_topic_as_identifier: bool = True) -> None:
self.abi = abi
# By default, we consider that the first topic is the event identifier.
# This is true for log entries emitted by smart contracts:
Expand Down
4 changes: 2 additions & 2 deletions multiversx_sdk/delegation/delegation_transactions_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from multiversx_sdk.abi import Serializer
from multiversx_sdk.abi.biguint_value import BigUIntValue
from multiversx_sdk.abi.string_value import StringValue
from multiversx_sdk.builders.transaction_builder import TransactionBuilder
from multiversx_sdk.core import Address, Transaction
from multiversx_sdk.core.constants import DELEGATION_MANAGER_SC_ADDRESS
from multiversx_sdk.core.errors import ListsLengthMismatchError
from multiversx_sdk.core.interfaces import IValidatorPublicKey
from multiversx_sdk.builders.transaction_builder import TransactionBuilder
from multiversx_sdk.delegation.errors import ListsLengthMismatchError


class IConfig(Protocol):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import List

from multiversx_sdk.core import (Address, TransactionEvent,
TransactionOnNetwork,
find_events_by_identifier)
Expand All @@ -14,13 +12,13 @@ def __init__(self) -> None:
pass

def parse_create_new_delegation_contract(self,
transaction: TransactionOnNetwork) -> List[CreateNewDelegationContractOutcome]:
transaction: TransactionOnNetwork) -> list[CreateNewDelegationContractOutcome]:
self._ensure_no_error(transaction.logs.events)

events = find_events_by_identifier(transaction, "SCDeploy")
return [CreateNewDelegationContractOutcome(self._extract_contract_address(event)) for event in events]

def _ensure_no_error(self, transaction_events: List[TransactionEvent]) -> None:
def _ensure_no_error(self, transaction_events: list[TransactionEvent]) -> None:
for event in transaction_events:
if event.identifier == "signalError":
data = event.additional_data[0].decode()[1:] if len(event.additional_data[0]) else ""
Expand Down
3 changes: 3 additions & 0 deletions multiversx_sdk/delegation/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ListsLengthMismatchError(Exception):
def __init__(self, message: str) -> None:
super().__init__(message)
23 changes: 5 additions & 18 deletions multiversx_sdk/entrypoints/entrypoints.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Any, Optional, Protocol, Tuple, Union
from typing import Optional, Union

from multiversx_sdk.abi.abi import Abi
from multiversx_sdk.account_management import AccountController
from multiversx_sdk.accounts import Account
from multiversx_sdk.core import (Address, Message, MessageComputer,
Expand All @@ -21,20 +22,6 @@
from multiversx_sdk.wallet.user_verifer import UserVerifier


class IAbi(Protocol):
def encode_endpoint_input_parameters(self, endpoint_name: str, values: list[Any]) -> list[bytes]:
...

def encode_constructor_input_parameters(self, values: list[Any]) -> list[bytes]:
...

def encode_upgrade_constructor_input_parameters(self, values: list[Any]) -> list[bytes]:
...

def decode_endpoint_output_parameters(self, endpoint_name: str, encoded_values: list[bytes]) -> list[Any]:
...


class NetworkEntrypoint:
def __init__(self,
network_provider_url: str,
Expand Down Expand Up @@ -83,15 +70,15 @@ def verify_message_signature(self, message: Message) -> bool:
def recall_account_nonce(self, address: Address) -> int:
return self.network_provider.get_account(address).nonce

def send_transactions(self, transactions: list[Transaction]) -> Tuple[int, list[bytes]]:
def send_transactions(self, transactions: list[Transaction]) -> tuple[int, list[bytes]]:
"""
Sends multiple transactions.

Args:
transactions (list[Transaction]): An iterable containing multiple transactions (e.g. a list of transactions).

Returns:
Tuple (int, list[bytes]): The integer indicates the total number of transactions sent, while the list contains the transactions hashes. If a transaction is not sent, the hash is empty.
tuple (int, list[bytes]): The integer indicates the total number of transactions sent, while the list contains the transactions hashes. If a transaction is not sent, the hash is empty.
"""
return self.network_provider.send_transactions(transactions)

Expand All @@ -113,7 +100,7 @@ def create_account_controller(self) -> AccountController:
def create_relayed_controller(self) -> RelayedController:
return RelayedController(self.chain_id)

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

def create_token_management_controller(self) -> TokenManagementController:
Expand Down
2 changes: 1 addition & 1 deletion multiversx_sdk/entrypoints/entrypoints_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_contract_flow(self):
tx_hash = self.entrypoint.send_transaction(transaction)
self.entrypoint.await_completed_transaction(tx_hash)

query_result = controller.query_contract(
query_result = controller.query(
contract=contract_address,
function="getSum",
arguments=[]
Expand Down
5 changes: 0 additions & 5 deletions multiversx_sdk/entrypoints/errors.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
class BadUsageError(Exception):
def __init__(self, message: str) -> None:
super().__init__(message)


class InvalidNetworkProviderKindError(Exception):
def __init__(self) -> None:
super().__init__("Invalid network provider kind. Choose between `api` and `proxy`.")
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def test_get_sc_invoking_tx(self):

def test_query_contract(self):
query = SmartContractQuery(
contract="erd1qqqqqqqqqqqqqpgqqy34h7he2ya6qcagqre7ur7cc65vt0mxrc8qnudkr4",
contract=Address.new_from_bech32("erd1qqqqqqqqqqqqqpgqqy34h7he2ya6qcagqre7ur7cc65vt0mxrc8qnudkr4"),
function="getSum",
arguments=[],
)
Expand Down
4 changes: 2 additions & 2 deletions multiversx_sdk/network_providers/http_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@

def smart_contract_query_to_vm_query_request(query: SmartContractQuery) -> dict[str, Any]:
request: dict[str, Any] = {
"scAddress": query.contract,
"scAddress": query.contract.to_bech32(),
"funcName": query.function,
"value": str(query.value if query.value else 0),
"args": [arg.hex() for arg in query.arguments]
}

if query.caller:
request["caller"] = query.caller
request["caller"] = query.caller.to_bech32()

return request

Expand Down
4 changes: 2 additions & 2 deletions multiversx_sdk/network_providers/proxy_network_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def get_definition_of_fungible_token(self, token_identifier: str) -> FungibleTok
"""Fetches the definition of a fungible token."""
encoded_identifier = token_identifier.encode()
query = SmartContractQuery(
contract=ESDT_CONTRACT_ADDRESS,
contract=Address.new_from_bech32(ESDT_CONTRACT_ADDRESS),
function="getTokenProperties",
arguments=[encoded_identifier],
)
Expand All @@ -261,7 +261,7 @@ def get_definition_of_tokens_collection(self, collection_name: str) -> TokensCol
"""Fetches the definition of a tokens collection."""
encoded_identifier = collection_name.encode()
query = SmartContractQuery(
contract=ESDT_CONTRACT_ADDRESS,
contract=Address.new_from_bech32(ESDT_CONTRACT_ADDRESS),
function="getTokenProperties",
arguments=[encoded_identifier],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def test_get_transaction_status(self):

def test_query_contract(self):
query = SmartContractQuery(
contract="erd1qqqqqqqqqqqqqpgqqy34h7he2ya6qcagqre7ur7cc65vt0mxrc8qnudkr4",
contract=Address.new_from_bech32("erd1qqqqqqqqqqqqqpgqqy34h7he2ya6qcagqre7ur7cc65vt0mxrc8qnudkr4"),
function="getSum",
arguments=[]
)
Expand Down
3 changes: 3 additions & 0 deletions multiversx_sdk/relayed/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class InvalidInnerTransactionError(Exception):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, errors in their own feature folder 👍

def __init__(self, message: str) -> None:
super().__init__(message)
2 changes: 1 addition & 1 deletion multiversx_sdk/relayed/relayed_transactions_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from multiversx_sdk.abi import AddressValue, BigUIntValue, Serializer
from multiversx_sdk.abi.bytes_value import BytesValue
from multiversx_sdk.core import Address, Transaction
from multiversx_sdk.core.errors import InvalidInnerTransactionError
from multiversx_sdk.relayed.errors import InvalidInnerTransactionError


class IConfig(Protocol):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import pytest

from multiversx_sdk.core import Address, Transaction, TransactionComputer
from multiversx_sdk.core.errors import InvalidInnerTransactionError
from multiversx_sdk.core.transactions_factory_config import \
TransactionsFactoryConfig
from multiversx_sdk.relayed.errors import InvalidInnerTransactionError
from multiversx_sdk.relayed.relayed_transactions_factory import \
RelayedTransactionsFactory
from multiversx_sdk.testutils.wallets import load_wallets
Expand Down
10 changes: 10 additions & 0 deletions multiversx_sdk/smart_contracts/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

class SmartContractQueryError(Exception):
def __init__(self, return_code: str, message: str) -> None:
super().__init__(message)
self.return_code = return_code


class ArgumentSerializationError(Exception):
def __init__(self, message: str = "Unable to encode arguments: unsupported format or missing ABI file") -> None:
super().__init__(message)
Loading
Loading