Skip to content

Commit

Permalink
fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
popenta committed Nov 27, 2023
1 parent 8064660 commit 5cfe31a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
9 changes: 4 additions & 5 deletions multiversx_sdk_cli/cli_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from pathlib import Path
from typing import Any, List

from multiversx_sdk_core import (Address, AddressComputer, TokenComputer,
Transaction)
from multiversx_sdk_core import Address, AddressComputer, Transaction
from multiversx_sdk_core.transaction_factories import TransactionsFactoryConfig
from multiversx_sdk_network_providers.proxy_network_provider import \
ProxyNetworkProvider
Expand Down Expand Up @@ -307,7 +306,7 @@ def deploy(args: Any):
cli_shared.prepare_chain_id_in_args(args)

config = TransactionsFactoryConfig(args.chain)
contract = SmartContract(config, TokenComputer())
contract = SmartContract(config)

address_computer = AddressComputer(NUMBER_OF_SHARDS)
contract_address = address_computer.compute_contract_address(deployer=sender.address, deployment_nonce=sender.nonce)
Expand Down Expand Up @@ -381,7 +380,7 @@ def call(args: Any):
sender = _prepare_sender(args)

config = TransactionsFactoryConfig(args.chain)
contract = SmartContract(config, TokenComputer())
contract = SmartContract(config)
contract_address = Address.new_from_bech32(args.contract)

tx = contract.get_execute_transaction(sender, args)
Expand All @@ -399,7 +398,7 @@ def upgrade(args: Any):
sender = _prepare_sender(args)

config = TransactionsFactoryConfig(args.chain)
contract = SmartContract(config, TokenComputer())
contract = SmartContract(config)
contract_address = Address.new_from_bech32(args.contract)

tx = contract.get_upgrade_transaction(sender, args)
Expand Down
25 changes: 7 additions & 18 deletions multiversx_sdk_cli/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pathlib import Path
from typing import Any, List, Optional, Protocol, Sequence

from multiversx_sdk_core import Transaction, TransactionPayload
from multiversx_sdk_core import TokenComputer, Transaction, TransactionPayload
from multiversx_sdk_core.address import Address
from multiversx_sdk_core.transaction_factories import \
SmartContractTransactionsFactory
Expand Down Expand Up @@ -70,22 +70,9 @@ class IConfig(Protocol):
gas_limit_per_byte: int


class IToken(Protocol):
identifier: str
nonce: int


class ITokenComputer(Protocol):
def is_fungible(self, token: IToken) -> bool:
...

def extract_identifier_from_extended_identifier(self, identifier: str) -> str:
...


class SmartContract:
def __init__(self, config: IConfig, token_computer: ITokenComputer):
self._factory = SmartContractTransactionsFactory(config, token_computer)
def __init__(self, config: IConfig):
self._factory = SmartContractTransactionsFactory(config, TokenComputer())

def get_deploy_transaction(self, owner: Account, args: Any) -> Transaction:
arguments = args.arguments or []
Expand Down Expand Up @@ -175,9 +162,10 @@ def query_detailed(contract_address: IAddress, proxy: INetworkProvider, function
value: int = 0, caller: Optional[IAddress] = 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]
arguments_hex = [_prepare_argument(arg) for arg in arguments]
prepared_arguments_bytes = [bytes.fromhex(arg) for arg in arguments_hex]

query = ContractQuery(contract_address, function, value, prepared_arguments, caller)
query = ContractQuery(contract_address, function, value, prepared_arguments_bytes, caller)

response = proxy.query_contract(query)
# Temporary workaround, until we add "isSuccess" on the response class.
Expand Down Expand Up @@ -252,6 +240,7 @@ def hex_to_bytes(arg: str):
return bytes.fromhex(argument)


# only used for contract queries and stake operations
def _prepare_argument(argument: Any):
as_str = str(argument)
as_hex = _to_hex(as_str)
Expand Down

0 comments on commit 5cfe31a

Please sign in to comment.