From 31473356affb8d33b489c298c322958f2bacc822 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Wed, 6 Sep 2023 17:49:45 +0300 Subject: [PATCH 01/13] convert from wallet to bech32 address or pubkey --- multiversx_sdk_cli/cli_wallet.py | 27 ++++++++++++++++++++- multiversx_sdk_cli/tests/test_cli_wallet.py | 22 +++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/multiversx_sdk_cli/cli_wallet.py b/multiversx_sdk_cli/cli_wallet.py index 523f8159..97b8a934 100644 --- a/multiversx_sdk_cli/cli_wallet.py +++ b/multiversx_sdk_cli/cli_wallet.py @@ -20,6 +20,9 @@ WALLET_FORMAT_KEYSTORE_MNEMONIC = "keystore-mnemonic" WALLET_FORMAT_KEYSTORE_SECRET_KEY = "keystore-secret-key" WALLET_FORMAT_PEM = "pem" +WALLET_FORMAT_BECH32_ADDRESS = "bech32_address" +WALLET_FORMAT_PUBLIC_KEY = "public_key" + WALLET_FORMATS = [ WALLET_FORMAT_RAW_MNEMONIC, WALLET_FORMAT_KEYSTORE_MNEMONIC, @@ -27,6 +30,10 @@ WALLET_FORMAT_PEM, ] +WALLET_FORMATS_AND_ADDRESSES: List[str] = [] +WALLET_FORMATS_AND_ADDRESSES.extend(WALLET_FORMATS) +WALLET_FORMATS_AND_ADDRESSES.extend([WALLET_FORMAT_BECH32_ADDRESS, WALLET_FORMAT_PUBLIC_KEY]) + def setup_parser(args: List[str], subparsers: Any) -> Any: parser = cli_shared.add_group_subparser( @@ -56,7 +63,7 @@ def setup_parser(args: List[str], subparsers: Any) -> Any: sub.add_argument("--infile", help="path to the input file") sub.add_argument("--outfile", help="path to the output file") sub.add_argument("--in-format", required=True, choices=WALLET_FORMATS, help="the format of the input file") - sub.add_argument("--out-format", required=True, choices=WALLET_FORMATS, help="the format of the output file") + sub.add_argument("--out-format", required=True, choices=WALLET_FORMATS_AND_ADDRESSES, help="the format of the output file") sub.add_argument("--address-index", help=f"the address index, if input format is {WALLET_FORMAT_RAW_MNEMONIC}, {WALLET_FORMAT_KEYSTORE_MNEMONIC} or {WALLET_FORMAT_PEM} (with multiple entries) and the output format is {WALLET_FORMAT_KEYSTORE_SECRET_KEY} or {WALLET_FORMAT_PEM}", type=int, default=0) sub.add_argument("--address-hrp", help=f"the human-readable part of the address, when the output format is {WALLET_FORMAT_KEYSTORE_SECRET_KEY} or {WALLET_FORMAT_PEM} (default: %(default)s)", type=str, default=DEFAULT_HRP) sub.set_defaults(func=convert_wallet) @@ -209,6 +216,24 @@ def _create_wallet_content( pem = UserPEM(address.bech32(), secret_key) return pem.to_text() + if out_format == WALLET_FORMAT_BECH32_ADDRESS: + if mnemonic: + secret_key = mnemonic.derive_key(address_index) + assert secret_key is not None + + pubkey = secret_key.generate_public_key() + address = pubkey.to_address(address_hrp) + return address.bech32() + + if out_format == WALLET_FORMAT_PUBLIC_KEY: + if mnemonic: + secret_key = mnemonic.derive_key(address_index) + assert secret_key is not None + + pubkey = secret_key.generate_public_key() + address = pubkey.to_address(address_hrp) + return address.hex() # type: ignore + raise KnownError(f"Cannot create wallet, unknown output format: <{out_format}>. Make sure to use one of following: {WALLET_FORMATS}.") diff --git a/multiversx_sdk_cli/tests/test_cli_wallet.py b/multiversx_sdk_cli/tests/test_cli_wallet.py index 86b29ba4..a73cc572 100644 --- a/multiversx_sdk_cli/tests/test_cli_wallet.py +++ b/multiversx_sdk_cli/tests/test_cli_wallet.py @@ -217,6 +217,28 @@ def test_wallet_bech32_decode(capsys: Any): assert out == "0139472eff6886771a982f3083da5d421f24c29181e63888228dc81ca60d69e1" +def test_wallet_convert_pem_to_bech32_address(capsys: Any): + infile = testdata_path / "alice.pem" + + main([ + "wallet", "convert", "--infile", str(infile), "--in-format", "pem", "--out-format", "bech32_address" + ]) + + out = _read_stdout(capsys).strip("Output:\n\n") + assert out == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + + +def test_wallet_convert_pem_to_pubkey(capsys: Any): + infile = testdata_path / "alice.pem" + + main([ + "wallet", "convert", "--infile", str(infile), "--in-format", "pem", "--out-format", "public_key" + ]) + + out = _read_stdout(capsys).strip("Output:\n\n") + assert out == "0139472eff6886771a982f3083da5d421f24c29181e63888228dc81ca60d69e1" + + def _read_stdout_mnemonic(capsys: Any) -> str: return _read_stdout(capsys).replace("Mnemonic:", "").strip() From 4ebb173c2f2de24fd2330b33b79afb45aa2412e9 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Thu, 7 Sep 2023 10:04:19 +0300 Subject: [PATCH 02/13] keep wallet format consistent --- multiversx_sdk_cli/cli_wallet.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/multiversx_sdk_cli/cli_wallet.py b/multiversx_sdk_cli/cli_wallet.py index 97b8a934..b598eade 100644 --- a/multiversx_sdk_cli/cli_wallet.py +++ b/multiversx_sdk_cli/cli_wallet.py @@ -20,8 +20,8 @@ WALLET_FORMAT_KEYSTORE_MNEMONIC = "keystore-mnemonic" WALLET_FORMAT_KEYSTORE_SECRET_KEY = "keystore-secret-key" WALLET_FORMAT_PEM = "pem" -WALLET_FORMAT_BECH32_ADDRESS = "bech32_address" -WALLET_FORMAT_PUBLIC_KEY = "public_key" +WALLET_FORMAT_BECH32_ADDRESS = "bech32-address" +WALLET_FORMAT_PUBLIC_KEY = "public-key" WALLET_FORMATS = [ WALLET_FORMAT_RAW_MNEMONIC, From 3ffd2ef94e889552bb83fd4bb3b0ccdcb70d748d Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Thu, 7 Sep 2023 10:05:01 +0300 Subject: [PATCH 03/13] fix unit tests --- multiversx_sdk_cli/tests/test_cli_wallet.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/multiversx_sdk_cli/tests/test_cli_wallet.py b/multiversx_sdk_cli/tests/test_cli_wallet.py index a73cc572..764319d2 100644 --- a/multiversx_sdk_cli/tests/test_cli_wallet.py +++ b/multiversx_sdk_cli/tests/test_cli_wallet.py @@ -221,7 +221,7 @@ def test_wallet_convert_pem_to_bech32_address(capsys: Any): infile = testdata_path / "alice.pem" main([ - "wallet", "convert", "--infile", str(infile), "--in-format", "pem", "--out-format", "bech32_address" + "wallet", "convert", "--infile", str(infile), "--in-format", "pem", "--out-format", "bech32-address" ]) out = _read_stdout(capsys).strip("Output:\n\n") @@ -232,7 +232,7 @@ def test_wallet_convert_pem_to_pubkey(capsys: Any): infile = testdata_path / "alice.pem" main([ - "wallet", "convert", "--infile", str(infile), "--in-format", "pem", "--out-format", "public_key" + "wallet", "convert", "--infile", str(infile), "--in-format", "pem", "--out-format", "public-key" ]) out = _read_stdout(capsys).strip("Output:\n\n") From 518c9aa100d31cd4a843fc3cbf5e60da684114f5 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Thu, 7 Sep 2023 10:23:00 +0300 Subject: [PATCH 04/13] fix after review --- multiversx_sdk_cli/cli_wallet.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/multiversx_sdk_cli/cli_wallet.py b/multiversx_sdk_cli/cli_wallet.py index b598eade..7df252a9 100644 --- a/multiversx_sdk_cli/cli_wallet.py +++ b/multiversx_sdk_cli/cli_wallet.py @@ -30,9 +30,7 @@ WALLET_FORMAT_PEM, ] -WALLET_FORMATS_AND_ADDRESSES: List[str] = [] -WALLET_FORMATS_AND_ADDRESSES.extend(WALLET_FORMATS) -WALLET_FORMATS_AND_ADDRESSES.extend([WALLET_FORMAT_BECH32_ADDRESS, WALLET_FORMAT_PUBLIC_KEY]) +WALLET_FORMATS_AND_ADDRESSES = [*WALLET_FORMATS, WALLET_FORMAT_BECH32_ADDRESS, WALLET_FORMAT_PUBLIC_KEY] def setup_parser(args: List[str], subparsers: Any) -> Any: @@ -231,8 +229,7 @@ def _create_wallet_content( assert secret_key is not None pubkey = secret_key.generate_public_key() - address = pubkey.to_address(address_hrp) - return address.hex() # type: ignore + return pubkey.hex() raise KnownError(f"Cannot create wallet, unknown output format: <{out_format}>. Make sure to use one of following: {WALLET_FORMATS}.") From 22b0ee945ddee41650cba730e416d55ea772bd71 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Thu, 7 Sep 2023 11:10:47 +0300 Subject: [PATCH 05/13] fix no wasm opt argument --- multiversx_sdk_cli/cli_contracts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multiversx_sdk_cli/cli_contracts.py b/multiversx_sdk_cli/cli_contracts.py index e36ad61e..987ce8de 100644 --- a/multiversx_sdk_cli/cli_contracts.py +++ b/multiversx_sdk_cli/cli_contracts.py @@ -463,7 +463,7 @@ def do_reproducible_build(args: Any): utils.ensure_folder(output_path) options = args.__dict__ - no_wasm_opt = options.get("no-wasm-opt", True) + no_wasm_opt = options.get("no_wasm_opt", True) if not is_docker_installed(): raise DockerMissingError() From 382ebf6dfef41599752ed33261fa39ee3a0c301a Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Thu, 7 Sep 2023 11:20:19 +0300 Subject: [PATCH 06/13] set no wasm opt on False by deafult --- multiversx_sdk_cli/cli_contracts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multiversx_sdk_cli/cli_contracts.py b/multiversx_sdk_cli/cli_contracts.py index 987ce8de..ebf431e4 100644 --- a/multiversx_sdk_cli/cli_contracts.py +++ b/multiversx_sdk_cli/cli_contracts.py @@ -463,7 +463,7 @@ def do_reproducible_build(args: Any): utils.ensure_folder(output_path) options = args.__dict__ - no_wasm_opt = options.get("no_wasm_opt", True) + no_wasm_opt = options.get("no_wasm_opt", False) if not is_docker_installed(): raise DockerMissingError() From 58e1dc21c4583f76a139834d6e3e0e1967ecaeb1 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Thu, 7 Sep 2023 11:32:12 +0300 Subject: [PATCH 07/13] fix after review --- multiversx_sdk_cli/cli_wallet.py | 10 +++++----- multiversx_sdk_cli/tests/test_cli_wallet.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/multiversx_sdk_cli/cli_wallet.py b/multiversx_sdk_cli/cli_wallet.py index 7df252a9..57bfbb6c 100644 --- a/multiversx_sdk_cli/cli_wallet.py +++ b/multiversx_sdk_cli/cli_wallet.py @@ -20,8 +20,8 @@ WALLET_FORMAT_KEYSTORE_MNEMONIC = "keystore-mnemonic" WALLET_FORMAT_KEYSTORE_SECRET_KEY = "keystore-secret-key" WALLET_FORMAT_PEM = "pem" -WALLET_FORMAT_BECH32_ADDRESS = "bech32-address" -WALLET_FORMAT_PUBLIC_KEY = "public-key" +WALLET_FORMAT_ADDRESS_BECH32 = "address-bech32" +WALLET_FORMAT_ADDRESS_HEX = "address-hex" WALLET_FORMATS = [ WALLET_FORMAT_RAW_MNEMONIC, @@ -30,7 +30,7 @@ WALLET_FORMAT_PEM, ] -WALLET_FORMATS_AND_ADDRESSES = [*WALLET_FORMATS, WALLET_FORMAT_BECH32_ADDRESS, WALLET_FORMAT_PUBLIC_KEY] +WALLET_FORMATS_AND_ADDRESSES = [*WALLET_FORMATS, WALLET_FORMAT_ADDRESS_BECH32, WALLET_FORMAT_ADDRESS_HEX] def setup_parser(args: List[str], subparsers: Any) -> Any: @@ -214,7 +214,7 @@ def _create_wallet_content( pem = UserPEM(address.bech32(), secret_key) return pem.to_text() - if out_format == WALLET_FORMAT_BECH32_ADDRESS: + if out_format == WALLET_FORMAT_ADDRESS_BECH32: if mnemonic: secret_key = mnemonic.derive_key(address_index) assert secret_key is not None @@ -223,7 +223,7 @@ def _create_wallet_content( address = pubkey.to_address(address_hrp) return address.bech32() - if out_format == WALLET_FORMAT_PUBLIC_KEY: + if out_format == WALLET_FORMAT_ADDRESS_HEX: if mnemonic: secret_key = mnemonic.derive_key(address_index) assert secret_key is not None diff --git a/multiversx_sdk_cli/tests/test_cli_wallet.py b/multiversx_sdk_cli/tests/test_cli_wallet.py index 764319d2..b6353fb7 100644 --- a/multiversx_sdk_cli/tests/test_cli_wallet.py +++ b/multiversx_sdk_cli/tests/test_cli_wallet.py @@ -221,7 +221,7 @@ def test_wallet_convert_pem_to_bech32_address(capsys: Any): infile = testdata_path / "alice.pem" main([ - "wallet", "convert", "--infile", str(infile), "--in-format", "pem", "--out-format", "bech32-address" + "wallet", "convert", "--infile", str(infile), "--in-format", "pem", "--out-format", "address-bech32" ]) out = _read_stdout(capsys).strip("Output:\n\n") @@ -232,7 +232,7 @@ def test_wallet_convert_pem_to_pubkey(capsys: Any): infile = testdata_path / "alice.pem" main([ - "wallet", "convert", "--infile", str(infile), "--in-format", "pem", "--out-format", "public-key" + "wallet", "convert", "--infile", str(infile), "--in-format", "pem", "--out-format", "address-hex" ]) out = _read_stdout(capsys).strip("Output:\n\n") From aac841f5f1640579f09b103f2466bf04ba4995a3 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Thu, 7 Sep 2023 12:01:04 +0300 Subject: [PATCH 08/13] bump version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 702b77e9..a464b548 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "multiversx-sdk-cli" -version = "8.0.0" +version = "8.1.0" authors = [ { name="MultiversX" }, ] From 2dacfcc0f74eb682ab05546cde6ae2cf749aad79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Sun, 17 Sep 2023 21:44:30 +0300 Subject: [PATCH 09/13] Adjust default vmtools version: 1.4.60. --- multiversx_sdk_cli/config.py | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/multiversx_sdk_cli/config.py b/multiversx_sdk_cli/config.py index 638a22e4..5f6bbe39 100644 --- a/multiversx_sdk_cli/config.py +++ b/multiversx_sdk_cli/config.py @@ -145,7 +145,7 @@ def _guard_valid_config_deletion(name: str): def get_defaults() -> Dict[str, Any]: return { - "dependencies.vmtools.tag": "latest", + "dependencies.vmtools.tag": "1.4.60", "dependencies.mx_sdk_rs.tag": "latest", "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", diff --git a/pyproject.toml b/pyproject.toml index a464b548..60739b90 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "multiversx-sdk-cli" -version = "8.1.0" +version = "8.1.1" authors = [ { name="MultiversX" }, ] From 8c31980d421b31700561547ec81c737a70919133 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Thu, 21 Sep 2023 13:39:39 +0300 Subject: [PATCH 10/13] Test with python 3.11, as well. --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 24757526..8dd1900f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,7 +17,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest] - python-version: [3.8] + python-version: [3.8, 3.11] steps: - uses: actions/checkout@v2 From 7fb38c11888399f975748ec001e4b4e5840491ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Thu, 21 Sep 2023 13:48:00 +0300 Subject: [PATCH 11/13] Fix tag for vmtools. --- multiversx_sdk_cli/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multiversx_sdk_cli/config.py b/multiversx_sdk_cli/config.py index 5f6bbe39..863e64f7 100644 --- a/multiversx_sdk_cli/config.py +++ b/multiversx_sdk_cli/config.py @@ -145,7 +145,7 @@ def _guard_valid_config_deletion(name: str): def get_defaults() -> Dict[str, Any]: return { - "dependencies.vmtools.tag": "1.4.60", + "dependencies.vmtools.tag": "v1.4.60", "dependencies.mx_sdk_rs.tag": "latest", "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", From 4aaf7ab6d20e119481cf89792ac05203fe510ec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Thu, 21 Sep 2023 13:49:42 +0300 Subject: [PATCH 12/13] Bump version. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 60739b90..b4476a0e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "multiversx-sdk-cli" -version = "8.1.1" +version = "8.1.2" authors = [ { name="MultiversX" }, ] From 476a99d85ad73b10e53d8b680dbff566d18dc259 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Mon, 25 Sep 2023 16:48:57 +0300 Subject: [PATCH 13/13] add link to transactions for mxpy output --- multiversx_sdk_cli/cli_shared.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/multiversx_sdk_cli/cli_shared.py b/multiversx_sdk_cli/cli_shared.py index 2438695e..75fa665d 100644 --- a/multiversx_sdk_cli/cli_shared.py +++ b/multiversx_sdk_cli/cli_shared.py @@ -21,6 +21,7 @@ from multiversx_sdk_cli.ledger.ledger_functions import do_get_ledger_address from multiversx_sdk_cli.simulation import Simulator from multiversx_sdk_cli.transactions import send_and_wait_for_result +from multiversx_sdk_cli.utils import log_explorer_transaction from multiversx_sdk_cli.ux import show_warning @@ -274,8 +275,16 @@ def send_or_simulate(tx: ITransaction, args: Any, dump_output: bool = True) -> C simulation = Simulator(proxy).run(tx) output_builder.set_simulation_results(simulation) finally: + output_transaction = output_builder.build() + if dump_output: - utils.dump_out_json(output_builder.build(), outfile=outfile) + utils.dump_out_json(output_transaction, outfile=outfile) + + if send_only: + log_explorer_transaction( + chain=output_transaction["emittedTransaction"]["chainID"], + transaction_hash=output_transaction["emittedTransactionHash"] + ) return output_builder