Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge main in feat/next #341

Merged
merged 20 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion multiversx_sdk_cli/cli_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
11 changes: 10 additions & 1 deletion multiversx_sdk_cli/cli_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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

Expand Down
24 changes: 23 additions & 1 deletion multiversx_sdk_cli/cli_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@
WALLET_FORMAT_KEYSTORE_MNEMONIC = "keystore-mnemonic"
WALLET_FORMAT_KEYSTORE_SECRET_KEY = "keystore-secret-key"
WALLET_FORMAT_PEM = "pem"
WALLET_FORMAT_ADDRESS_BECH32 = "address-bech32"
WALLET_FORMAT_ADDRESS_HEX = "address-hex"

WALLET_FORMATS = [
WALLET_FORMAT_RAW_MNEMONIC,
WALLET_FORMAT_KEYSTORE_MNEMONIC,
WALLET_FORMAT_KEYSTORE_SECRET_KEY,
WALLET_FORMAT_PEM,
]

WALLET_FORMATS_AND_ADDRESSES = [*WALLET_FORMATS, WALLET_FORMAT_ADDRESS_BECH32, WALLET_FORMAT_ADDRESS_HEX]


def setup_parser(args: List[str], subparsers: Any) -> Any:
parser = cli_shared.add_group_subparser(
Expand Down Expand Up @@ -56,7 +61,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)
Expand Down Expand Up @@ -209,6 +214,23 @@ def _create_wallet_content(
pem = UserPEM(address.bech32(), secret_key)
return pem.to_text()

if out_format == WALLET_FORMAT_ADDRESS_BECH32:
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_ADDRESS_HEX:
if mnemonic:
secret_key = mnemonic.derive_key(address_index)
assert secret_key is not None

pubkey = secret_key.generate_public_key()
return pubkey.hex()

raise KnownError(f"Cannot create wallet, unknown output format: <{out_format}>. Make sure to use one of following: {WALLET_FORMATS}.")


Expand Down
2 changes: 1 addition & 1 deletion multiversx_sdk_cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": "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",
Expand Down
22 changes: 22 additions & 0 deletions multiversx_sdk_cli/tests/test_cli_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "address-bech32"
])

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", "address-hex"
])

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()

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "multiversx-sdk-cli"
version = "8.0.0"
version = "8.1.2"
authors = [
{ name="MultiversX" },
]
Expand Down
Loading