From 77963322979ff29b4528696247692aad68f2bd7a Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Wed, 9 Apr 2025 10:23:52 +0300 Subject: [PATCH 1/4] fix displaying tx on network --- multiversx_sdk_cli/cli_output.py | 6 ++-- multiversx_sdk_cli/transactions.py | 58 +----------------------------- pyproject.toml | 2 +- 3 files changed, 5 insertions(+), 61 deletions(-) diff --git a/multiversx_sdk_cli/cli_output.py b/multiversx_sdk_cli/cli_output.py index 2250f489..84f02aee 100644 --- a/multiversx_sdk_cli/cli_output.py +++ b/multiversx_sdk_cli/cli_output.py @@ -6,7 +6,6 @@ from multiversx_sdk import Address, Transaction, TransactionOnNetwork from multiversx_sdk_cli import utils -from multiversx_sdk_cli.transactions import transaction_on_network_to_dictionary from multiversx_sdk_cli.utils import ISerializable logger = logging.getLogger("cli.output") @@ -36,7 +35,8 @@ def set_contract_address(self, contract_address: Address): return self def set_awaited_transaction(self, awaited_transaction: TransactionOnNetwork, omitted_fields: list[str] = []): - return self.set_transaction_on_network(awaited_transaction, omitted_fields) + self.set_transaction_on_network(awaited_transaction, omitted_fields) + self.set_emitted_transaction_hash(awaited_transaction.hash.hex()) def set_transaction_on_network( self, @@ -69,7 +69,7 @@ def build(self) -> dict[str, Any]: output["contractAddress"] = contract_address if self.transaction_on_network: - transaction_on_network_dict = transaction_on_network_to_dictionary(self.transaction_on_network) + transaction_on_network_dict = self.transaction_on_network.raw utils.omit_fields(transaction_on_network_dict, self.transaction_on_network_omitted_fields) output["transactionOnNetwork"] = transaction_on_network_dict diff --git a/multiversx_sdk_cli/transactions.py b/multiversx_sdk_cli/transactions.py index 0d8d9772..40074518 100644 --- a/multiversx_sdk_cli/transactions.py +++ b/multiversx_sdk_cli/transactions.py @@ -1,15 +1,12 @@ import json import logging -from typing import Any, Optional, Protocol, TextIO, Union +from typing import Optional, Protocol, TextIO, Union from multiversx_sdk import ( Address, AwaitingOptions, - SmartContractResult, TokenTransfer, Transaction, - TransactionEvent, - TransactionLogs, TransactionOnNetwork, TransactionsFactoryConfig, TransferTransactionsFactory, @@ -116,56 +113,3 @@ def load_transaction_from_file(f: TextIO) -> Transaction: data_json: bytes = f.read().encode() transaction_dictionary = json.loads(data_json).get("tx") or json.loads(data_json).get("emittedTransaction") return Transaction.new_from_dictionary(transaction_dictionary) - - -def transaction_event_to_dictionary(event: TransactionEvent) -> dict[str, Any]: - return { - "address": event.address.to_bech32(), - "identifier": event.identifier, - "topics": [topic.hex() for topic in event.topics], - "data": event.data.decode(), - "additional_data": [data.hex() for data in event.additional_data], - } - - -def transaction_logs_to_dictionary(logs: TransactionLogs) -> dict[str, Any]: - return { - "address": logs.address.to_bech32(), - "events": [transaction_event_to_dictionary(event) for event in logs.events], - } - - -def smart_contract_result_to_dictionary(result: SmartContractResult) -> dict[str, Any]: - return { - "sender": result.sender.to_bech32(), - "receiver": result.receiver.to_bech32(), - "data": result.data.decode(), - "logs": transaction_logs_to_dictionary(result.logs), - } - - -def transaction_on_network_to_dictionary(tx: TransactionOnNetwork) -> dict[str, Any]: - return { - "sender": tx.sender.to_bech32(), - "receiver": tx.receiver.to_bech32(), - "hash": tx.hash.hex(), - "nonce": tx.nonce, - "round": tx.round, - "epoch": tx.epoch, - "timestamp": tx.timestamp, - "blockHash": tx.block_hash.hex(), - "miniBlockHash": tx.miniblock_hash.hex(), - "senderShard": tx.sender_shard, - "receiverShard": tx.receiver_shard, - "value": tx.value, - "gasLimit": tx.gas_limit, - "gasPrice": tx.gas_price, - "function": tx.function, - "data": tx.data.decode(), - "version": tx.version, - "options": tx.options, - "signature": tx.signature.hex(), - "status": tx.status.status, - "smartContractResults": [smart_contract_result_to_dictionary(res) for res in tx.smart_contract_results], - "logs": transaction_logs_to_dictionary(tx.logs), - } diff --git a/pyproject.toml b/pyproject.toml index b911b8cc..7b925fc9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "multiversx-sdk-cli" -version = "10.1.0" +version = "10.1.1" authors = [ { name="MultiversX" }, ] From 15211e497e4e0df6bb4494c777370a0a082e285e Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Mon, 28 Apr 2025 16:36:16 +0300 Subject: [PATCH 2/4] add command to unverify smart contract --- CLI.md | 41 ++++++++++++++++++++- multiversx_sdk_cli/cli_contracts.py | 55 +++++++++++++++++++++++++++++ pyproject.toml | 2 +- 3 files changed, 96 insertions(+), 2 deletions(-) diff --git a/CLI.md b/CLI.md index 9c8e9845..79de3032 100644 --- a/CLI.md +++ b/CLI.md @@ -58,7 +58,7 @@ usage: mxpy contract COMMAND [-h] ... Deploy, upgrade and interact with Smart Contracts COMMANDS: - {deploy,call,upgrade,query,verify,reproducible-build,build} + {deploy,call,upgrade,query,verify,unverify,reproducible-build,build} OPTIONS: -h, --help show this help message and exit @@ -71,6 +71,7 @@ call Interact with a Smart Contract (execute function) upgrade Upgrade a previously-deployed Smart Contract. query Query a Smart Contract (call a pure function) verify Verify the authenticity of the code of a deployed Smart Contract +unverify Unverify a previously verified Smart Contract reproducible-build Build a Smart Contract and get the same output as a previously built Smart Contract build Build a Smart Contract project. This command is DISABLED. @@ -129,6 +130,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --proxy PROXY 🔗 the URL of the proxy --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. @@ -222,6 +224,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --proxy PROXY 🔗 the URL of the proxy --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. @@ -325,6 +328,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --proxy PROXY 🔗 the URL of the proxy --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. @@ -416,6 +420,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation ``` ### Contract.ReproducibleBuild @@ -504,6 +509,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. --recall-nonce ⭮ whether to recall the nonce when creating the transaction (default: @@ -610,6 +616,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --infile INFILE input file (a previously saved transaction) --outfile OUTFILE where to save the output (the signed transaction) (default: stdout) --send ✓ whether to broadcast the transaction (default: False) @@ -724,6 +731,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. --recall-nonce ⭮ whether to recall the nonce when creating the transaction (default: @@ -780,6 +788,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. --recall-nonce ⭮ whether to recall the nonce when creating the transaction (default: @@ -834,6 +843,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. --recall-nonce ⭮ whether to recall the nonce when creating the transaction (default: @@ -888,6 +898,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. --recall-nonce ⭮ whether to recall the nonce when creating the transaction (default: @@ -942,6 +953,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. --recall-nonce ⭮ whether to recall the nonce when creating the transaction (default: @@ -996,6 +1008,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. --recall-nonce ⭮ whether to recall the nonce when creating the transaction (default: @@ -1049,6 +1062,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. --recall-nonce ⭮ whether to recall the nonce when creating the transaction (default: @@ -1103,6 +1117,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. --recall-nonce ⭮ whether to recall the nonce when creating the transaction (default: @@ -1157,6 +1172,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. --recall-nonce ⭮ whether to recall the nonce when creating the transaction (default: @@ -1211,6 +1227,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. --recall-nonce ⭮ whether to recall the nonce when creating the transaction (default: @@ -1265,6 +1282,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. --recall-nonce ⭮ whether to recall the nonce when creating the transaction (default: @@ -1318,6 +1336,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. --recall-nonce ⭮ whether to recall the nonce when creating the transaction (default: @@ -1411,6 +1430,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. --recall-nonce ⭮ whether to recall the nonce when creating the transaction (default: @@ -1483,6 +1503,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. --recall-nonce ⭮ whether to recall the nonce when creating the transaction (default: @@ -1539,6 +1560,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. --recall-nonce ⭮ whether to recall the nonce when creating the transaction (default: @@ -1595,6 +1617,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. --recall-nonce ⭮ whether to recall the nonce when creating the transaction (default: @@ -1651,6 +1674,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. --recall-nonce ⭮ whether to recall the nonce when creating the transaction (default: @@ -1707,6 +1731,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. --recall-nonce ⭮ whether to recall the nonce when creating the transaction (default: @@ -1763,6 +1788,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. --recall-nonce ⭮ whether to recall the nonce when creating the transaction (default: @@ -1817,6 +1843,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. --recall-nonce ⭮ whether to recall the nonce when creating the transaction (default: @@ -1871,6 +1898,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. --recall-nonce ⭮ whether to recall the nonce when creating the transaction (default: @@ -1925,6 +1953,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. --recall-nonce ⭮ whether to recall the nonce when creating the transaction (default: @@ -1979,6 +2008,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. --recall-nonce ⭮ whether to recall the nonce when creating the transaction (default: @@ -2033,6 +2063,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. --recall-nonce ⭮ whether to recall the nonce when creating the transaction (default: @@ -2088,6 +2119,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. --recall-nonce ⭮ whether to recall the nonce when creating the transaction (default: @@ -2143,6 +2175,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. --recall-nonce ⭮ whether to recall the nonce when creating the transaction (default: @@ -2199,6 +2232,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. --recall-nonce ⭮ whether to recall the nonce when creating the transaction (default: @@ -2255,6 +2289,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. --recall-nonce ⭮ whether to recall the nonce when creating the transaction (default: @@ -2312,6 +2347,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. --recall-nonce ⭮ whether to recall the nonce when creating the transaction (default: @@ -2369,6 +2405,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --nonce NONCE # the nonce for the transaction. If not provided, is fetched from the network. --recall-nonce ⭮ whether to recall the nonce when creating the transaction (default: @@ -2510,6 +2547,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation ``` ### Wallet.VerifyMessage @@ -3030,6 +3068,7 @@ options: --sender-wallet-index SENDER_WALLET_INDEX 🔑 the address index; can be used for PEM files, keyfiles of type mnemonic or Ledger devices (default: 0) --sender-username SENDER_USERNAME 🖄 the username of the sender + --hrp HRP The hrp used to convert the address to its bech32 representation --chain {D,T} the chain identifier --api API custom api url for the native auth client --wallet-url WALLET_URL custom wallet url to call the faucet from diff --git a/multiversx_sdk_cli/cli_contracts.py b/multiversx_sdk_cli/cli_contracts.py index cb9df27c..e192baa6 100644 --- a/multiversx_sdk_cli/cli_contracts.py +++ b/multiversx_sdk_cli/cli_contracts.py @@ -4,9 +4,11 @@ from pathlib import Path from typing import Any +import requests from multiversx_sdk import ( Address, AddressComputer, + Message, ProxyNetworkProvider, Transaction, TransactionsFactoryConfig, @@ -179,6 +181,27 @@ def setup_parser(args: list[str], subparsers: Any) -> Any: cli_shared.add_wallet_args(args, sub) sub.set_defaults(func=verify) + sub = cli_shared.add_command_subparser( + subparsers, + "contract", + "unverify", + "Unverify a previously verified Smart Contract", + ) + + _add_contract_arg(sub) + sub.add_argument( + "--code-hash", + required=True, + help="the code hash of the contract", + ) + sub.add_argument( + "--verifier-url", + required=True, + help="the url of the service that validates the contract", + ) + cli_shared.add_wallet_args(args, sub) + sub.set_defaults(func=unverify) + sub = cli_shared.add_command_subparser( subparsers, "contract", @@ -524,6 +547,13 @@ def _send_or_simulate(tx: Transaction, contract_address: Address, args: Any): def verify(args: Any) -> None: + response = input( + "Are you sure you want to verify the contract? This will publish the contract's source code, which will be displayed on the MultiversX Explorer (y/n): " + ) + if response.lower() != "y": + logger.info("Contract verification cancelled.") + return + contract = Address.new_from_bech32(args.contract) verifier_url = args.verifier_url @@ -537,6 +567,31 @@ def verify(args: Any) -> None: logger.info("Contract verification request completed!") +def unverify(args: Any) -> None: + account = cli_shared.prepare_account(args) + contract = args.contract + code_hash = args.code_hash + verifier_url = f"{args.verifier_url}/verifier" + + payload = { + "contract": contract, + "codeHash": code_hash, + } + + payload_json = json.dumps(payload, separators=(",", ":")) + message = Message(payload_json.encode()) + signature = account.sign_message(message) + + request_payload = { + "signature": signature.hex(), + "payload": payload_json, + } + + response = requests.delete(verifier_url, json=request_payload) + logger.info(f"Your request to unverify contract {contract} was submitted.") + print(response.json().get("message")) + + def do_reproducible_build(args: Any): project_path = args.project docker_image = args.docker_image diff --git a/pyproject.toml b/pyproject.toml index 7b925fc9..a7b38afc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "multiversx-sdk-cli" -version = "10.1.1" +version = "10.2.0" authors = [ { name="MultiversX" }, ] From 65a76dd0b872fa7b924639adaee70903b1d2da2f Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Tue, 29 Apr 2025 14:09:35 +0300 Subject: [PATCH 3/4] fix for unverify contract --- multiversx_sdk_cli/cli_contracts.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/multiversx_sdk_cli/cli_contracts.py b/multiversx_sdk_cli/cli_contracts.py index e192baa6..f79dfe48 100644 --- a/multiversx_sdk_cli/cli_contracts.py +++ b/multiversx_sdk_cli/cli_contracts.py @@ -1,3 +1,4 @@ +import hashlib import json import logging import os @@ -569,25 +570,28 @@ def verify(args: Any) -> None: def unverify(args: Any) -> None: account = cli_shared.prepare_account(args) - contract = args.contract - code_hash = args.code_hash - verifier_url = f"{args.verifier_url}/verifier" + contract: str = args.contract + code_hash: str = args.code_hash + verifier_url: str = f"{args.verifier_url}/verifier" payload = { "contract": contract, "codeHash": code_hash, } - payload_json = json.dumps(payload, separators=(",", ":")) - message = Message(payload_json.encode()) - signature = account.sign_message(message) + serialized_payload = json.dumps(payload, separators=(",", ":")).encode("utf-8") + hash = hashlib.sha256(serialized_payload).hexdigest() + message_to_sign = (contract + hash).encode("utf-8") + + signature = account.sign_message(Message(message_to_sign)) request_payload = { "signature": signature.hex(), - "payload": payload_json, + "payload": payload, } - response = requests.delete(verifier_url, json=request_payload) + headers = {"Content-type": "application/json"} + response = requests.delete(verifier_url, json=request_payload, headers=headers) logger.info(f"Your request to unverify contract {contract} was submitted.") print(response.json().get("message")) From 352900ac4565fa933448a2e6c07025705b44fe36 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Tue, 29 Apr 2025 15:00:35 +0300 Subject: [PATCH 4/4] add args to skip confirmation prompt --- multiversx_sdk_cli/cli_contracts.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/multiversx_sdk_cli/cli_contracts.py b/multiversx_sdk_cli/cli_contracts.py index f79dfe48..7ad92e1f 100644 --- a/multiversx_sdk_cli/cli_contracts.py +++ b/multiversx_sdk_cli/cli_contracts.py @@ -180,6 +180,14 @@ def setup_parser(args: list[str], subparsers: Any) -> Any: help="in case of a multicontract, specify the contract variant you want to verify", ) cli_shared.add_wallet_args(args, sub) + sub.add_argument( + "--skip-confirmation", + "-y", + dest="skip_confirmation", + action="store_true", + default=False, + help="can be used to skip the confirmation prompt", + ) sub.set_defaults(func=verify) sub = cli_shared.add_command_subparser( @@ -548,12 +556,13 @@ def _send_or_simulate(tx: Transaction, contract_address: Address, args: Any): def verify(args: Any) -> None: - response = input( - "Are you sure you want to verify the contract? This will publish the contract's source code, which will be displayed on the MultiversX Explorer (y/n): " - ) - if response.lower() != "y": - logger.info("Contract verification cancelled.") - return + if not args.skip_confirmation: + response = input( + "Are you sure you want to verify the contract? This will publish the contract's source code, which will be displayed on the MultiversX Explorer (y/n): " + ) + if response.lower() != "y": + logger.info("Contract verification cancelled.") + return contract = Address.new_from_bech32(args.contract) verifier_url = args.verifier_url