Skip to content

Commit

Permalink
Merge pull request #404 from multiversx/feat/next
Browse files Browse the repository at this point in the history
Merge feat/next into main
  • Loading branch information
popenta committed Jan 30, 2024
2 parents 4c08e9a + f883790 commit 7d110d2
Show file tree
Hide file tree
Showing 22 changed files with 310 additions and 227 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ jobs:
pytest .
- name: Run CLI tests
run: |
python3 -m multiversx_sdk_cli.cli config set dependencies.vmtools.tag v1.4.60
cd ./multiversx_sdk_cli/tests
source ./test_cli_contracts.sh && testAll || return 1
source ./test_cli_dns.sh && testOffline || return 1
21 changes: 19 additions & 2 deletions CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ mxpy is part of the multiversx-sdk and consists of Command Line Tools and Python
for interacting with the Blockchain (in general) and with Smart Contracts (in particular).
mxpy targets a broad audience of users and developers.
https://docs.multiversx.com/sdk-and-tools/mxpy.
See:
- https://docs.multiversx.com/sdk-and-tools/sdk-py
- https://docs.multiversx.com/sdk-and-tools/sdk-py/mxpy-cli
COMMAND GROUPS:
Expand Down Expand Up @@ -1293,7 +1296,7 @@ usage: mxpy config COMMAND [-h] ...
Configure multiversx-sdk (default values etc.)
COMMANDS:
{dump,get,set,delete,new,switch,list}
{dump,get,set,delete,new,switch,list,reset}
OPTIONS:
-h, --help show this help message and exit
Expand All @@ -1308,6 +1311,7 @@ delete Deletes a configuration value.
new Creates a new configuration.
switch Switch to a different config
list List available configs
reset Deletes the config file. Default config will be used.
```
### Configuration.Dump
Expand Down Expand Up @@ -1399,6 +1403,19 @@ usage: mxpy config list [-h] ...
List available configs
options:
-h, --help show this help message and exit
```
### Configuration.Reset


