Skip to content

Commit af10ef5

Browse files
authored
Merge pull request #512 from multiversx/feat/next
v10.1.0: Merge feat/next into main
2 parents 7a28de3 + 995d0ee commit af10ef5

10 files changed

Lines changed: 175 additions & 138 deletions

File tree

CLI.md

Lines changed: 104 additions & 68 deletions
Large diffs are not rendered by default.

multiversx_sdk_cli/args_validation.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ def validate_transaction_args(args: Any):
1010

1111

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

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

2119

2220
def validate_receiver_args(args: Any):

multiversx_sdk_cli/cli.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ def _do_main(cli_args: list[str]):
6666
default_hrp = config.get_address_hrp()
6767
LibraryConfig.default_address_hrp = default_hrp
6868

69+
if hasattr(args, "recall_nonce") and args.recall_nonce:
70+
logger.warning("The --recall-nonce flag is DEPRECATED. The nonce is fetched from the network by default.")
71+
6972
if not hasattr(args, "func"):
7073
parser.print_help()
7174
else:

multiversx_sdk_cli/cli_faucet.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from multiversx_sdk import Message, NativeAuthClient, NativeAuthClientConfig
77

88
from multiversx_sdk_cli import cli_shared
9-
from multiversx_sdk_cli.errors import BadUserInput
9+
from multiversx_sdk_cli.errors import ArgumentsNotProvidedError, BadUserInput
1010

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

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

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

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

64+
if not chain:
65+
return get_custom_wallet_and_api_urls(args)
66+
6267
if chain.upper() == "D":
6368
return WebWalletUrls.DEVNET.value, ApiUrls.DEVNET.value
6469

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

6873
raise BadUserInput("Invalid chain id. Choose between 'D' for devnet and 'T' for testnet.")
74+
75+
76+
def get_custom_wallet_and_api_urls(args: Any) -> tuple[str, str]:
77+
wallet = args.wallet_url
78+
api = args.api
79+
80+
if not wallet:
81+
raise ArgumentsNotProvidedError("--wallet-url not provided")
82+
83+
if not api:
84+
raise ArgumentsNotProvidedError("--api not provided")
85+
86+
return wallet, api

