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

Reference newer sdk & add client name #456

Merged
merged 2 commits into from
Nov 1, 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
4 changes: 3 additions & 1 deletion multiversx_sdk_cli/cli_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from multiversx_sdk import Address, ProxyNetworkProvider

from multiversx_sdk_cli import cli_shared, utils
from multiversx_sdk_cli.config import get_config_for_network_providers

logger = logging.getLogger("cli.accounts")

Expand Down Expand Up @@ -33,7 +34,8 @@ def _add_address_arg(sub: Any):
def get_account(args: Any):
proxy_url = args.proxy
address = args.address
proxy = ProxyNetworkProvider(proxy_url)
config = get_config_for_network_providers()
proxy = ProxyNetworkProvider(url=proxy_url, config=config)
account = proxy.get_account(Address.new_from_bech32(address))

if args.balance:
Expand Down
16 changes: 6 additions & 10 deletions multiversx_sdk_cli/cli_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from multiversx_sdk_cli import cli_shared, projects, utils
from multiversx_sdk_cli.cli_output import CLIOutputBuilder
from multiversx_sdk_cli.config import get_config_for_network_providers
from multiversx_sdk_cli.constants import NUMBER_OF_SHARDS
from multiversx_sdk_cli.contract_verification import \
trigger_contract_verification
Expand Down Expand Up @@ -100,7 +101,7 @@ def setup_parser(args: List[str], subparsers: Any) -> Any:
cli_shared.add_tx_args(args, sub, with_receiver=False, with_data=False)
_add_function_arg(sub)
_add_arguments_arg(sub)
_add_token_transfers_args(sub)
cli_shared.add_token_transfers_args(sub)
sub.add_argument("--wait-result", action="store_true", default=False,
help="signal to wait for the transaction result - only valid if --send is set")
sub.add_argument("--timeout", default=100, help="max num of seconds to wait for result"
Expand Down Expand Up @@ -243,12 +244,6 @@ def _add_arguments_arg(sub: Any):
"E.g. [{ 'to': 'erd1...', 'amount': 10000000000 }]")


def _add_token_transfers_args(sub: Any):
sub.add_argument("--token-transfers", nargs='+',
help="token transfers for transfer & execute, as [token, amount] "
"E.g. --token-transfers NFT-123456-0a 1 ESDT-987654 100000000")


def _add_metadata_arg(sub: Any):
sub.add_argument("--metadata-not-upgradeable", dest="metadata_upgradeable", action="store_false",
help="‼ mark the contract as NOT upgradeable (default: upgradeable)")
Expand Down Expand Up @@ -448,14 +443,15 @@ def query(args: Any):
args.chain = ""
cli_shared.prepare_chain_id_in_args(args)

config = TransactionsFactoryConfig(args.chain)
factory_config = TransactionsFactoryConfig(args.chain)
abi = Abi.load(Path(args.abi)) if args.abi else None
contract = SmartContract(config, abi)
contract = SmartContract(factory_config, abi)

arguments, should_prepare_args = _get_contract_arguments(args)
contract_address = Address.new_from_bech32(args.contract)

proxy = ProxyNetworkProvider(args.proxy)
network_provider_config = get_config_for_network_providers()
proxy = ProxyNetworkProvider(url=args.proxy, config=network_provider_config)
function = args.function

