-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathargs_validation.py
More file actions
69 lines (44 loc) · 2.27 KB
/
args_validation.py
File metadata and controls
69 lines (44 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from typing import Any
from multiversx_sdk_cli.errors import InvalidArgumentsError
def validate_transaction_args(args: Any):
validate_nonce_args(args)
validate_receiver_args(args)
validate_gas_limit_args(args)
def validate_nonce_args(args: Any):
"""If nonce is not provided, ensure that proxy is provided."""
if hasattr(args, "nonce") and args.nonce is None:
if hasattr(args, "proxy") and not args.proxy:
raise InvalidArgumentsError("--proxy must be provided if --nonce is not provided")
def validate_receiver_args(args: Any):
"""Ensure that receiver is provided."""
if hasattr(args, "receiver") and not args.receiver:
raise InvalidArgumentsError("--receiver must be provided")
def validate_gas_limit_args(args: Any):
"""Ensure that gas_limit is provided."""
if hasattr(args, "gas_limit") and not args.gas_limit:
raise InvalidArgumentsError("--gas-limit must be provided")
def ensure_wallet_args_are_provided(args: Any):
signing_methods = [args.pem, args.keyfile, args.ledger]
if all(signing_methods):
raise InvalidArgumentsError("Only one of --pem, --keyfile, or --ledger must be provided")
if not any(signing_methods):
raise InvalidArgumentsError("One of --pem, --keyfile, or --ledger must be provided")
def ensure_relayer_wallet_args_are_provided(args: Any):
signing_methods = [args.relayer_pem, args.relayer_keyfile, args.relayer_ledger]
if all(signing_methods):
raise InvalidArgumentsError(
"Only one of --relayer-pem, --relayer-keyfile, or --relayer-ledger must be provided"
)
if not any(signing_methods):
raise InvalidArgumentsError("One of --relayer-pem, --relayer-keyfile, or --relayer-ledger must be provided")
def validate_broadcast_args(args: Any):
if args.send and args.simulate:
raise InvalidArgumentsError("Cannot both 'simulate' and 'send' a transaction")
if args.send or args.simulate:
validate_proxy_argument(args)
def validate_chain_id_args(args: Any):
if not args.chain and not args.proxy:
raise InvalidArgumentsError("Either --chain or --proxy must be provided")
def validate_proxy_argument(args: Any):
if not args.proxy:
raise InvalidArgumentsError("--proxy must be provided")