Skip to content

Commit

Permalink
fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
popenta committed Mar 8, 2024
1 parent 618e63d commit bfd94ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 33 deletions.
39 changes: 8 additions & 31 deletions multiversx_sdk/core/adapters/query_runner_adapter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import List, Optional, Protocol, Sequence

from multiversx_sdk.core.address import Address
from multiversx_sdk.core.contract_query import ContractQuery
from multiversx_sdk.core.interfaces import IAddress
from multiversx_sdk.core.smart_contract_query import (
SmartContractQuery, SmartContractQueryResponse)
Expand Down Expand Up @@ -38,48 +39,24 @@ def query_contract(self, query: IQuery) -> IQueryResponse:
...


class ContractQuery(IQuery):
def __init__(self, address: IAddress, function: str, value: int, arguments: List[bytes], caller: Optional[IAddress] = None):
self.contract = address
self.function = function
self.caller = caller
self.value = value
self.encoded_arguments = [item.hex() for item in arguments]

def get_contract(self) -> IAddress:
return self.contract

def get_function(self) -> str:
return self.function

def get_encoded_arguments(self) -> Sequence[str]:
return self.encoded_arguments

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

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


class QueryRunnerAdapter:
def __init__(self, network_provider: INetworkProvider) -> None:
self.network_provider = network_provider

def run_query(self, query: SmartContractQuery) -> SmartContractQueryResponse:
legacy_query = ContractQuery(
address=Address.new_from_bech32(query.contract),
adapted_query = ContractQuery(
contract=Address.new_from_bech32(query.contract),
function=query.function,
value=query.value if query.value else 0,
arguments=query.arguments,
encoded_arguments=[arg.hex() for arg in query.arguments],
caller=Address.new_from_bech32(query.caller) if query.caller else None
)

legacy_query_response = self.network_provider.query_contract(legacy_query)
adapted_query_response = self.network_provider.query_contract(adapted_query)

return SmartContractQueryResponse(
function=query.function,
return_code=legacy_query_response.return_code,
return_message=legacy_query_response.return_message,
return_data_parts=legacy_query_response.get_return_data_parts()
return_code=adapted_query_response.return_code,
return_message=adapted_query_response.return_message,
return_data_parts=adapted_query_response.get_return_data_parts()
)
2 changes: 0 additions & 2 deletions multiversx_sdk/core/contract_query.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


from typing import List, Optional, Sequence

from multiversx_sdk.core.interfaces import IAddress
Expand Down

0 comments on commit bfd94ad

Please sign in to comment.