Skip to content
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
172 changes: 104 additions & 68 deletions CLI.md

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions multiversx_sdk_cli/args_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ def validate_transaction_args(args: Any):


def validate_nonce_args(args: Any):
"""If nonce is not provided, ensure that recall_nonce is provided. If recall_nonce is provided, ensure that proxy is provided."""
"""If nonce is not provided, ensure that proxy is provided."""
if hasattr(args, "nonce") and args.nonce is None:
if not args.recall_nonce:
raise InvalidArgumentsError("Either --nonce or --recall-nonce must be provided")

if hasattr(args, "proxy") and not args.proxy:
raise InvalidArgumentsError("--proxy must be provided if --recall-nonce is used")
raise InvalidArgumentsError("--proxy must be provided if --nonce is not provided")


def validate_receiver_args(args: Any):
Expand Down
3 changes: 3 additions & 0 deletions multiversx_sdk_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def _do_main(cli_args: list[str]):
default_hrp = config.get_address_hrp()
LibraryConfig.default_address_hrp = default_hrp

if hasattr(args, "recall_nonce") and args.recall_nonce:
logger.warning("The --recall-nonce flag is DEPRECATED. The nonce is fetched from the network by default.")

if not hasattr(args, "func"):
parser.print_help()
else:
Expand Down
22 changes: 20 additions & 2 deletions multiversx_sdk_cli/cli_faucet.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from multiversx_sdk import Message, NativeAuthClient, NativeAuthClientConfig

from multiversx_sdk_cli import cli_shared
from multiversx_sdk_cli.errors import BadUserInput
from multiversx_sdk_cli.errors import ArgumentsNotProvidedError, BadUserInput

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

Expand All @@ -27,7 +27,9 @@ def setup_parser(args: list[str], subparsers: Any) -> Any:

sub = cli_shared.add_command_subparser(subparsers, "faucet", "request", "Request xEGLD.")
cli_shared.add_wallet_args(args, sub)
sub.add_argument("--chain", required=True, choices=["D", "T"], help="the chain identifier")
sub.add_argument("--chain", choices=["D", "T"], help="the chain identifier")
sub.add_argument("--api", type=str, help="custom api url for the native auth client")
sub.add_argument("--wallet-url", type=str, help="custom wallet url to call the faucet from")
sub.set_defaults(func=faucet)

parser.epilog = cli_shared.build_group_epilog(subparsers)
Expand Down Expand Up @@ -59,10 +61,26 @@ def call_web_wallet_faucet(wallet_url: str, access_token: str):
def get_wallet_and_api_urls(args: Any) -> tuple[str, str]:
chain: str = args.chain

if not chain:
return get_custom_wallet_and_api_urls(args)

if chain.upper() == "D":
return WebWalletUrls.DEVNET.value, ApiUrls.DEVNET.value

if chain.upper() == "T":
return WebWalletUrls.TESTNET.value, ApiUrls.TESTNET.value

raise BadUserInput("Invalid chain id. Choose between 'D' for devnet and 'T' for testnet.")


def get_custom_wallet_and_api_urls(args: Any) -> tuple[str, str]:
wallet = args.wallet_url
api = args.api

if not wallet:
raise ArgumentsNotProvidedError("--wallet-url not provided")

if not api:
raise ArgumentsNotProvidedError("--api not provided")

return wallet, api
49 changes: 44 additions & 5 deletions multiversx_sdk_cli/cli_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from multiversx_sdk import (
Account,
Address,
ApiNetworkProvider,
LedgerAccount,
ProxyNetworkProvider,
Transaction,
Expand Down Expand Up @@ -103,13 +104,13 @@ def add_tx_args(
type=int,
required=False,
default=None,
help="# the nonce for the transaction",
help="# the nonce for the transaction. If not provided, is fetched from the network.",
)
sub.add_argument(
"--recall-nonce",
action="store_true",
default=False,
help="⭮ whether to recall the nonce when creating the transaction (default: %(default)s)",
help="⭮ whether to recall the nonce when creating the transaction (default: %(default)s). This argument is OBSOLETE.",
)

if with_receiver:
Expand Down Expand Up @@ -175,6 +176,9 @@ def add_wallet_args(args: list[str], sub: Any):
help="🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: %(default)s)",
)
sub.add_argument("--sender-username", required=False, help="🖄 the username of the sender")
sub.add_argument(
"--hrp", required=False, type=str, help="The hrp used to convert the address to its bech32 representation"
)


def add_guardian_wallet_args(args: list[str], sub: Any):
Expand Down Expand Up @@ -282,7 +286,7 @@ def parse_omit_fields_arg(args: Any) -> list[str]:


def prepare_account(args: Any):
hrp = config.get_address_hrp()
hrp = _get_address_hrp(args)

if args.pem:
return Account.new_from_pem(file_path=Path(args.pem), index=args.sender_wallet_index, hrp=hrp)
Expand All @@ -302,8 +306,43 @@ def prepare_account(args: Any):
raise errors.NoWalletProvided()


def _get_address_hrp(args: Any) -> str:
"""Use hrp provided by the user. If not provided, fetch from network. If proxy not provided, get hrp from config."""
hrp: str = ""

if hasattr(args, "hrp") and args.hrp:
hrp = args.hrp
return hrp

if hasattr(args, "proxy") and args.proxy:
hrp = _get_hrp_from_proxy(args)
elif hasattr(args, "api") and args.api:
hrp = _get_hrp_from_api(args)

if hrp:
return hrp

return config.get_address_hrp()


def _get_hrp_from_proxy(args: Any) -> str:
network_provider_config = config.get_config_for_network_providers()
proxy = ProxyNetworkProvider(url=args.proxy, config=network_provider_config)
network_config = proxy.get_network_config()
hrp: str = network_config.raw.get("erd_address_hrp", "")
return hrp