```
$ mxpy config reset --help
usage: mxpy config reset [-h] ...
Deletes the config file. Default config will be used.
options:
-h, --help show this help message and exit
Expand Down
1 change: 1 addition & 0 deletions CLI.md.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ generate() {
command "Configuration.New" "config new"
command "Configuration.Switch" "config switch"
command "Configuration.List" "config list"
command "Configuration.Reset" "config reset"

group "Data" "data"
command "Data.Dump" "data parse"
Expand Down
7 changes: 4 additions & 3 deletions multiversx_sdk_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,12 @@ def verify_deprecated_entries_in_config_file():
if len(deprecated_keys) == 0:
return

message = "The following entries are deprecated. Please remove them from the `mxpy.json` config file. \n"
config_path = config.resolve_config_path()
message = f"The following config entries are deprecated. Please access `{str(config_path)}` and remove them. \n"
for entry in deprecated_keys:
message += f"{entry} \n"
message += f"-> {entry} \n"

ux.show_warning(message)
ux.show_warning(message.rstrip('\n'))


if __name__ == "__main__":
Expand Down
16 changes: 16 additions & 0 deletions multiversx_sdk_cli/cli_config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import logging
import os
import sys
from typing import Any

from multiversx_sdk_cli import cli_shared, config, utils
from multiversx_sdk_cli.ux import confirm_continuation

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

Expand Down Expand Up @@ -40,6 +42,9 @@ def setup_parser(subparsers: Any) -> Any:
sub = cli_shared.add_command_subparser(subparsers, "config", "list", "List available configs")
sub.set_defaults(func=list_configs)

sub = cli_shared.add_command_subparser(subparsers, "config", "reset", "Deletes the config file. Default config will be used.")
sub.set_defaults(func=delete_config)

parser.epilog = cli_shared.build_group_epilog(subparsers)
return subparsers

Expand Down Expand Up @@ -93,3 +98,14 @@ def list_configs(args: Any):
if config_name == data.get("active", "default"):
config_name += "*"
print(config_name)


def delete_config(args: Any):
config_file = config.resolve_config_path()
if not config_file.is_file():
logger.info(f"Config file not found. Aborting...")
return

confirm_continuation(f"The file `{str(config_file)}` will be deleted. Do you want to continue? (y/n)")
os.remove(config_file)
logger.info("Successfully deleted the config file")
46 changes: 42 additions & 4 deletions multiversx_sdk_cli/cli_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def _add_contract_arg(sub: Any):


def _add_function_arg(sub: Any):
sub.add_argument("--function", required=True, help="the function to call")
sub.add_argument("--function", required=True, type=str, help="the function to call")


def _add_arguments_arg(sub: Any):
Expand Down Expand Up @@ -321,7 +321,20 @@ def deploy(args: Any):
address_computer = AddressComputer(NUMBER_OF_SHARDS)
contract_address = address_computer.compute_contract_address(deployer=sender.address, deployment_nonce=args.nonce)

tx = contract.prepare_deploy_transaction(sender, args)
tx = contract.prepare_deploy_transaction(
owner=sender,
bytecode=Path(args.bytecode),
arguments=args.arguments,
upgradeable=args.metadata_upgradeable,
readable=args.metadata_readable,
payable=args.metadata_payable,
payable_by_sc=args.metadata_payable_by_sc,
gas_limit=int(args.gas_limit),
value=int(args.value),
nonce=int(args.nonce),
version=int(args.version),
options=int(args.options),
guardian=args.guardian)
tx = _sign_guarded_tx(args, tx)

logger.info("Contract address: %s", contract_address.to_bech32())
Expand Down Expand Up @@ -356,7 +369,18 @@ def call(args: Any):
contract = SmartContract(config)
contract_address = Address.new_from_bech32(args.contract)

tx = contract.prepare_execute_transaction(sender, args)
tx = contract.prepare_execute_transaction(
caller=sender,
contract=contract_address,
function=args.function,
arguments=args.arguments,
gas_limit=int(args.gas_limit),
value=int(args.value),
transfers=args.token_transfers,
nonce=int(args.nonce),
version=int(args.version),
options=int(args.options),
guardian=args.guardian)
tx = _sign_guarded_tx(args, tx)

_send_or_simulate(tx, contract_address, args)
Expand All @@ -374,7 +398,21 @@ def upgrade(args: Any):
contract = SmartContract(config)
contract_address = Address.new_from_bech32(args.contract)

tx = contract.prepare_upgrade_transaction(sender, args)
tx = contract.prepare_upgrade_transaction(
owner=sender,
contract=contract_address,
bytecode=Path(args.bytecode),
arguments=args.arguments,
upgradeable=args.metadata_upgradeable,
readable=args.metadata_readable,
payable=args.metadata_payable,
payable_by_sc=args.metadata_payable_by_sc,
gas_limit=int(args.gas_limit),
value=int(args.value),
nonce=int(args.nonce),
version=int(args.version),
options=int(args.options),
guardian=args.guardian)
tx = _sign_guarded_tx(args, tx)

_send_or_simulate(tx, contract_address, args)
Expand Down
39 changes: 31 additions & 8 deletions multiversx_sdk_cli/cli_deps.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import logging
from typing import Any
from typing import Any, List, Tuple

from multiversx_sdk_cli import cli_shared, config, dependencies, errors
from multiversx_sdk_cli.dependencies.install import get_deps_dict
from multiversx_sdk_cli.dependencies.modules import DependencyModule

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

Expand Down Expand Up @@ -34,16 +35,38 @@ def install(args: Any):

def check(args: Any):
name: str = args.name
module = dependencies.get_module_by_key(name)
tag_to_check: str = config.get_dependency_tag(module.key)

if name == "all":
all_dependencies = dependencies.get_all_deps()
missing_dependencies: List[Tuple[str, str]] = []

for dependency in all_dependencies:
tag_to_check: str = config.get_dependency_tag(dependency.key)
is_installed = check_module_is_installed(dependency, tag_to_check)

if not is_installed:
missing_dependencies.append((dependency.key, tag_to_check))

if len(missing_dependencies):
raise errors.DependenciesMissing(missing_dependencies)
return
else:
module = dependencies.get_module_by_key(name)
tag_to_check: str = config.get_dependency_tag(module.key)

is_installed = check_module_is_installed(module, tag_to_check)
if is_installed and name != "rust":
logger.info(f"[{module.key} {tag_to_check}] is installed.")
return
elif not is_installed:
raise errors.DependencyMissing(module.key, tag_to_check)


def check_module_is_installed(module: DependencyModule, tag_to_check: str) -> bool:
resolution: str = config.get_dependency_resolution(module.key)
resolution = resolution if resolution else "HOST"

logger.info(f"Checking dependency: module = {module.key}, tag = {tag_to_check}, resolution = {resolution}")

installed = module.is_installed(tag_to_check)
if installed:
logger.info(f"[{name} {tag_to_check}] is installed.")
return

raise errors.DependencyMissing(name, tag_to_check)
return installed
45 changes: 4 additions & 41 deletions multiversx_sdk_cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
from pathlib import Path
from typing import Any, Dict, List

import semver

from multiversx_sdk_cli import errors, utils
from multiversx_sdk_cli.ux import show_warning

Expand Down Expand Up @@ -145,8 +143,7 @@ def _guard_valid_config_deletion(name: str):

def get_defaults() -> Dict[str, Any]:
return {
"dependencies.vmtools.tag": "v1.4.60",
"dependencies.mx_sdk_rs.tag": "latest",
"dependencies.vmtools.tag": "v1.5.24",
"dependencies.vmtools.urlTemplate.linux": "https://github.com/multiversx/mx-chain-vm-go/archive/{TAG}.tar.gz",
"dependencies.vmtools.urlTemplate.osx": "https://github.com/multiversx/mx-chain-vm-go/archive/{TAG}.tar.gz",
"dependencies.vmtools.urlTemplate.windows": "https://github.com/multiversx/mx-chain-vm-go/archive/{TAG}.tar.gz",
Expand All @@ -156,9 +153,9 @@ def get_defaults() -> Dict[str, Any]:
"dependencies.golang.urlTemplate.linux": "https://golang.org/dl/{TAG}.linux-amd64.tar.gz",
"dependencies.golang.urlTemplate.osx": "https://golang.org/dl/{TAG}.darwin-amd64.tar.gz",
"dependencies.golang.urlTemplate.windows": "https://golang.org/dl/{TAG}.windows-amd64.zip",
"dependencies.twiggy.tag": "latest",
"dependencies.sc-meta.tag": "latest",
"dependencies.testwallets.tag": "latest",
"dependencies.twiggy.tag": "",
"dependencies.sc-meta.tag": "",
"dependencies.testwallets.tag": "v1.0.0",
"dependencies.testwallets.urlTemplate.linux": "https://github.com/multiversx/mx-sdk-testwallets/archive/{TAG}.tar.gz",
"dependencies.testwallets.urlTemplate.osx": "https://github.com/multiversx/mx-sdk-testwallets/archive/{TAG}.tar.gz",
"dependencies.testwallets.urlTemplate.windows": "https://github.com/multiversx/mx-sdk-testwallets/archive/{TAG}.tar.gz",
Expand Down Expand Up @@ -254,42 +251,8 @@ def determine_final_args(argv: List[str], config_args: Dict[str, Any]) -> List[s

def get_dependency_directory(key: str, tag: str) -> Path:
parent_directory = get_dependency_parent_directory(key)
if tag == 'latest':
if not parent_directory.is_dir():
return parent_directory / tag
tag = get_latest_semver_from_directory(parent_directory)

return parent_directory / tag


def get_dependency_parent_directory(key: str) -> Path:
return SDK_PATH / key


def get_latest_semver_from_directory(directory: Path) -> str:
subdirs = [subdir.name for subdir in directory.iterdir()]
try:
return get_latest_semver(subdirs)
except IndexError:
raise Exception(f'no versions found in {directory}')


def get_latest_semver(versions: List[str]) -> str:
semantic_versions = parse_strings_to_semver(versions)
latest_version = sorted(semantic_versions).pop()
return 'v' + str(latest_version)


def parse_strings_to_semver(version_strings: List[str]) -> List[semver.VersionInfo]:
versions = []
for version_string in version_strings:
try:
# Omit the 'v' prefix of the version string
version_string = version_string[1:]
version = semver.VersionInfo.parse(version_string)
except ValueError:
continue

versions.append(version)

return versions

0 comments on commit 7d110d2

Please sign in to comment.