mxpy 5.1.0__tar.gz → 10.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mxpy-10.0.0/.gitignore +32 -0
- mxpy-10.0.0/LICENSE +11 -0
- mxpy-10.0.0/PKG-INFO +81 -0
- mxpy-10.0.0/README.md +60 -0
- mxpy-10.0.0/multiversx_sdk_cli/__init__.py +0 -0
- mxpy-10.0.0/multiversx_sdk_cli/args_validation.py +71 -0
- mxpy-10.0.0/multiversx_sdk_cli/base_transactions_controller.py +86 -0
- mxpy-10.0.0/multiversx_sdk_cli/cli.py +149 -0
- mxpy-10.0.0/multiversx_sdk_cli/cli_config.py +125 -0
- mxpy-10.0.0/multiversx_sdk_cli/cli_contracts.py +574 -0
- mxpy-10.0.0/multiversx_sdk_cli/cli_data.py +122 -0
- mxpy-10.0.0/multiversx_sdk_cli/cli_delegation.py +978 -0
- mxpy-10.0.0/multiversx_sdk_cli/cli_deps.py +79 -0
- mxpy-10.0.0/multiversx_sdk_cli/cli_dns.py +212 -0
- mxpy-10.0.0/multiversx_sdk_cli/cli_faucet.py +68 -0
- mxpy-10.0.0/multiversx_sdk_cli/cli_ledger.py +47 -0
- mxpy-10.0.0/multiversx_sdk_cli/cli_localnet.py +186 -0
- mxpy-10.0.0/multiversx_sdk_cli/cli_output.py +122 -0
- mxpy-10.0.0/multiversx_sdk_cli/cli_password.py +23 -0
- mxpy-10.0.0/multiversx_sdk_cli/cli_shared.py +580 -0
- mxpy-10.0.0/multiversx_sdk_cli/cli_transactions.py +245 -0
- mxpy-10.0.0/multiversx_sdk_cli/cli_validator_wallet.py +123 -0
- mxpy-10.0.0/multiversx_sdk_cli/cli_validators.py +523 -0
- mxpy-10.0.0/multiversx_sdk_cli/cli_wallet.py +379 -0
- mxpy-10.0.0/multiversx_sdk_cli/config.py +252 -0
- mxpy-10.0.0/multiversx_sdk_cli/constants.py +21 -0
- mxpy-10.0.0/multiversx_sdk_cli/contract_verification.py +169 -0
- mxpy-10.0.0/multiversx_sdk_cli/contracts.py +285 -0
- mxpy-10.0.0/multiversx_sdk_cli/cosign_transaction.py +29 -0
- mxpy-10.0.0/multiversx_sdk_cli/delegation.py +798 -0
- mxpy-10.0.0/multiversx_sdk_cli/dependencies/__init__.py +15 -0
- mxpy-10.0.0/multiversx_sdk_cli/dependencies/install.py +61 -0
- mxpy-10.0.0/multiversx_sdk_cli/dependencies/modules.py +201 -0
- mxpy-10.0.0/multiversx_sdk_cli/dependencies/resolution.py +19 -0
- mxpy-10.0.0/multiversx_sdk_cli/dns.py +163 -0
- mxpy-10.0.0/multiversx_sdk_cli/docker.py +72 -0
- mxpy-10.0.0/multiversx_sdk_cli/downloader.py +56 -0
- mxpy-10.0.0/multiversx_sdk_cli/errors.py +187 -0
- mxpy-10.0.0/multiversx_sdk_cli/guardian_relayer_data.py +16 -0
- mxpy-10.0.0/multiversx_sdk_cli/guards.py +13 -0
- mxpy-10.0.0/multiversx_sdk_cli/interfaces.py +16 -0
- mxpy-10.0.0/multiversx_sdk_cli/localnet/__init__.py +0 -0
- mxpy-10.0.0/multiversx_sdk_cli/localnet/config_default.py +66 -0
- mxpy-10.0.0/multiversx_sdk_cli/localnet/config_general.py +26 -0
- mxpy-10.0.0/multiversx_sdk_cli/localnet/config_networking.py +46 -0
- mxpy-10.0.0/multiversx_sdk_cli/localnet/config_part.py +38 -0
- mxpy-10.0.0/multiversx_sdk_cli/localnet/config_root.py +177 -0
- mxpy-10.0.0/multiversx_sdk_cli/localnet/config_sharding.py +41 -0
- mxpy-10.0.0/multiversx_sdk_cli/localnet/config_software.py +179 -0
- mxpy-10.0.0/multiversx_sdk_cli/localnet/constants.py +8 -0
- mxpy-10.0.0/multiversx_sdk_cli/localnet/genesis.py +10 -0
- mxpy-10.0.0/multiversx_sdk_cli/localnet/genesis_json.py +54 -0
- mxpy-10.0.0/multiversx_sdk_cli/localnet/genesis_smart_contracts_json.py +16 -0
- mxpy-10.0.0/multiversx_sdk_cli/localnet/libraries.py +18 -0
- mxpy-10.0.0/multiversx_sdk_cli/localnet/node.py +27 -0
- mxpy-10.0.0/multiversx_sdk_cli/localnet/node_config_toml.py +83 -0
- mxpy-10.0.0/multiversx_sdk_cli/localnet/nodes_setup_json.py +39 -0
- mxpy-10.0.0/multiversx_sdk_cli/localnet/p2p_toml.py +22 -0
- mxpy-10.0.0/multiversx_sdk_cli/localnet/seednode_p2pKey.pem +4 -0
- mxpy-10.0.0/multiversx_sdk_cli/localnet/step_build_software.py +85 -0
- mxpy-10.0.0/multiversx_sdk_cli/localnet/step_clean.py +14 -0
- mxpy-10.0.0/multiversx_sdk_cli/localnet/step_config.py +215 -0
- mxpy-10.0.0/multiversx_sdk_cli/localnet/step_new.py +19 -0
- mxpy-10.0.0/multiversx_sdk_cli/localnet/step_prerequisites.py +59 -0
- mxpy-10.0.0/multiversx_sdk_cli/localnet/step_start.py +250 -0
- mxpy-10.0.0/multiversx_sdk_cli/localnet/wallets.py +94 -0
- mxpy-10.0.0/multiversx_sdk_cli/myprocess.py +33 -0
- mxpy-10.0.0/multiversx_sdk_cli/sign_verify.py +69 -0
- mxpy-10.0.0/multiversx_sdk_cli/simulation.py +34 -0
- mxpy-10.0.0/multiversx_sdk_cli/transactions.py +171 -0
- mxpy-10.0.0/multiversx_sdk_cli/utils.py +171 -0
- mxpy-10.0.0/multiversx_sdk_cli/ux.py +22 -0
- mxpy-10.0.0/multiversx_sdk_cli/validators.py +537 -0
- mxpy-10.0.0/multiversx_sdk_cli/version.py +28 -0
- mxpy-10.0.0/multiversx_sdk_cli/workstation.py +40 -0
- mxpy-10.0.0/pyproject.toml +44 -0
- mxpy-5.1.0/.github/workflows/python-publish.yml +0 -38
- mxpy-5.1.0/PKG-INFO +0 -13
- mxpy-5.1.0/README.md +0 -3
- mxpy-5.1.0/pyproject.toml +0 -21
mxpy-10.0.0/.gitignore
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
.eggs
|
|
2
|
+
dist
|
|
3
|
+
__pycache__
|
|
4
|
+
*.egg-info
|
|
5
|
+
*.py[cod]
|
|
6
|
+
*$py.class
|
|
7
|
+
.pytest_cache/
|
|
8
|
+
.idea
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
# mypy
|
|
12
|
+
.mypy_cache/
|
|
13
|
+
|
|
14
|
+
# Sphinx documentation
|
|
15
|
+
docs/_build/
|
|
16
|
+
|
|
17
|
+
# Tags generated by ctags
|
|
18
|
+
tags
|
|
19
|
+
|
|
20
|
+
# Environments
|
|
21
|
+
.env
|
|
22
|
+
.venv
|
|
23
|
+
env/
|
|
24
|
+
venv/
|
|
25
|
+
ENV/
|
|
26
|
+
env.bak/
|
|
27
|
+
venv.bak/
|
|
28
|
+
|
|
29
|
+
# Typings
|
|
30
|
+
typings
|
|
31
|
+
|
|
32
|
+
multiversx_sdk_cli/tests/testdata-out
|
mxpy-10.0.0/LICENSE
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
## License
|
|
2
|
+
|
|
3
|
+
The MIT License (MIT)
|
|
4
|
+
|
|
5
|
+
Copyright (c) MultiversX
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
8
|
+
|
|
9
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
mxpy-10.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mxpy
|
|
3
|
+
Version: 10.0.0
|
|
4
|
+
Summary: MultiversX Smart Contracts Tools
|
|
5
|
+
Project-URL: Homepage, https://github.com/multiversx/mx-sdk-py-cli
|
|
6
|
+
Author: MultiversX
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Requires-Python: >=3.8
|
|
14
|
+
Requires-Dist: argcomplete==3.2.2
|
|
15
|
+
Requires-Dist: ledgercomm[hid]
|
|
16
|
+
Requires-Dist: multiversx-sdk[ledger]==1.2.0
|
|
17
|
+
Requires-Dist: requests<3.0.0,>=2.32.0
|
|
18
|
+
Requires-Dist: rich==13.3.4
|
|
19
|
+
Requires-Dist: toml>=0.10.2
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# Description
|
|
23
|
+
Python Command Line Tools for interacting with Multivers<sup>X</sup>.
|
|
24
|
+
|
|
25
|
+
## Documentation
|
|
26
|
+
[docs.multiversx.com](https://docs.multiversx.com/sdk-and-tools/sdk-py/)
|
|
27
|
+
|
|
28
|
+
## CLI
|
|
29
|
+
[CLI](CLI.md)
|
|
30
|
+
|
|
31
|
+
## Distribution
|
|
32
|
+
[pipx](https://docs.multiversx.com/sdk-and-tools/sdk-py/installing-mxpy/) [(PyPi)](https://pypi.org/project/multiversx-sdk-cli/#history)
|
|
33
|
+
|
|
34
|
+
## Development setup
|
|
35
|
+
|
|
36
|
+
Clone this repository and cd into it:
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
git clone https://github.com/multiversx/mx-sdk-py-cli.git
|
|
40
|
+
cd mx-sdk-py-cli
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Virtual environment
|
|
44
|
+
|
|
45
|
+
Create a virtual environment and install the dependencies:
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
python3 -m venv ./venv
|
|
49
|
+
source ./venv/bin/activate
|
|
50
|
+
pip install -r ./requirements.txt --upgrade
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Install development dependencies, as well:
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
pip install -r ./requirements-dev.txt --upgrade
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Allow `pre-commit` to automatically run on `git commit`:
|
|
60
|
+
```
|
|
61
|
+
pre-commit install
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Above, `requirements.txt` should mirror the **dependencies** section of `pyproject.toml`.
|
|
65
|
+
|
|
66
|
+
If using VSCode, restart it or follow these steps:
|
|
67
|
+
- `Ctrl + Shift + P`
|
|
68
|
+
- _Select Interpreter_
|
|
69
|
+
- Choose `./venv/bin/python`.
|
|
70
|
+
|
|
71
|
+
### Using your local `mxpy`
|
|
72
|
+
|
|
73
|
+
If you want to test the modifications you locally made to `mxpy`, set `PYTHONPATH` with the path to your local repository path.
|
|
74
|
+
|
|
75
|
+
For example, if you cloned the repository at `~/mx-sdk-py-cli`, run:
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
export PYTHONPATH="~/mx-sdk-py-cli"
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Then `mxpy` will use the code in your local repository.
|
mxpy-10.0.0/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Description
|
|
2
|
+
Python Command Line Tools for interacting with Multivers<sup>X</sup>.
|
|
3
|
+
|
|
4
|
+
## Documentation
|
|
5
|
+
[docs.multiversx.com](https://docs.multiversx.com/sdk-and-tools/sdk-py/)
|
|
6
|
+
|
|
7
|
+
## CLI
|
|
8
|
+
[CLI](CLI.md)
|
|
9
|
+
|
|
10
|
+
## Distribution
|
|
11
|
+
[pipx](https://docs.multiversx.com/sdk-and-tools/sdk-py/installing-mxpy/) [(PyPi)](https://pypi.org/project/multiversx-sdk-cli/#history)
|
|
12
|
+
|
|
13
|
+
## Development setup
|
|
14
|
+
|
|
15
|
+
Clone this repository and cd into it:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
git clone https://github.com/multiversx/mx-sdk-py-cli.git
|
|
19
|
+
cd mx-sdk-py-cli
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Virtual environment
|
|
23
|
+
|
|
24
|
+
Create a virtual environment and install the dependencies:
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
python3 -m venv ./venv
|
|
28
|
+
source ./venv/bin/activate
|
|
29
|
+
pip install -r ./requirements.txt --upgrade
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Install development dependencies, as well:
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
pip install -r ./requirements-dev.txt --upgrade
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Allow `pre-commit` to automatically run on `git commit`:
|
|
39
|
+
```
|
|
40
|
+
pre-commit install
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Above, `requirements.txt` should mirror the **dependencies** section of `pyproject.toml`.
|
|
44
|
+
|
|
45
|
+
If using VSCode, restart it or follow these steps:
|
|
46
|
+
- `Ctrl + Shift + P`
|
|
47
|
+
- _Select Interpreter_
|
|
48
|
+
- Choose `./venv/bin/python`.
|
|
49
|
+
|
|
50
|
+
### Using your local `mxpy`
|
|
51
|
+
|
|
52
|
+
If you want to test the modifications you locally made to `mxpy`, set `PYTHONPATH` with the path to your local repository path.
|
|
53
|
+
|
|
54
|
+
For example, if you cloned the repository at `~/mx-sdk-py-cli`, run:
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
export PYTHONPATH="~/mx-sdk-py-cli"
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Then `mxpy` will use the code in your local repository.
|
|
File without changes
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
from multiversx_sdk_cli.errors import InvalidArgumentsError
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def validate_transaction_args(args: Any):
|
|
7
|
+
validate_nonce_args(args)
|
|
8
|
+
validate_receiver_args(args)
|
|
9
|
+
validate_gas_limit_args(args)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
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."""
|
|
14
|
+
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")
|
|
17
|
+
|
|
18
|
+
if hasattr(args, "proxy") and not args.proxy:
|
|
19
|
+
raise InvalidArgumentsError("--proxy must be provided if --recall-nonce is used")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def validate_receiver_args(args: Any):
|
|
23
|
+
"""Ensure that receiver is provided."""
|
|
24
|
+
if hasattr(args, "receiver") and not args.receiver:
|
|
25
|
+
raise InvalidArgumentsError("--receiver must be provided")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def validate_gas_limit_args(args: Any):
|
|
29
|
+
"""Ensure that gas_limit is provided."""
|
|
30
|
+
if hasattr(args, "gas_limit") and not args.gas_limit:
|
|
31
|
+
raise InvalidArgumentsError("--gas-limit must be provided")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def ensure_wallet_args_are_provided(args: Any):
|
|
35
|
+
signing_methods = [args.pem, args.keyfile, args.ledger]
|
|
36
|
+
|
|
37
|
+
if all(signing_methods):
|
|
38
|
+
raise InvalidArgumentsError("Only one of --pem, --keyfile, or --ledger must be provided")
|
|
39
|
+
|
|
40
|
+
if not any(signing_methods):
|
|
41
|
+
raise InvalidArgumentsError("One of --pem, --keyfile, or --ledger must be provided")
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def ensure_relayer_wallet_args_are_provided(args: Any):
|
|
45
|
+
signing_methods = [args.relayer_pem, args.relayer_keyfile, args.relayer_ledger]
|
|
46
|
+
|
|
47
|
+
if all(signing_methods):
|
|
48
|
+
raise InvalidArgumentsError(
|
|
49
|
+
"Only one of --relayer-pem, --relayer-keyfile, or --relayer-ledger must be provided"
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
if not any(signing_methods):
|
|
53
|
+
raise InvalidArgumentsError("One of --relayer-pem, --relayer-keyfile, or --relayer-ledger must be provided")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def validate_broadcast_args(args: Any):
|
|
57
|
+
if args.send and args.simulate:
|
|
58
|
+
raise InvalidArgumentsError("Cannot both 'simulate' and 'send' a transaction")
|
|
59
|
+
|
|
60
|
+
if args.send or args.simulate:
|
|
61
|
+
validate_proxy_argument(args)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def validate_chain_id_args(args: Any):
|
|
65
|
+
if not args.chain and not args.proxy:
|
|
66
|
+
raise InvalidArgumentsError("Either --chain or --proxy must be provided")
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def validate_proxy_argument(args: Any):
|
|
70
|
+
if not args.proxy:
|
|
71
|
+
raise InvalidArgumentsError("--proxy must be provided")
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
from typing import Optional, Union
|
|
2
|
+
|
|
3
|
+
from multiversx_sdk import LedgerAccount, Transaction, TransactionComputer
|
|
4
|
+
|
|
5
|
+
from multiversx_sdk_cli.constants import (
|
|
6
|
+
EXTRA_GAS_LIMIT_FOR_GUARDED_TRANSACTIONS,
|
|
7
|
+
EXTRA_GAS_LIMIT_FOR_RELAYED_TRANSACTIONS,
|
|
8
|
+
)
|
|
9
|
+
from multiversx_sdk_cli.cosign_transaction import cosign_transaction
|
|
10
|
+
from multiversx_sdk_cli.interfaces import IAccount
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class BaseTransactionsController:
|
|
14
|
+
def __init__(self) -> None:
|
|
15
|
+
pass
|
|
16
|
+
|
|
17
|
+
def sign_transaction(
|
|
18
|
+
self,
|
|
19
|
+
transaction: Transaction,
|
|
20
|
+
sender: Optional[IAccount] = None,
|
|
21
|
+
guardian: Optional[IAccount] = None,
|
|
22
|
+
relayer: Optional[IAccount] = None,
|
|
23
|
+
guardian_service_url: Optional[str] = None,
|
|
24
|
+
guardian_2fa_code: Optional[str] = None,
|
|
25
|
+
):
|
|
26
|
+
"""Signs the transaction using the sender's account and, if required, additionally signs with the guardian's and relayer's accounts. Ensures the appropriate transaction options are set as needed."""
|
|
27
|
+
self._set_options_for_guarded_transaction_if_needed(transaction)
|
|
28
|
+
self._set_options_for_hash_signing_if_needed(transaction, sender, guardian, relayer)
|
|
29
|
+
|
|
30
|
+
if sender:
|
|
31
|
+
transaction.signature = sender.sign_transaction(transaction)
|
|
32
|
+
|
|
33
|
+
self._sign_guarded_transaction_if_guardian(
|
|
34
|
+
transaction,
|
|
35
|
+
guardian,
|
|
36
|
+
guardian_service_url,
|
|
37
|
+
guardian_2fa_code,
|
|
38
|
+
)
|
|
39
|
+
self._sign_relayed_transaction_if_relayer(transaction, relayer)
|
|
40
|
+
|
|
41
|
+
def add_extra_gas_limit_if_required(self, transaction: Transaction):
|
|
42
|
+
"""In case of guarded or relayed transactions, extra gas limit is added."""
|
|
43
|
+
if transaction.guardian:
|
|
44
|
+
transaction.gas_limit += EXTRA_GAS_LIMIT_FOR_GUARDED_TRANSACTIONS
|
|
45
|
+
|
|
46
|
+
if transaction.relayer:
|
|
47
|
+
transaction.gas_limit += EXTRA_GAS_LIMIT_FOR_RELAYED_TRANSACTIONS
|
|
48
|
+
|
|
49
|
+
def _set_options_for_guarded_transaction_if_needed(self, transaction: Transaction):
|
|
50
|
+
if transaction.guardian:
|
|
51
|
+
transaction_computer = TransactionComputer()
|
|
52
|
+
transaction_computer.apply_guardian(transaction, transaction.guardian)
|
|
53
|
+
|
|
54
|
+
def _set_options_for_hash_signing_if_needed(
|
|
55
|
+
self,
|
|
56
|
+
transaction: Transaction,
|
|
57
|
+
sender: Union[IAccount, None],
|
|
58
|
+
guardian: Union[IAccount, None],
|
|
59
|
+
relayer: Union[IAccount, None],
|
|
60
|
+
):
|
|
61
|
+
if (
|
|
62
|
+
isinstance(sender, LedgerAccount)
|
|
63
|
+
or isinstance(guardian, LedgerAccount)
|
|
64
|
+
or isinstance(relayer, LedgerAccount)
|
|
65
|
+
):
|
|
66
|
+
transaction_computer = TransactionComputer()
|
|
67
|
+
transaction_computer.apply_options_for_hash_signing(transaction)
|
|
68
|
+
|
|
69
|
+
def _sign_guarded_transaction_if_guardian(
|
|
70
|
+
self,
|
|
71
|
+
transaction: Transaction,
|
|
72
|
+
guardian: Union[IAccount, None],
|
|
73
|
+
guardian_service_url: Union[str, None],
|
|
74
|
+
guardian_2fa_code: Union[str, None],
|
|
75
|
+
) -> Transaction:
|
|
76
|
+
# If the guardian account is provided, we sign locally. Otherwise, we reach for the trusted cosign service.
|
|
77
|
+
if guardian:
|
|
78
|
+
transaction.guardian_signature = guardian.sign_transaction(transaction)
|
|
79
|
+
elif transaction.guardian and guardian_service_url and guardian_2fa_code:
|
|
80
|
+
cosign_transaction(transaction, guardian_service_url, guardian_2fa_code)
|
|
81
|
+
|
|
82
|
+
return transaction
|
|
83
|
+
|
|
84
|
+
def _sign_relayed_transaction_if_relayer(self, transaction: Transaction, relayer: Union[IAccount, None]):
|
|
85
|
+
if relayer and transaction.relayer:
|
|
86
|
+
transaction.relayer_signature = relayer.sign_transaction(transaction)
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# PYTHON_ARGCOMPLETE_OK
|
|
2
|
+
import argparse
|
|
3
|
+
import logging
|
|
4
|
+
import sys
|
|
5
|
+
from argparse import ArgumentParser
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
import argcomplete
|
|
9
|
+
from multiversx_sdk import LibraryConfig
|
|
10
|
+
from rich.logging import RichHandler
|
|
11
|
+
|
|
12
|
+
import multiversx_sdk_cli.cli_config
|
|
13
|
+
import multiversx_sdk_cli.cli_contracts
|
|
14
|
+
import multiversx_sdk_cli.cli_data
|
|
15
|
+
import multiversx_sdk_cli.cli_delegation
|
|
16
|
+
import multiversx_sdk_cli.cli_deps
|
|
17
|
+
import multiversx_sdk_cli.cli_dns
|
|
18
|
+
import multiversx_sdk_cli.cli_faucet
|
|
19
|
+
import multiversx_sdk_cli.cli_ledger
|
|
20
|
+
import multiversx_sdk_cli.cli_localnet
|
|
21
|
+
import multiversx_sdk_cli.cli_transactions
|
|
22
|
+
import multiversx_sdk_cli.cli_validator_wallet
|
|
23
|
+
import multiversx_sdk_cli.cli_validators
|
|
24
|
+
import multiversx_sdk_cli.cli_wallet
|
|
25
|
+
import multiversx_sdk_cli.version
|
|
26
|
+
from multiversx_sdk_cli import config, errors, utils, ux
|
|
27
|
+
|
|
28
|
+
logger = logging.getLogger("cli")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def main(cli_args: list[str] = sys.argv[1:]):
|
|
32
|
+
try:
|
|
33
|
+
_do_main(cli_args)
|
|
34
|
+
except errors.KnownError as err:
|
|
35
|
+
logger.critical(err.get_pretty())
|
|
36
|
+
ux.show_critical_error(err.get_pretty())
|
|
37
|
+
return 1
|
|
38
|
+
except KeyboardInterrupt:
|
|
39
|
+
print("process killed by user.")
|
|
40
|
+
return 1
|
|
41
|
+
return 0
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _do_main(cli_args: list[str]):
|
|
45
|
+
utils.ensure_folder(config.SDK_PATH)
|
|
46
|
+
argv_with_config_args = config.add_config_args(cli_args)
|
|
47
|
+
parser = setup_parser(argv_with_config_args)
|
|
48
|
+
argcomplete.autocomplete(parser)
|
|
49
|
+
args = parser.parse_args(argv_with_config_args)
|
|
50
|
+
|
|
51
|
+
if args.verbose:
|
|
52
|
+
logging.basicConfig(
|
|
53
|
+
level="DEBUG",
|
|
54
|
+
force=True,
|
|
55
|
+
format="%(name)s: %(message)s",
|
|
56
|
+
handlers=[RichHandler(show_time=False, rich_tracebacks=True)],
|
|
57
|
+
)
|
|
58
|
+
else:
|
|
59
|
+
logging.basicConfig(
|
|
60
|
+
level="INFO",
|
|
61
|
+
format="%(name)s: %(message)s",
|
|
62
|
+
handlers=[RichHandler(show_time=False, rich_tracebacks=True)],
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
verify_deprecated_entries_in_config_file()
|
|
66
|
+
default_hrp = config.get_address_hrp()
|
|
67
|
+
LibraryConfig.default_address_hrp = default_hrp
|
|
68
|
+
|
|
69
|
+
if not hasattr(args, "func"):
|
|
70
|
+
parser.print_help()
|
|
71
|
+
else:
|
|
72
|
+
args.func(args)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def setup_parser(args: list[str]):
|
|
76
|
+
parser = ArgumentParser(
|
|
77
|
+
prog="mxpy",
|
|
78
|
+
usage="mxpy [-h] [-v] [--verbose] COMMAND-GROUP [-h] COMMAND ...",
|
|
79
|
+
description="""
|
|
80
|
+
-----------
|
|
81
|
+
DESCRIPTION
|
|
82
|
+
-----------
|
|
83
|
+
mxpy is part of the multiversx-sdk and consists of Command Line Tools and Python SDK
|
|
84
|
+
for interacting with the Blockchain (in general) and with Smart Contracts (in particular).
|
|
85
|
+
|
|
86
|
+
mxpy targets a broad audience of users and developers.
|
|
87
|
+
|
|
88
|
+
See:
|
|
89
|
+
- https://docs.multiversx.com/sdk-and-tools/sdk-py
|
|
90
|
+
- https://docs.multiversx.com/sdk-and-tools/sdk-py/mxpy-cli
|
|
91
|
+
""",
|
|
92
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
parser._positionals.title = "COMMAND GROUPS"
|
|
96
|
+
parser._optionals.title = "TOP-LEVEL OPTIONS"
|
|
97
|
+
version = multiversx_sdk_cli.version.get_version()
|
|
98
|
+
parser.add_argument(
|
|
99
|
+
"-v",
|
|
100
|
+
"--version",
|
|
101
|
+
action="version",
|
|
102
|
+
version=f"MultiversX Python CLI (mxpy) {version}",
|
|
103
|
+
)
|
|
104
|
+
parser.add_argument("--verbose", action="store_true", default=False)
|
|
105
|
+
|
|
106
|
+
subparsers = parser.add_subparsers()
|
|
107
|
+
commands: list[Any] = []
|
|
108
|
+
|
|
109
|
+
commands.append(multiversx_sdk_cli.cli_contracts.setup_parser(args, subparsers))
|
|
110
|
+
commands.append(multiversx_sdk_cli.cli_transactions.setup_parser(args, subparsers))
|
|
111
|
+
commands.append(multiversx_sdk_cli.cli_validators.setup_parser(args, subparsers))
|
|
112
|
+
commands.append(multiversx_sdk_cli.cli_ledger.setup_parser(subparsers))
|
|
113
|
+
commands.append(multiversx_sdk_cli.cli_wallet.setup_parser(args, subparsers))
|
|
114
|
+
commands.append(multiversx_sdk_cli.cli_validator_wallet.setup_parser(args, subparsers))
|
|
115
|
+
commands.append(multiversx_sdk_cli.cli_deps.setup_parser(subparsers))
|
|
116
|
+
commands.append(multiversx_sdk_cli.cli_config.setup_parser(subparsers))
|
|
117
|
+
commands.append(multiversx_sdk_cli.cli_localnet.setup_parser(args, subparsers))
|
|
118
|
+
commands.append(multiversx_sdk_cli.cli_data.setup_parser(subparsers))
|
|
119
|
+
commands.append(multiversx_sdk_cli.cli_delegation.setup_parser(args, subparsers))
|
|
120
|
+
commands.append(multiversx_sdk_cli.cli_dns.setup_parser(args, subparsers))
|
|
121
|
+
commands.append(multiversx_sdk_cli.cli_faucet.setup_parser(args, subparsers))
|
|
122
|
+
|
|
123
|
+
parser.epilog = """
|
|
124
|
+
----------------------
|
|
125
|
+
COMMAND GROUPS summary
|
|
126
|
+
----------------------
|
|
127
|
+
"""
|
|
128
|
+
for choice, sub in subparsers.choices.items():
|
|
129
|
+
parser.epilog += f"{choice.ljust(30)} {sub.description}\n"
|
|
130
|
+
|
|
131
|
+
return parser
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def verify_deprecated_entries_in_config_file():
|
|
135
|
+
deprecated_keys = config.get_deprecated_entries_in_config_file()
|
|
136
|
+
if len(deprecated_keys) == 0:
|
|
137
|
+
return
|
|
138
|
+
|
|
139
|
+
config_path = config.resolve_config_path()
|
|
140
|
+
message = f"The following config entries are deprecated. Please access `{str(config_path)}` and remove them. \n"
|
|
141
|
+
for entry in deprecated_keys:
|
|
142
|
+
message += f"-> {entry} \n"
|
|
143
|
+
|
|
144
|
+
ux.show_warning(message.rstrip("\n"))
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
if __name__ == "__main__":
|
|
148
|
+
ret = main(sys.argv[1:])
|
|
149
|
+
sys.exit(ret)
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import os
|
|
3
|
+
import sys
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from multiversx_sdk_cli import cli_shared, config, utils
|
|
7
|
+
from multiversx_sdk_cli.ux import confirm_continuation
|
|
8
|
+
|
|
9
|
+
logger = logging.getLogger("cli.config")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def setup_parser(subparsers: Any) -> Any:
|
|
13
|
+
parser = cli_shared.add_group_subparser(subparsers, "config", "Configure multiversx-sdk (default values etc.)")
|
|
14
|
+
subparsers = parser.add_subparsers()
|
|
15
|
+
|
|
16
|
+
sub = cli_shared.add_command_subparser(subparsers, "config", "dump", "Dumps configuration.")
|
|
17
|
+
sub.add_argument(
|
|
18
|
+
"--defaults",
|
|
19
|
+
required=False,
|
|
20
|
+
help="dump defaults instead of local config",
|
|
21
|
+
action="store_true",
|
|
22
|
+
)
|
|
23
|
+
sub.set_defaults(func=dump)
|
|
24
|
+
|
|
25
|
+
sub = cli_shared.add_command_subparser(subparsers, "config", "get", "Gets a configuration value.")
|
|
26
|
+
_add_name_arg(sub)
|
|
27
|
+
sub.set_defaults(func=get_value)
|
|
28
|
+
|
|
29
|
+
sub = cli_shared.add_command_subparser(subparsers, "config", "set", "Sets a configuration value.")
|
|
30
|
+
_add_name_arg(sub)
|
|
31
|
+
sub.add_argument("value", help="the new value")
|
|
32
|
+
sub.set_defaults(func=set_value)
|
|
33
|
+
|
|
34
|
+
sub = cli_shared.add_command_subparser(subparsers, "config", "delete", "Deletes a configuration value.")
|
|
35
|
+
_add_name_arg(sub)
|
|
36
|
+
sub.set_defaults(func=delete_value)
|
|
37
|
+
|
|
38
|
+
sub = cli_shared.add_command_subparser(subparsers, "config", "new", "Creates a new configuration.")
|
|
39
|
+
_add_name_arg(sub)
|
|
40
|
+
sub.add_argument(
|
|
41
|
+
"--template",
|
|
42
|
+
required=False,
|
|
43
|
+
help="template from which to create the new config",
|
|
44
|
+
)
|
|
45
|
+
sub.set_defaults(func=new_config)
|
|
46
|
+
|
|
47
|
+
sub = cli_shared.add_command_subparser(subparsers, "config", "switch", "Switch to a different config")
|
|
48
|
+
_add_name_arg(sub)
|
|
49
|
+
sub.set_defaults(func=switch_config)
|
|
50
|
+
|
|
51
|
+
sub = cli_shared.add_command_subparser(subparsers, "config", "list", "List available configs")
|
|
52
|
+
sub.set_defaults(func=list_configs)
|
|
53
|
+
|
|
54
|
+
sub = cli_shared.add_command_subparser(
|
|
55
|
+
subparsers,
|
|
56
|
+
"config",
|
|
57
|
+
"reset",
|
|
58
|
+
"Deletes the config file. Default config will be used.",
|
|
59
|
+
)
|
|
60
|
+
sub.set_defaults(func=delete_config)
|
|
61
|
+
|
|
62
|
+
parser.epilog = cli_shared.build_group_epilog(subparsers)
|
|
63
|
+
return subparsers
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _add_name_arg(sub: Any):
|
|
67
|
+
sub.add_argument("name", help="the name of the configuration entry")
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def dump(args: Any):
|
|
71
|
+
if args.defaults:
|
|
72
|
+
_dump_defaults()
|
|
73
|
+
else:
|
|
74
|
+
_dump_active()
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _dump_defaults():
|
|
78
|
+
utils.dump_out_json(config.get_defaults(), sys.stdout)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _dump_active():
|
|
82
|
+
utils.dump_out_json(config.get_active(), sys.stdout)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def get_value(args: Any):
|
|
86
|
+
value = config.get_value(args.name)
|
|
87
|
+
print(value)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def set_value(args: Any):
|
|
91
|
+
config.set_value(args.name, args.value)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def delete_value(args: Any):
|
|
95
|
+
config.delete_value(args.name)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def new_config(args: Any):
|
|
99
|
+
config.create_new_config(name=args.name, template=args.template)
|
|
100
|
+
_dump_active()
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def switch_config(args: Any):
|
|
104
|
+
config.set_active(args.name)
|
|
105
|
+
_dump_active()
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def list_configs(args: Any):
|
|
109
|
+
data = config.read_file()
|
|
110
|
+
configurations = data.get("configurations", {})
|
|
111
|
+
for config_name in configurations.keys():
|
|
112
|
+
if config_name == data.get("active", "default"):
|
|
113
|
+
config_name += "*"
|
|
114
|
+
print(config_name)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def delete_config(args: Any):
|
|
118
|
+
config_file = config.resolve_config_path()
|
|
119
|
+
if not config_file.is_file():
|
|
120
|
+
logger.info("Config file not found. Aborting...")
|
|
121
|
+
return
|
|
122
|
+
|
|
123
|
+
confirm_continuation(f"The file `{str(config_file)}` will be deleted. Do you want to continue? (y/n)")
|
|
124
|
+
os.remove(config_file)
|
|
125
|
+
logger.info("Successfully deleted the config file")
|