|
1 | 1 | import argparse |
2 | 2 | import ast |
| 3 | +import string |
3 | 4 | import sys |
4 | 5 | from argparse import FileType |
5 | 6 | from typing import Any, List, Text |
6 | 7 |
|
7 | 8 | from erdpy import config, errors, scope, utils |
8 | 9 | from erdpy.accounts import Account |
| 10 | +from erdpy.ledger.ledger_functions import do_get_ledger_address |
9 | 11 | from erdpy.proxy.core import ElrondProxy |
10 | 12 | from erdpy.transactions import Transaction |
11 | 13 |
|
@@ -69,18 +71,22 @@ def add_tx_args(sub: Any, with_nonce: bool = True, with_receiver: bool = True, w |
69 | 71 |
|
70 | 72 | sub.add_argument("--chain", default=scope.get_chain_id(), help="the chain identifier (default: %(default)s)") |
71 | 73 | sub.add_argument("--version", type=int, default=scope.get_tx_version(), help="the transaction version (default: %(default)s)") |
| 74 | + sub.add_argument("--options", type=int, default=0, help="the transaction options (default: 0)") |
72 | 75 |
|
73 | 76 |
|
74 | 77 | def add_wallet_args(sub: Any): |
75 | | - sub.add_argument("--pem", required=not (utils.is_arg_present("--keyfile", sys.argv)), help="🔑 the PEM file, if keyfile not provided") |
| 78 | + sub.add_argument("--pem", required=check_if_sign_method_required("--pem"), help="🔑 the PEM file, if keyfile not provided") |
76 | 79 | sub.add_argument("--pem-index", default=0, help="🔑 the index in the PEM file (default: %(default)s)") |
77 | | - sub.add_argument("--keyfile", required=not (utils.is_arg_present("--pem", sys.argv)), help="🔑 a JSON keyfile, if PEM not provided") |
78 | | - sub.add_argument("--passfile", required=not (utils.is_arg_present("--pem", sys.argv)), help="🔑 a file containing keyfile's password, if keyfile provided") |
| 80 | + sub.add_argument("--keyfile", required=check_if_sign_method_required("--keyfile"), help="🔑 a JSON keyfile, if PEM not provided") |
| 81 | + sub.add_argument("--passfile", required=(utils.is_arg_present("--keyfile", sys.argv)), help="🔑 a file containing keyfile's password, if keyfile provided") |
| 82 | + sub.add_argument("--ledger", action="store_true", required=check_if_sign_method_required("--ledger"), default=False, help="🔐 bool flag for signing transaction using ledger") |
| 83 | + sub.add_argument("--ledger-account-index", type=int, default=0, help="🔐 the index of the account when using Ledger") |
| 84 | + sub.add_argument("--ledger-address-index", type=int, default=0, help="🔐 the index of the address when using Ledger") |
79 | 85 | sub.add_argument("--sender-username", required=False, help="🖄 the username of the sender") |
80 | 86 |
|
81 | 87 |
|
82 | 88 | def add_proxy_arg(sub: Any): |
83 | | - sub.add_argument("--proxy", default=scope.get_proxy(), help="🖧 the URL of the proxy (default: %(default)s)") |
| 89 | + sub.add_argument("--proxy", default=scope.get_proxy(), help="🔗 the URL of the proxy (default: %(default)s)") |
84 | 90 |
|
85 | 91 |
|
86 | 92 | def add_outfile_arg(sub: Any, what: str = ""): |
@@ -109,6 +115,9 @@ def prepare_nonce_in_args(args: Any): |
109 | 115 | account = Account(pem_file=args.pem, pem_index=args.pem_index) |
110 | 116 | elif args.keyfile and args.passfile: |
111 | 117 | account = Account(key_file=args.keyfile, pass_file=args.passfile) |
| 118 | + elif args.ledger: |
| 119 | + address = do_get_ledger_address(account_index=args.ledger_account_index, address_index=args.ledger_address_index) |
| 120 | + account = Account(address=address) |
112 | 121 | else: |
113 | 122 | raise errors.NoWalletProvided() |
114 | 123 |
|
@@ -138,3 +147,17 @@ def send_or_simulate(tx: Transaction, args: Any): |
138 | 147 | elif args.simulate: |
139 | 148 | response = tx.simulate(ElrondProxy(args.proxy)) |
140 | 149 | utils.dump_out_json(response) |
| 150 | + |
| 151 | + |
| 152 | +def check_if_sign_method_required(checked_method: string) -> bool: |
| 153 | + methods = ["--pem", "--keyfile", "--ledger"] |
| 154 | + rest_of_methods = [] |
| 155 | + for method in methods: |
| 156 | + if method != checked_method: |
| 157 | + rest_of_methods.append(method) |
| 158 | + |
| 159 | + for method in rest_of_methods: |
| 160 | + if utils.is_arg_present(method, sys.argv): |
| 161 | + return False |
| 162 | + |
| 163 | + return True |
0 commit comments