Skip to content

Commit 4fe058f

Browse files
authored
Merge pull request #524 from multiversx/merge-main-in-feat-05-06
Merge main in feat/next
2 parents 812c633 + 6e863ff commit 4fe058f

5 files changed

Lines changed: 75 additions & 62 deletions

File tree

CLI.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ usage: mxpy contract COMMAND [-h] ...
6060
Deploy, upgrade and interact with Smart Contracts
6161
6262
COMMANDS:
63-
{deploy,call,upgrade,query,verify,reproducible-build,build}
63+
{deploy,call,upgrade,query,verify,unverify,reproducible-build,build}
6464
6565
OPTIONS:
6666
-h, --help show this help message and exit
@@ -73,6 +73,7 @@ call Interact with a Smart Contract (execute function)
7373
upgrade Upgrade a previously-deployed Smart Contract.
7474
query Query a Smart Contract (call a pure function)
7575
verify Verify the authenticity of the code of a deployed Smart Contract
76+
unverify Unverify a previously verified Smart Contract
7677
reproducible-build Build a Smart Contract and get the same output as a previously built Smart Contract
7778
build Build a Smart Contract project. This command is DISABLED.
7879

multiversx_sdk_cli/cli_contracts.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
import hashlib
12
import json
23
import logging
34
import os
45
from pathlib import Path
56
from typing import Any
67

8+
import requests
79
from multiversx_sdk import (
810
Address,
911
AddressComputer,
12+
Message,
1013
ProxyNetworkProvider,
1114
Transaction,
1215
TransactionsFactoryConfig,
@@ -147,8 +150,37 @@ def setup_parser(args: list[str], subparsers: Any) -> Any:
147150
help="in case of a multicontract, specify the contract variant you want to verify",
148151
)
149152
cli_shared.add_wallet_args(args, sub)
153+
sub.add_argument(
154+
"--skip-confirmation",
155+
"-y",
156+
dest="skip_confirmation",
157+
action="store_true",
158+
default=False,
159+
help="can be used to skip the confirmation prompt",
160+
)
150161
sub.set_defaults(func=verify)
151162