def _get_hrp_from_api(args: Any) -> str:
network_provider_config = config.get_config_for_network_providers()
proxy = ApiNetworkProvider(url=args.api, config=network_provider_config)
network_config = proxy.get_network_config()
hrp: str = network_config.raw.get("erd_address_hrp", "")
return hrp


def load_guardian_account(args: Any) -> Union[IAccount, None]:
hrp = config.get_address_hrp()
hrp = _get_address_hrp(args)

if args.guardian_pem:
return Account.new_from_pem(file_path=Path(args.guardian_pem), index=args.guardian_wallet_index, hrp=hrp)
Expand Down Expand Up @@ -434,7 +473,7 @@ def _is_matching_address(account_address: Union[Address, None], args_address: Un


def load_relayer_account(args: Any) -> Union[IAccount, None]:
hrp = config.get_address_hrp()
hrp = _get_address_hrp(args)

if args.relayer_pem:
return Account.new_from_pem(file_path=Path(args.relayer_pem), index=args.relayer_wallet_index, hrp=hrp)
Expand Down
2 changes: 1 addition & 1 deletion multiversx_sdk_cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def get_value(name: str) -> str:
return value


def get_address_hrp():
def get_address_hrp() -> str:
return get_value("default_address_hrp")


Expand Down
36 changes: 0 additions & 36 deletions multiversx_sdk_cli/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,31 +62,11 @@ def __init__(self, directory: str):
super().__init__(f"Bad directory: {directory}")


class BadFile(KnownError):
def __init__(self, filename: str, inner: Any = None):
super().__init__(f"Bad file: {filename}.", inner)


class NotSupportedProject(KnownError):
def __init__(self, directory: str):
super().__init__(f"Directory is not a supported project: {directory}")


class PlatformNotSupported(KnownError):
def __init__(self, action_or_item: str, platform: str):
super().__init__(f"[{action_or_item}] is not supported on platform [{platform}].")


class BuildError(KnownError):
def __init__(self, message: str):
super().__init__(f"Build error: {message}.")


class UnknownArgumentFormat(KnownError):
def __init__(self, argument: Any):
super().__init__(f"Cannot handle non-hex, non-number arguments yet: {argument}.")


class BadInputError(KnownError):
def __init__(self, input: str, message: str):
super().__init__(f"Bad input [{input}]: {message}")
Expand Down Expand Up @@ -126,11 +106,6 @@ def __init__(self, message: str):
super().__init__(f"Bad usage: {message}.")


class CannotReadValidatorsData(KnownError):
def __init__(self):
super(CannotReadValidatorsData, self).__init__("cannot read validators data")


class TransactionIsNotSigned(KnownError):
def __init__(self):
super().__init__("Transaction is not signed.")
Expand All @@ -141,11 +116,6 @@ def __init__(self):
super().__init__("No wallet provided.")


class LedgerError(KnownError):
def __init__(self, message: str):
super().__init__("Ledger error: " + message)


class DockerMissingError(KnownError):
def __init__(self):
super().__init__("Docker is not installed! Please visit https://docs.docker.com/get-docker/ to install docker.")
Expand All @@ -161,12 +131,6 @@ def __init__(self, message: str):
super().__init__(message)


class ProxyError(KnownError):
def __init__(self, message: str, url: str, data: str, code: str):
inner = {"url": url, "data": data, "code": code}
super().__init__(message, inner)


class WalletGenerationError(KnownError):
def __init__(self, message: str):
super().__init__(message)
Expand Down
9 changes: 0 additions & 9 deletions multiversx_sdk_cli/tests/test_cli_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def test_contract_deploy():
"https://testnet-api.multiversx.com",
"--chain",
"T",
"--recall-nonce",
"--gas-limit",
"5000000",
"--arguments",
Expand Down Expand Up @@ -57,7 +56,6 @@ def test_contract_upgrade():
"https://testnet-api.multiversx.com",
"--chain",
"T",
"--recall-nonce",
"--gas-limit",
"5000000",
"--arguments",
Expand Down Expand Up @@ -86,7 +84,6 @@ def test_contract_call():
"https://testnet-api.multiversx.com",
"--chain",
"T",
"--recall-nonce",
"--gas-limit",
"5000000",
"--arguments",
Expand Down Expand Up @@ -177,7 +174,6 @@ def test_contract_flow(capsys: Any):
adder,
"--pem",
alice,
"--recall-nonce",
"--gas-limit",
"5000000",
"--proxy",
Expand Down Expand Up @@ -220,7 +216,6 @@ def test_contract_flow(capsys: Any):
alice,
"--function",
"add",
"--recall-nonce",
"--gas-limit",
"5000000",
"--proxy",
Expand Down Expand Up @@ -262,7 +257,6 @@ def test_contract_flow(capsys: Any):
adder,
"--pem",
alice,
"--recall-nonce",
"--gas-limit",
"5000000",
"--proxy",
Expand All @@ -287,7 +281,6 @@ def test_contract_deploy_without_required_arguments():
adder,
"--pem",
alice,
"--recall-nonce",
"--gas-limit",
"5000000",
"--arguments",
Expand Down Expand Up @@ -490,7 +483,6 @@ def test_contract_query(capsys: Any):
adder_abi,
"--pem",
alice,
"--recall-nonce",
"--gas-limit",
"5000000",
"--proxy",
Expand All @@ -516,7 +508,6 @@ def test_contract_query(capsys: Any):
alice,
"--function",
"add",
"--recall-nonce",
"--gas-limit",
"5000000",
"--proxy",
Expand Down
Loading
Loading