multiversx_sdk_cli/cli_shared.py

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from multiversx_sdk import (
99
Account,
1010
Address,
11+
ApiNetworkProvider,
1112
LedgerAccount,
1213
ProxyNetworkProvider,
1314
Transaction,
@@ -103,13 +104,13 @@ def add_tx_args(
103104
type=int,
104105
required=False,
105106
default=None,
106-
help="# the nonce for the transaction",
107+
help="# the nonce for the transaction. If not provided, is fetched from the network.",
107108
)
108109
sub.add_argument(
109110
"--recall-nonce",
110111
action="store_true",
111112
default=False,
112-
help="⭮ whether to recall the nonce when creating the transaction (default: %(default)s)",
113+
help="⭮ whether to recall the nonce when creating the transaction (default: %(default)s). This argument is OBSOLETE.",
113114
)
114115

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

179183

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

283287

284288
def prepare_account(args: Any):
285-
hrp = config.get_address_hrp()
289+
hrp = _get_address_hrp(args)
286290

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

304308

309+
def _get_address_hrp(args: Any) -> str:
310+
"""Use hrp provided by the user. If not provided, fetch from network. If proxy not provided, get hrp from config."""
311+
hrp: str = ""
312+
313+
if hasattr(args, "hrp") and args.hrp:
314+
hrp = args.hrp
315+
return hrp
316+
317+
if hasattr(args, "proxy") and args.proxy:
318+
hrp = _get_hrp_from_proxy(args)
319+
elif hasattr(args, "api") and args.api:
320+
hrp = _get_hrp_from_api(args)
321+
322+
if hrp:
323+
return hrp
324+
325+
return config.get_address_hrp()
326+
327+
328+
def _get_hrp_from_proxy(args: Any) -> str:
329+
network_provider_config = config.get_config_for_network_providers()
330+
proxy = ProxyNetworkProvider(url=args.proxy, config=network_provider_config)
331+
network_config = proxy.get_network_config()
332+
hrp: str = network_config.raw.get("erd_address_hrp", "")
333+
return hrp
334+
335+
336+
def _get_hrp_from_api(args: Any) -> str:
337+
network_provider_config = config.get_config_for_network_providers()
338+
proxy = ApiNetworkProvider(url=args.api, config=network_provider_config)
339+
network_config = proxy.get_network_config()
340+
hrp: str = network_config.raw.get("erd_address_hrp", "")
341+
return hrp
342+
343+
305344
def load_guardian_account(args: Any) -> Union[IAccount, None]:
306-
hrp = config.get_address_hrp()
345+
hrp = _get_address_hrp(args)
307346

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

435474

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

439478
if args.relayer_pem:
440479
return Account.new_from_pem(file_path=Path(args.relayer_pem), index=args.relayer_wallet_index, hrp=hrp)

multiversx_sdk_cli/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def get_value(name: str) -> str:
5757
return value
5858

5959

60-
def get_address_hrp():
60+
def get_address_hrp() -> str:
6161
return get_value("default_address_hrp")
6262

6363

multiversx_sdk_cli/errors.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -62,31 +62,11 @@ def __init__(self, directory: str):
6262
super().__init__(f"Bad directory: {directory}")
6363

6464

65-
class BadFile(KnownError):
66-
def __init__(self, filename: str, inner: Any = None):
67-
super().__init__(f"Bad file: {filename}.", inner)
68-
69-
70-
class NotSupportedProject(KnownError):
71-
def __init__(self, directory: str):
72-
super().__init__(f"Directory is not a supported project: {directory}")
73-
74-
7565
class PlatformNotSupported(KnownError):
7666
def __init__(self, action_or_item: str, platform: str):
7767
super().__init__(f"[{action_or_item}] is not supported on platform [{platform}].")
7868

7969

80-
class BuildError(KnownError):
81-
def __init__(self, message: str):
82-
super().__init__(f"Build error: {message}.")
83-
84-
85-
class UnknownArgumentFormat(KnownError):
86-
def __init__(self, argument: Any):
87-
super().__init__(f"Cannot handle non-hex, non-number arguments yet: {argument}.")
88-
89-
9070
class BadInputError(KnownError):
9171
def __init__(self, input: str, message: str):
9272
super().__init__(f"Bad input [{input}]: {message}")
@@ -126,11 +106,6 @@ def __init__(self, message: str):
126106
super().__init__(f"Bad usage: {message}.")
127107

128108

129-
class CannotReadValidatorsData(KnownError):
130-
def __init__(self):
131-
super(CannotReadValidatorsData, self).__init__("cannot read validators data")
132-
133-
134109
class TransactionIsNotSigned(KnownError):
135110
def __init__(self):
136111
super().__init__("Transaction is not signed.")
@@ -141,11 +116,6 @@ def __init__(self):
141116
super().__init__("No wallet provided.")
142117

143118

144-
class LedgerError(KnownError):
145-
def __init__(self, message: str):
146-
super().__init__("Ledger error: " + message)
147-
148-
149119
class DockerMissingError(KnownError):
150120
def __init__(self):
151121
super().__init__("Docker is not installed! Please visit https://docs.docker.com/get-docker/ to install docker.")
@@ -161,12 +131,6 @@ def __init__(self, message: str):
161131
super().__init__(message)
162132

163133

164-
class ProxyError(KnownError):
165-
def __init__(self, message: str, url: str, data: str, code: str):
166-
inner = {"url": url, "data": data, "code": code}
167-
super().__init__(message, inner)
168-
169-
170134
class WalletGenerationError(KnownError):
171135
def __init__(self, message: str):
172136
super().__init__(message)

multiversx_sdk_cli/tests/test_cli_contracts.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def test_contract_deploy():
2828
"https://testnet-api.multiversx.com",
2929
"--chain",
3030
"T",
31-
"--recall-nonce",
3231
"--gas-limit",
3332
"5000000",
3433
"--arguments",
@@ -57,7 +56,6 @@ def test_contract_upgrade():
5756
"https://testnet-api.multiversx.com",
5857
"--chain",
5958
"T",
60-
"--recall-nonce",
6159
"--gas-limit",
6260
"5000000",
6361
"--arguments",
@@ -86,7 +84,6 @@ def test_contract_call():
8684
"https://testnet-api.multiversx.com",
8785
"--chain",
8886
"T",
89-
"--recall-nonce",
9087
"--gas-limit",
9188
"5000000",
9289
"--arguments",
@@ -177,7 +174,6 @@ def test_contract_flow(capsys: Any):
177174
adder,
178175
"--pem",
179176
alice,
180-
"--recall-nonce",
181177
"--gas-limit",
182178
"5000000",
183179
"--proxy",
@@ -220,7 +216,6 @@ def test_contract_flow(capsys: Any):
220216
alice,
221217
"--function",
222218
"add",
223-
"--recall-nonce",
224219
"--gas-limit",
225220
"5000000",
226221
"--proxy",
@@ -262,7 +257,6 @@ def test_contract_flow(capsys: Any):
262257
adder,
263258
"--pem",
264259
alice,
265-
"--recall-nonce",
266260
"--gas-limit",
267261
"5000000",
268262
"--proxy",
@@ -287,7 +281,6 @@ def test_contract_deploy_without_required_arguments():
287281
adder,
288282
"--pem",
289283
alice,
290-
"--recall-nonce",
291284
"--gas-limit",
292285
"5000000",
293286
"--arguments",
@@ -490,7 +483,6 @@ def test_contract_query(capsys: Any):
490483
adder_abi,
491484
"--pem",
492485
alice,
493-
"--recall-nonce",
494486
"--gas-limit",
495487
"5000000",
496488
"--proxy",
@@ -516,7 +508,6 @@ def test_contract_query(capsys: Any):
516508
alice,
517509
"--function",
518510
"add",
519-
"--recall-nonce",
520511
"--gas-limit",
521512
"5000000",
522513
"--proxy",

0 commit comments

Comments
 (0)