163+
sub = cli_shared.add_command_subparser(
164+
subparsers,
165+
"contract",
166+
"unverify",
167+
"Unverify a previously verified Smart Contract",
168+
)
169+
170+
_add_contract_arg(sub)
171+
sub.add_argument(
172+
"--code-hash",
173+
required=True,
174+
help="the code hash of the contract",
175+
)
176+
sub.add_argument(
177+
"--verifier-url",
178+
required=True,
179+
help="the url of the service that validates the contract",
180+
)
181+
cli_shared.add_wallet_args(args, sub)
182+
sub.set_defaults(func=unverify)
183+
152184
sub = cli_shared.add_command_subparser(
153185
subparsers,
154186
"contract",
@@ -473,6 +505,14 @@ def _send_or_simulate(tx: Transaction, contract_address: Address, args: Any):
473505

474506

475507
def verify(args: Any) -> None:
508+
if not args.skip_confirmation:
509+
response = input(
510+
"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): "
511+
)
512+
if response.lower() != "y":
513+
logger.info("Contract verification cancelled.")
514+
return
515+
476516
contract = Address.new_from_bech32(args.contract)
477517
verifier_url = args.verifier_url
478518

@@ -486,6 +526,34 @@ def verify(args: Any) -> None:
486526
logger.info("Contract verification request completed!")
487527

488528

529+
def unverify(args: Any) -> None:
530+
account = cli_shared.prepare_account(args)
531+
contract: str = args.contract
532+
code_hash: str = args.code_hash
533+
verifier_url: str = f"{args.verifier_url}/verifier"
534+
535+
payload = {
536+
"contract": contract,
537+
"codeHash": code_hash,
538+
}
539+
540+
serialized_payload = json.dumps(payload, separators=(",", ":")).encode("utf-8")
541+
hash = hashlib.sha256(serialized_payload).hexdigest()
542+
message_to_sign = (contract + hash).encode("utf-8")
543+
544+
signature = account.sign_message(Message(message_to_sign))
545+
546+
request_payload = {
547+
"signature": signature.hex(),
548+
"payload": payload,
549+
}
550+
551+
headers = {"Content-type": "application/json"}
552+
response = requests.delete(verifier_url, json=request_payload, headers=headers)
553+
logger.info(f"Your request to unverify contract {contract} was submitted.")
554+
print(response.json().get("message"))
555+
556+
489557
def do_reproducible_build(args: Any):
490558
project_path = args.project
491559
docker_image = args.docker_image

multiversx_sdk_cli/cli_output.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from multiversx_sdk import Address, Transaction, TransactionOnNetwork
77

88
from multiversx_sdk_cli import utils
9-
from multiversx_sdk_cli.transactions import transaction_on_network_to_dictionary
109
from multiversx_sdk_cli.utils import ISerializable
1110

1211
logger = logging.getLogger("cli.output")
@@ -36,7 +35,8 @@ def set_contract_address(self, contract_address: Address):
3635
return self
3736

3837
def set_awaited_transaction(self, awaited_transaction: TransactionOnNetwork, omitted_fields: list[str] = []):
39-
return self.set_transaction_on_network(awaited_transaction, omitted_fields)
38+
self.set_transaction_on_network(awaited_transaction, omitted_fields)
39+
self.set_emitted_transaction_hash(awaited_transaction.hash.hex())
4040

4141
def set_transaction_on_network(
4242
self,
@@ -69,7 +69,7 @@ def build(self) -> dict[str, Any]:
6969
output["contractAddress"] = contract_address
7070

7171
if self.transaction_on_network:
72-
transaction_on_network_dict = transaction_on_network_to_dictionary(self.transaction_on_network)
72+
transaction_on_network_dict = self.transaction_on_network.raw
7373
utils.omit_fields(transaction_on_network_dict, self.transaction_on_network_omitted_fields)
7474
output["transactionOnNetwork"] = transaction_on_network_dict
7575

multiversx_sdk_cli/transactions.py

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import json
22
import logging
3-
from typing import Any, Optional, Protocol, TextIO, Union
3+
from typing import Optional, Protocol, TextIO, Union
44

55
from multiversx_sdk import (
66
Address,
77
AwaitingOptions,
8-
SmartContractResult,
98
TokenTransfer,
109
Transaction,
11-
TransactionEvent,
12-
TransactionLogs,
1310
TransactionOnNetwork,
1411
TransactionsFactoryConfig,
1512
TransferTransactionsFactory,
@@ -116,56 +113,3 @@ def load_transaction_from_file(f: TextIO) -> Transaction:
116113
data_json: bytes = f.read().encode()
117114
transaction_dictionary = json.loads(data_json).get("tx") or json.loads(data_json).get("emittedTransaction")
118115
return Transaction.new_from_dictionary(transaction_dictionary)
119-
120-
121-
def transaction_event_to_dictionary(event: TransactionEvent) -> dict[str, Any]:
122-
return {
123-
"address": event.address.to_bech32(),
124-
"identifier": event.identifier,
125-
"topics": [topic.hex() for topic in event.topics],
126-
"data": event.data.decode(),
127-
"additional_data": [data.hex() for data in event.additional_data],
128-
}
129-
130-
131-
def transaction_logs_to_dictionary(logs: TransactionLogs) -> dict[str, Any]:
132-
return {
133-
"address": logs.address.to_bech32(),
134-
"events": [transaction_event_to_dictionary(event) for event in logs.events],
135-
}
136-
137-
138-
def smart_contract_result_to_dictionary(result: SmartContractResult) -> dict[str, Any]:
139-
return {
140-
"sender": result.sender.to_bech32(),
141-
"receiver": result.receiver.to_bech32(),
142-
"data": result.data.decode(),
143-
"logs": transaction_logs_to_dictionary(result.logs),
144-
}
145-
146-
147-
def transaction_on_network_to_dictionary(tx: TransactionOnNetwork) -> dict[str, Any]:
148-
return {
149-
"sender": tx.sender.to_bech32(),
150-
"receiver": tx.receiver.to_bech32(),
151-
"hash": tx.hash.hex(),
152-
"nonce": tx.nonce,
153-
"round": tx.round,
154-
"epoch": tx.epoch,
155-
"timestamp": tx.timestamp,
156-
"blockHash": tx.block_hash.hex(),
157-
"miniBlockHash": tx.miniblock_hash.hex(),
158-
"senderShard": tx.sender_shard,
159-
"receiverShard": tx.receiver_shard,
160-
"value": tx.value,
161-
"gasLimit": tx.gas_limit,
162-
"gasPrice": tx.gas_price,
163-
"function": tx.function,
164-
"data": tx.data.decode(),
165-
"version": tx.version,
166-
"options": tx.options,
167-
"signature": tx.signature.hex(),
168-
"status": tx.status.status,
169-
"smartContractResults": [smart_contract_result_to_dictionary(res) for res in tx.smart_contract_results],
170-
"logs": transaction_logs_to_dictionary(tx.logs),
171-
}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "multiversx-sdk-cli"
7-
version = "10.1.0"
7+
version = "10.2.0"
88
authors = [
99
{ name="MultiversX" },
1010
]

0 commit comments

Comments
 (0)