diff --git a/multiversx_sdk_cli/accounts.py b/multiversx_sdk_cli/accounts.py index 489f03a7..33616067 100644 --- a/multiversx_sdk_cli/accounts.py +++ b/multiversx_sdk_cli/accounts.py @@ -6,7 +6,7 @@ TransactionComputer, UserSigner) from multiversx_sdk.network_providers.accounts import AccountOnNetwork -from multiversx_sdk_cli.constants import DEFAULT_HRP +from multiversx_sdk_cli.config import get_address_hrp from multiversx_sdk_cli.interfaces import IAccount, IAddress, ITransaction from multiversx_sdk_cli.ledger.config import compare_versions from multiversx_sdk_cli.ledger.ledger_app_handler import \ @@ -61,11 +61,11 @@ def __init__(self, if pem_file: pem_path = Path(pem_file).expanduser().resolve() self.signer = UserSigner.from_pem_file(pem_path, pem_index) - self.address = Address(self.signer.get_pubkey().buffer, DEFAULT_HRP) + self.address = Address(self.signer.get_pubkey().buffer, get_address_hrp()) elif key_file and password: key_file_path = Path(key_file).expanduser().resolve() self.signer = UserSigner.from_wallet(key_file_path, password) - self.address = Address(self.signer.get_pubkey().buffer, DEFAULT_HRP) + self.address = Address(self.signer.get_pubkey().buffer, get_address_hrp()) def sign_transaction(self, transaction: ITransaction) -> str: assert self.signer is not None diff --git a/multiversx_sdk_cli/cli.py b/multiversx_sdk_cli/cli.py index 79eacf20..76fe95e1 100644 --- a/multiversx_sdk_cli/cli.py +++ b/multiversx_sdk_cli/cli.py @@ -6,6 +6,7 @@ from typing import Any, List import argcomplete +from multiversx_sdk import LibraryConfig from rich.logging import RichHandler import multiversx_sdk_cli.cli_accounts @@ -53,6 +54,8 @@ def _do_main(cli_args: List[str]): logging.basicConfig(level="INFO", format='%(name)s: %(message)s', handlers=[RichHandler(show_time=False, rich_tracebacks=True)]) verify_deprecated_entries_in_config_file() + default_hrp = config.get_address_hrp() + LibraryConfig.default_address_hrp = default_hrp if not hasattr(args, "func"): parser.print_help() diff --git a/multiversx_sdk_cli/cli_dns.py b/multiversx_sdk_cli/cli_dns.py index 703f29a1..dbbc9c9b 100644 --- a/multiversx_sdk_cli/cli_dns.py +++ b/multiversx_sdk_cli/cli_dns.py @@ -1,11 +1,11 @@ from typing import Any, List -from multiversx_sdk import Address, ProxyNetworkProvider +from multiversx_sdk import ProxyNetworkProvider from prettytable import PrettyTable from multiversx_sdk_cli import cli_shared from multiversx_sdk_cli.config import get_config_for_network_providers -from multiversx_sdk_cli.constants import ADDRESS_ZERO_BECH32 +from multiversx_sdk_cli.constants import ADDRESS_ZERO_HEX from multiversx_sdk_cli.dns import (compute_dns_address_for_shard_id, dns_address_for_name, name_hash, register, registration_cost, resolve, validate_name, @@ -82,7 +82,7 @@ def dns_resolve(args: Any): config = get_config_for_network_providers() addr = resolve(args.name, ProxyNetworkProvider(url=args.proxy, config=config)) - if addr.to_hex() != Address.new_from_bech32(ADDRESS_ZERO_BECH32).to_hex(): + if addr.to_hex() != ADDRESS_ZERO_HEX: print(addr.to_bech32()) diff --git a/multiversx_sdk_cli/cli_wallet.py b/multiversx_sdk_cli/cli_wallet.py index eeae9ebb..1f8b2082 100644 --- a/multiversx_sdk_cli/cli_wallet.py +++ b/multiversx_sdk_cli/cli_wallet.py @@ -10,7 +10,8 @@ from multiversx_sdk.core.address import get_shard_of_pubkey from multiversx_sdk_cli import cli_shared, utils -from multiversx_sdk_cli.constants import DEFAULT_HRP, NUMBER_OF_SHARDS +from multiversx_sdk_cli.config import get_address_hrp +from multiversx_sdk_cli.constants import NUMBER_OF_SHARDS from multiversx_sdk_cli.errors import (BadUserInput, KnownError, WalletGenerationError) from multiversx_sdk_cli.sign_verify import SignedMessage, sign_message @@ -54,7 +55,7 @@ def setup_parser(args: List[str], subparsers: Any) -> Any: ) sub.add_argument("--format", choices=WALLET_FORMATS, help="the format of the generated wallet file (default: %(default)s)", default=None) sub.add_argument("--outfile", help="the output path and base file name for the generated wallet files (default: %(default)s)", type=str) - sub.add_argument("--address-hrp", help=f"the human-readable part of the address, when format is {WALLET_FORMAT_KEYSTORE_SECRET_KEY} or {WALLET_FORMAT_PEM} (default: %(default)s)", type=str, default=DEFAULT_HRP) + sub.add_argument("--address-hrp", help=f"the human-readable part of the address, when format is {WALLET_FORMAT_KEYSTORE_SECRET_KEY} or {WALLET_FORMAT_PEM} (default: %(default)s)", type=str, default=get_address_hrp()) sub.add_argument("--shard", type=int, help="the shard in which the address will be generated; (default: random)") sub.set_defaults(func=wallet_new) @@ -69,7 +70,7 @@ def setup_parser(args: List[str], subparsers: Any) -> Any: 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_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.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=get_address_hrp()) sub.set_defaults(func=convert_wallet) sub = cli_shared.add_command_subparser( @@ -82,6 +83,7 @@ def setup_parser(args: List[str], subparsers: Any) -> Any: group = sub.add_mutually_exclusive_group(required=True) group.add_argument("--encode", action="store_true", help="whether to encode") group.add_argument("--decode", action="store_true", help="whether to decode") + sub.add_argument("--hrp", type=str, help="the human readable part; only used for encoding to bech32 (default: %(default)s)", default=get_address_hrp()) sub.set_defaults(func=do_bech32) sub = cli_shared.add_command_subparser( @@ -288,7 +290,8 @@ def do_bech32(args: Any): value = args.value if encode: - address = Address.new_from_hex(value, DEFAULT_HRP) + hrp = args.hrp + address = Address.new_from_hex(value, hrp) result = address.to_bech32() else: address = Address.new_from_bech32(value) diff --git a/multiversx_sdk_cli/config.py b/multiversx_sdk_cli/config.py index db067f65..621ab5b1 100644 --- a/multiversx_sdk_cli/config.py +++ b/multiversx_sdk_cli/config.py @@ -60,6 +60,10 @@ def get_value(name: str) -> str: return value +def get_address_hrp(): + return get_value("default_address_hrp") + + def set_value(name: str, value: Any): _guard_valid_name(name) data = read_file() @@ -162,6 +166,7 @@ def get_defaults() -> Dict[str, Any]: "dependencies.testwallets.urlTemplate.windows": "https://github.com/multiversx/mx-sdk-testwallets/archive/{TAG}.tar.gz", "dependencies.wasm-opt.tag": "0.112.0", "github_api_token": "", + "default_address_hrp": "erd" } diff --git a/multiversx_sdk_cli/constants.py b/multiversx_sdk_cli/constants.py index fabd8809..0f0e0dbc 100644 --- a/multiversx_sdk_cli/constants.py +++ b/multiversx_sdk_cli/constants.py @@ -9,7 +9,6 @@ DEFAULT_TX_VERSION = 2 -DEFAULT_HRP = "erd" -ADDRESS_ZERO_BECH32 = "erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq6gq4hu" +ADDRESS_ZERO_HEX = "0000000000000000000000000000000000000000000000000000000000000000" NUMBER_OF_SHARDS = 3 diff --git a/multiversx_sdk_cli/contracts.py b/multiversx_sdk_cli/contracts.py index 98885dc4..5f8214b9 100644 --- a/multiversx_sdk_cli/contracts.py +++ b/multiversx_sdk_cli/contracts.py @@ -11,7 +11,7 @@ from multiversx_sdk_cli import errors from multiversx_sdk_cli.accounts import Account -from multiversx_sdk_cli.constants import DEFAULT_HRP +from multiversx_sdk_cli.config import get_address_hrp from multiversx_sdk_cli.interfaces import IAddress logger = logging.getLogger("contracts") @@ -211,7 +211,7 @@ def _prepare_args_for_factory(self, arguments: List[str]) -> List[Any]: args.append(self._hex_to_bytes(arg)) elif arg.isnumeric(): args.append(int(arg)) - elif arg.startswith(DEFAULT_HRP): + elif arg.startswith(get_address_hrp()): args.append(Address.new_from_bech32(arg)) elif arg.lower() == FALSE_STR_LOWER: args.append(False) @@ -253,7 +253,7 @@ def _to_hex(arg: str): if arg.isnumeric(): return _prepare_decimal(arg) - elif arg.startswith(DEFAULT_HRP): + elif arg.startswith(get_address_hrp()): addr = Address.from_bech32(arg) return _prepare_hexadecimal(f"{HEX_PREFIX}{addr.hex()}") elif arg.lower() == FALSE_STR_LOWER or arg.lower() == TRUE_STR_LOWER: diff --git a/multiversx_sdk_cli/dns.py b/multiversx_sdk_cli/dns.py index 114b1a11..61e387c4 100644 --- a/multiversx_sdk_cli/dns.py +++ b/multiversx_sdk_cli/dns.py @@ -6,7 +6,8 @@ from multiversx_sdk_cli import cli_shared, utils from multiversx_sdk_cli.accounts import Account -from multiversx_sdk_cli.constants import ADDRESS_ZERO_BECH32, DEFAULT_HRP +from multiversx_sdk_cli.config import get_address_hrp +from multiversx_sdk_cli.constants import ADDRESS_ZERO_HEX from multiversx_sdk_cli.contracts import SmartContract from multiversx_sdk_cli.transactions import (compute_relayed_v1_data, do_prepare_transaction) @@ -36,10 +37,10 @@ def resolve(name: str, proxy: INetworkProvider) -> Address: ) if len(response) == 0: - return Address.from_bech32(ADDRESS_ZERO_BECH32) + return Address.new_from_hex(ADDRESS_ZERO_HEX, get_address_hrp()) result = response[0].get("returnDataParts")[0] - return Address.from_hex(result, DEFAULT_HRP) + return Address.new_from_hex(result, get_address_hrp()) def validate_name(name: str, shard_id: int, proxy: INetworkProvider): @@ -137,7 +138,7 @@ def compute_dns_address_for_shard_id(shard_id: int) -> Address: deployer_pubkey_prefix = InitialDNSAddress[:len(InitialDNSAddress) - ShardIdentiferLen] deployer_pubkey = deployer_pubkey_prefix + bytes([0, shard_id]) - deployer = Account(address=Address(deployer_pubkey, DEFAULT_HRP)) + deployer = Account(address=Address(deployer_pubkey, get_address_hrp())) deployer.nonce = 0 address_computer = AddressComputer(number_of_shards=3) contract_address = address_computer.compute_contract_address(deployer.address, deployer.nonce) diff --git a/multiversx_sdk_cli/sign_verify.py b/multiversx_sdk_cli/sign_verify.py index 09b45a55..77e4c77e 100644 --- a/multiversx_sdk_cli/sign_verify.py +++ b/multiversx_sdk_cli/sign_verify.py @@ -23,7 +23,7 @@ def verify_signature(self) -> bool: verifiable_message.signature = bytes.fromhex(self.signature) message_computer = MessageComputer() - verifier = UserVerifier.from_address(Address.from_bech32(self.address)) + verifier = UserVerifier.from_address(Address.new_from_bech32(self.address)) is_signed = verifier.verify(message_computer.compute_bytes_for_signing(verifiable_message), verifiable_message.signature) return is_signed @@ -37,4 +37,4 @@ def to_dictionary(self) -> Dict[str, str]: def sign_message(message: str, account: Account) -> SignedMessage: signature = account.sign_message(message.encode()) - return SignedMessage(account.address.bech32(), message, signature) + return SignedMessage(account.address.to_bech32(), message, signature) diff --git a/multiversx_sdk_cli/transactions.py b/multiversx_sdk_cli/transactions.py index 41937a50..91c0ae0a 100644 --- a/multiversx_sdk_cli/transactions.py +++ b/multiversx_sdk_cli/transactions.py @@ -136,7 +136,7 @@ def get_guardian_account_from_args(args: Any): account = Account(key_file=args.guardian_keyfile, password=password) elif args.guardian_ledger: address = do_get_ledger_address(account_index=args.guardian_ledger_account_index, address_index=args.guardian_ledger_address_index) - account = Account(address=Address.from_bech32(address)) + account = Account(address=Address.new_from_bech32(address)) else: raise errors.NoWalletProvided() diff --git a/pyproject.toml b/pyproject.toml index aa46997b..0002f4ee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "multiversx-sdk-cli" -version = "9.8.1" +version = "9.9.0" authors = [ { name="MultiversX" }, ] @@ -28,7 +28,7 @@ dependencies = [ "requests-cache", "rich==13.3.4", "argcomplete==3.2.2", - "multiversx-sdk==0.16.3" + "multiversx-sdk==0.19.0" ] [project.scripts] diff --git a/requirements.txt b/requirements.txt index 46320488..0c7334d0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,4 @@ requests-cache rich==13.3.4 argcomplete==3.2.2 -multiversx-sdk==0.16.3 +multiversx-sdk==0.19.0