Skip to content

Commit

Permalink
Merge pull request #199 from multiversx/fix-queries
Browse files Browse the repository at this point in the history
Fix contract query (parameter preparation and error reporting)
  • Loading branch information
andreibancioiu authored Jan 20, 2023
2 parents 7342e62 + bc3fcf2 commit f9d223b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion multiversx_sdk_cli/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "5.1.0"
__version__ = "5.1.1"
19 changes: 15 additions & 4 deletions multiversx_sdk_cli/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


class INetworkProvider(Protocol):
def query_contract(self, query: Any) -> Any:
def query_contract(self, query: Any) -> 'IContractQueryResponse':
...


Expand Down Expand Up @@ -50,11 +50,17 @@ def get_encoded_arguments(self) -> Sequence[str]:

def get_caller(self) -> Optional[Address]:
return self.caller

def get_value(self) -> int:
return self.value


class IContractQueryResponse(Protocol):
return_data: List[str]
return_code: str
return_message: str


class SmartContract:
def __init__(self, address: Optional[Address] = None, bytecode=None, metadata=None):
self.address = Address(address)
Expand Down Expand Up @@ -176,12 +182,17 @@ def query(
return [self._interpret_return_data(data) for data in return_data]

def query_detailed(self, proxy: INetworkProvider, function: str, arguments: List[Any],
value: int = 0, caller: Optional[Address] = None) -> Any:
value: int = 0, caller: Optional[Address] = None) -> Any:
arguments = arguments or []
# Temporary workaround, until we use sdk-core's serializer.
prepared_arguments = [bytes.fromhex(_prepare_argument(arg)) for arg in arguments]

query = ContractQuery(self.address, function, value, arguments, caller)
query = ContractQuery(self.address, function, value, prepared_arguments, caller)

response = proxy.query_contract(query)
# Temporary workaround, until we add "isSuccess" on the response class.
if response.return_code != "ok":
raise RuntimeError(f"Query failed: {response.return_message}")
return response

def _interpret_return_data(self, data: str) -> Any:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import setuptools

VERSION = "5.1.0"
VERSION = "5.1.1"

try:
with open('./multiversx_sdk_cli/_version.py', 'wt') as versionfile:
Expand Down

0 comments on commit f9d223b

Please sign in to comment.