result = contract.query_contract(
Expand Down
4 changes: 3 additions & 1 deletion multiversx_sdk_cli/cli_delegation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from multiversx_sdk import ProxyNetworkProvider, TransactionsFactoryConfig

from multiversx_sdk_cli import cli_shared, errors, utils
from multiversx_sdk_cli.config import get_config_for_network_providers
from multiversx_sdk_cli.delegation import DelegationOperations


Expand Down Expand Up @@ -209,7 +210,8 @@ def do_create_delegation_contract(args: Any):
def get_contract_address_by_deploy_tx_hash(args: Any):
args = utils.as_object(args)

proxy = ProxyNetworkProvider(args.proxy)
config = get_config_for_network_providers()
proxy = ProxyNetworkProvider(url=args.proxy, config=config)
Copy link
Contributor

Choose a reason for hiding this comment

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

In a future PR, we can have a shared function such as create_network_provider(url: str), to hold both these lines etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, was thinking the same.


transaction = proxy.get_transaction(args.create_tx_hash)
transaction_events = transaction.logs.events
Expand Down
15 changes: 11 additions & 4 deletions multiversx_sdk_cli/cli_dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from prettytable import PrettyTable

from multiversx_sdk_cli import cli_shared
from multiversx_sdk_cli.config import get_config_for_network_providers
from multiversx_sdk_cli.constants import ADDRESS_ZERO_BECH32
from multiversx_sdk_cli.dns import (compute_dns_address_for_shard_id,
dns_address_for_name, name_hash, register,
Expand Down Expand Up @@ -79,14 +80,17 @@ def _ensure_proxy_is_provided(args: Any):
def dns_resolve(args: Any):
_ensure_proxy_is_provided(args)

addr = resolve(args.name, ProxyNetworkProvider(args.proxy))
config = get_config_for_network_providers()
addr = resolve(args.name, ProxyNetworkProvider(url=args.proxy, config=config))
if addr.to_hex() != Address.new_from_bech32(ADDRESS_ZERO_BECH32).to_hex():
print(addr.to_bech32())


def dns_validate_name(args: Any):
_ensure_proxy_is_provided(args)
validate_name(args.name, args.shard_id, ProxyNetworkProvider(args.proxy))

config = get_config_for_network_providers()
validate_name(args.name, args.shard_id, ProxyNetworkProvider(url=args.proxy, config=config))


def get_name_hash(args: Any):
Expand All @@ -107,13 +111,16 @@ def get_dns_address_for_name_hex(args: Any):

def get_registration_cost(args: Any):
_ensure_proxy_is_provided(args)
print(registration_cost(args.shard_id, ProxyNetworkProvider(args.proxy)))

config = get_config_for_network_providers()
print(registration_cost(args.shard_id, ProxyNetworkProvider(url=args.proxy, config=config)))


def get_version(args: Any):
_ensure_proxy_is_provided(args)

proxy = ProxyNetworkProvider(args.proxy)
config = get_config_for_network_providers()
proxy = ProxyNetworkProvider(url=args.proxy, config=config)
if args.all:
t = PrettyTable(['Shard ID', 'Contract address (bech32)', 'Contract address (hex)', 'Version'])
for shard_id in range(0, 256):
Expand Down
19 changes: 14 additions & 5 deletions multiversx_sdk_cli/cli_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
load_password)
from multiversx_sdk_cli.constants import (DEFAULT_TX_VERSION,
TRANSACTION_OPTIONS_TX_GUARDED)
from multiversx_sdk_cli.custom_network_provider import CustomNetworkProvider
from multiversx_sdk_cli.errors import ArgumentsNotProvidedError
from multiversx_sdk_cli.interfaces import ITransaction
from multiversx_sdk_cli.ledger.ledger_functions import do_get_ledger_address
Expand Down Expand Up @@ -141,6 +140,12 @@ def add_omit_fields_arg(sub: Any):
sub.add_argument("--omit-fields", default="[]", type=str, required=False, help="omit fields in the output payload (default: %(default)s)")


def add_token_transfers_args(sub: Any):
sub.add_argument("--token-transfers", nargs='+',
help="token transfers for transfer & execute, as [token, amount] "
"E.g. --token-transfers NFT-123456-0a 1 ESDT-987654 100000000")


def parse_omit_fields_arg(args: Any) -> List[str]:
literal = args.omit_fields
parsed = ast.literal_eval(literal)
Expand Down Expand Up @@ -182,7 +187,8 @@ def prepare_nonce_in_args(args: Any):

if args.recall_nonce:
account = prepare_account(args)
account.sync_nonce(ProxyNetworkProvider(args.proxy))
network_provider_config = config.get_config_for_network_providers()
account.sync_nonce(ProxyNetworkProvider(url=args.proxy, config=network_provider_config))
args.nonce = account.nonce


Expand All @@ -191,7 +197,8 @@ def prepare_chain_id_in_args(args: Any):
raise ArgumentsNotProvidedError("chain ID cannot be decided: `--chain` or `--proxy` should be provided")

if args.chain and args.proxy:
proxy = ProxyNetworkProvider(args.proxy)
network_provider_config = config.get_config_for_network_providers()
proxy = ProxyNetworkProvider(url=args.proxy, config=network_provider_config)
fetched_chain_id = proxy.get_network_config().chain_id

if args.chain != fetched_chain_id:
Expand All @@ -204,7 +211,8 @@ def prepare_chain_id_in_args(args: Any):
if args.chain:
return
elif args.proxy:
proxy = ProxyNetworkProvider(args.proxy)
network_provider_config = config.get_config_for_network_providers()
proxy = ProxyNetworkProvider(url=args.proxy, config=network_provider_config)
args.chain = proxy.get_network_config().chain_id


Expand Down Expand Up @@ -253,7 +261,8 @@ def check_options_for_guarded_tx(options: int):


def send_or_simulate(tx: ITransaction, args: Any, dump_output: bool = True) -> CLIOutputBuilder:
proxy = CustomNetworkProvider(args.proxy)
network_provider_config = config.get_config_for_network_providers()
proxy = ProxyNetworkProvider(url=args.proxy, config=network_provider_config)

is_set_wait_result = hasattr(args, "wait_result") and args.wait_result
is_set_send = hasattr(args, "send") and args.send
Expand Down
20 changes: 10 additions & 10 deletions multiversx_sdk_cli/cli_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
from pathlib import Path
from typing import Any, List

from multiversx_sdk import ProxyNetworkProvider

from multiversx_sdk_cli import cli_shared, utils
from multiversx_sdk_cli.cli_output import CLIOutputBuilder
from multiversx_sdk_cli.config import get_config_for_network_providers
from multiversx_sdk_cli.cosign_transaction import cosign_transaction
from multiversx_sdk_cli.custom_network_provider import CustomNetworkProvider
from multiversx_sdk_cli.errors import NoWalletProvided
from multiversx_sdk_cli.transactions import (compute_relayed_v1_data,
do_prepare_transaction,
Expand All @@ -20,7 +22,7 @@ def setup_parser(args: List[str], subparsers: Any) -> Any:

sub = cli_shared.add_command_subparser(subparsers, "tx", "new", f"Create a new transaction.{CLIOutputBuilder.describe()}")
_add_common_arguments(args, sub)
_add_token_transfers_args(sub)
cli_shared.add_token_transfers_args(sub)
cli_shared.add_outfile_arg(sub, what="signed transaction, hash")
cli_shared.add_broadcast_args(sub, relay=True)
cli_shared.add_proxy_arg(sub)
Expand Down Expand Up @@ -65,12 +67,6 @@ def _add_common_arguments(args: List[str], sub: Any):
sub.add_argument("--data-file", type=str, default=None, help="a file containing transaction data")


def _add_token_transfers_args(sub: Any):
sub.add_argument("--token-transfers", nargs='+',
help="token transfers for transfer & execute, as [token, amount] "
"E.g. --token-transfers NFT-123456-0a 1 ESDT-987654 100000000")


def create_transaction(args: Any):
args = utils.as_object(args)

Expand All @@ -97,7 +93,9 @@ def send_transaction(args: Any):

tx = load_transaction_from_file(args.infile)
output = CLIOutputBuilder()
proxy = CustomNetworkProvider(args.proxy)

config = get_config_for_network_providers()
proxy = ProxyNetworkProvider(url=args.proxy, config=config)

try:
tx_hash = proxy.send_transaction(tx)
Expand All @@ -110,7 +108,9 @@ def send_transaction(args: Any):
def get_transaction(args: Any):
args = utils.as_object(args)
omit_fields = cli_shared.parse_omit_fields_arg(args)
proxy = CustomNetworkProvider(args.proxy)

config = get_config_for_network_providers()
proxy = ProxyNetworkProvider(url=args.proxy, config=config)

transaction = proxy.get_transaction(args.hash, True)
output = CLIOutputBuilder().set_transaction_on_network(transaction, omit_fields).build()
Expand Down
6 changes: 6 additions & 0 deletions multiversx_sdk_cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from pathlib import Path
from typing import Any, Dict, List

from multiversx_sdk import NetworkProviderConfig

from multiversx_sdk_cli import errors, utils

SDK_PATH = Path("~/multiversx-sdk").expanduser().resolve()
Expand Down Expand Up @@ -242,3 +244,7 @@ def get_dependency_directory(key: str, tag: str) -> Path:

def get_dependency_parent_directory(key: str) -> Path:
return SDK_PATH / key


def get_config_for_network_providers() -> NetworkProviderConfig:
return NetworkProviderConfig(client_name="mxpy")
36 changes: 0 additions & 36 deletions multiversx_sdk_cli/custom_network_provider.py

This file was deleted.

7 changes: 1 addition & 6 deletions multiversx_sdk_cli/interfaces.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, Protocol, Sequence
from typing import Any, Dict, Protocol


class IAddress(Protocol):
Expand All @@ -25,11 +25,6 @@ class ITransaction(Protocol):
guardian: str
signature: bytes
guardian_signature: bytes
relayer: str

@property
def inner_transactions(self) -> Sequence["ITransaction"]:
...


class IAccount(Protocol):
Expand Down
17 changes: 17 additions & 0 deletions multiversx_sdk_cli/tests/test_cli_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,22 @@ def test_create_multi_transfer_transaction(capsys: Any):
assert signature == "575b029d52ff5ffbfb7bab2f04052de88a6f7d022a6ad368459b8af9acaed3717d3f95db09f460649a8f405800838bc2c432496bd03c9039ea166bd32b84660e"


def test_create_multi_transfer_transaction_with_single_egld_transfer(capsys: Any):
return_code = main([
"tx", "new",
"--pem", str(testdata_path / "alice.pem"),
"--receiver", "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx",
"--nonce", "7",
"--gas-limit", "1300000",
"--token-transfers", "EGLD-000000", "1000000000000000000",
"--chain", "T",
])
assert return_code == 0
tx = _read_stdout(capsys)
tx_json = json.loads(tx)
data = tx_json["emittedTransactionData"]
assert data == "MultiESDTNFTTransfer@8049d639e5a6980d1cd2392abcce41029cda74a1563523a202f09641cc2618f8@01@45474c442d303030303030@@0de0b6b3a7640000"


def _read_stdout(capsys: Any) -> str:
return capsys.readouterr().out.strip()
4 changes: 3 additions & 1 deletion multiversx_sdk_cli/tests/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from multiversx_sdk_cli.accounts import Account
from multiversx_sdk_cli.cli import main
from multiversx_sdk_cli.config import get_config_for_network_providers


def test_get_account():
Expand All @@ -20,7 +21,8 @@ def test_get_account():

def test_sync_nonce():
account = Account(address=Address.new_from_bech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"))
proxy = ProxyNetworkProvider("https://testnet-api.multiversx.com")
config = get_config_for_network_providers()
proxy = ProxyNetworkProvider("https://testnet-api.multiversx.com", config=config)
account.sync_nonce(proxy)
assert True if account.nonce else False

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "multiversx-sdk-cli"
version = "9.8.0"
version = "9.8.1"
authors = [
{ name="MultiversX" },
]
Expand All @@ -28,7 +28,7 @@ dependencies = [
"requests-cache",
"rich==13.3.4",
"argcomplete==3.2.2",
"multiversx-sdk==0.13.0"
"multiversx-sdk==0.16.3"
]

[project.scripts]
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ requests-cache
rich==13.3.4
argcomplete==3.2.2

multiversx-sdk==0.13.0
multiversx-sdk==0.16.3
Loading