From 98d88581b152ebe02dfcdbc6e1855e605cf21a11 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Wed, 3 Jul 2024 11:40:39 +0300 Subject: [PATCH 01/14] reference sdk-py from feat branch --- multiversx_sdk_cli/cli_shared.py | 14 +++++++++++++- multiversx_sdk_cli/cli_transactions.py | 4 ++++ multiversx_sdk_cli/interfaces.py | 7 ++++++- requirements.txt | 2 +- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/multiversx_sdk_cli/cli_shared.py b/multiversx_sdk_cli/cli_shared.py index 10ba00fe..002659a4 100644 --- a/multiversx_sdk_cli/cli_shared.py +++ b/multiversx_sdk_cli/cli_shared.py @@ -63,7 +63,15 @@ def add_command_subparser(subparsers: Any, group: str, command: str, description ) -def add_tx_args(args: List[str], sub: Any, with_nonce: bool = True, with_receiver: bool = True, with_data: bool = True, with_estimate_gas: bool = False, with_guardian: bool = False): +def add_tx_args( + args: List[str], + sub: Any, + with_nonce: bool = True, + with_receiver: bool = True, + with_data: bool = True, + with_estimate_gas: bool = False, + with_guardian: bool = False, + with_relayed_v3: bool = True): if with_nonce: sub.add_argument("--nonce", type=int, required=not ("--recall-nonce" in args), help="# the nonce for the transaction") sub.add_argument("--recall-nonce", action="store_true", default=False, help="⭮ whether to recall the nonce when creating the transaction (default: %(default)s)") @@ -88,6 +96,10 @@ def add_tx_args(args: List[str], sub: Any, with_nonce: bool = True, with_receive if with_guardian: add_guardian_args(sub) + if with_relayed_v3: + sub.add_argument("--relayer", help="the address of the relayer") + sub.add_argument("--inner-transactions", help="a json file containing the inner transactions; should only be provided when creating the relayer's transaction") + sub.add_argument("--options", type=int, default=0, help="the transaction options (default: 0)") diff --git a/multiversx_sdk_cli/cli_transactions.py b/multiversx_sdk_cli/cli_transactions.py index 5e02cac1..999d2c19 100644 --- a/multiversx_sdk_cli/cli_transactions.py +++ b/multiversx_sdk_cli/cli_transactions.py @@ -1,3 +1,4 @@ +import logging from pathlib import Path from typing import Any, List @@ -10,6 +11,8 @@ do_prepare_transaction, load_transaction_from_file) +logger = logging.getLogger("cli.transactions") + def setup_parser(args: List[str], subparsers: Any) -> Any: parser = cli_shared.add_group_subparser(subparsers, "tx", "Create and broadcast Transactions") @@ -75,6 +78,7 @@ def create_transaction(args: Any): tx = do_prepare_transaction(args) if hasattr(args, "relay") and args.relay: + logger.warning("RelayedV1 transactions are deprecated. Please use RelayedV3 instead.") args.outfile.write(compute_relayed_v1_data(tx)) return diff --git a/multiversx_sdk_cli/interfaces.py b/multiversx_sdk_cli/interfaces.py index e59c3c8f..e0db9a2f 100644 --- a/multiversx_sdk_cli/interfaces.py +++ b/multiversx_sdk_cli/interfaces.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, Protocol +from typing import Any, Dict, Protocol, Sequence class IAddress(Protocol): @@ -25,6 +25,11 @@ class ITransaction(Protocol): guardian: str signature: bytes guardian_signature: bytes + relayer: str + + @property + def inner_transactions(self) -> Sequence["ITransaction"]: + ... class IAccount(Protocol): diff --git a/requirements.txt b/requirements.txt index c6f46432..cadf372e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,4 @@ requests-cache rich==13.3.4 argcomplete==3.2.2 -multiversx-sdk>=0.9.2,<1.0.0 +multiversx-sdk @ git+https://github.com/multiversx/mx-sdk-py@feat/next From c0c817bbf96d6687ed3469f756c298a93ac4c5c6 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Wed, 3 Jul 2024 17:17:36 +0300 Subject: [PATCH 02/14] add support for relayed v3 transactions --- multiversx_sdk_cli/cli_shared.py | 5 + multiversx_sdk_cli/cli_transactions.py | 37 +++++++- .../tests/test_cli_transactions.py | 78 +++++++++++++++- multiversx_sdk_cli/transactions.py | 91 +++++++------------ 4 files changed, 148 insertions(+), 63 deletions(-) diff --git a/multiversx_sdk_cli/cli_shared.py b/multiversx_sdk_cli/cli_shared.py index 002659a4..9b9ff606 100644 --- a/multiversx_sdk_cli/cli_shared.py +++ b/multiversx_sdk_cli/cli_shared.py @@ -99,6 +99,7 @@ def add_tx_args( if with_relayed_v3: sub.add_argument("--relayer", help="the address of the relayer") sub.add_argument("--inner-transactions", help="a json file containing the inner transactions; should only be provided when creating the relayer's transaction") + add_inner_transaction_outfile_arg(sub) sub.add_argument("--options", type=int, default=0, help="the transaction options (default: 0)") @@ -139,6 +140,10 @@ def add_outfile_arg(sub: Any, what: str = ""): sub.add_argument("--outfile", type=FileType("w"), default=sys.stdout, help=f"where to save the output {what} (default: stdout)") +def add_inner_transaction_outfile_arg(sub: Any): + sub.add_argument("--inner-transactions-outfile", type=str, help="where to save the transaction as an inner transaction (default: stdout)") + + def add_infile_arg(sub: Any, what: str = ""): what = f"({what})" if what else "" sub.add_argument("--infile", type=FileType("r"), required=True, help=f"input file {what}") diff --git a/multiversx_sdk_cli/cli_transactions.py b/multiversx_sdk_cli/cli_transactions.py index 222e47dc..9484fcf4 100644 --- a/multiversx_sdk_cli/cli_transactions.py +++ b/multiversx_sdk_cli/cli_transactions.py @@ -1,14 +1,17 @@ import logging from pathlib import Path -from typing import Any, List +from typing import Any, Dict, List + +from multiversx_sdk import Transaction, TransactionsConverter from multiversx_sdk_cli import cli_shared, utils from multiversx_sdk_cli.cli_output import CLIOutputBuilder from multiversx_sdk_cli.cosign_transaction import cosign_transaction from multiversx_sdk_cli.custom_network_provider import CustomNetworkProvider -from multiversx_sdk_cli.errors import NoWalletProvided +from multiversx_sdk_cli.errors import BadUsage, NoWalletProvided from multiversx_sdk_cli.transactions import (compute_relayed_v1_data, do_prepare_transaction, + load_inner_transactions_from_file, load_transaction_from_file) logger = logging.getLogger("cli.transactions") @@ -82,8 +85,14 @@ def create_transaction(args: Any): if args.data_file: args.data = Path(args.data_file).read_text() + check_relayer_transaction_with_data_field_for_relayed_v3(args) + tx = do_prepare_transaction(args) + if hasattr(args, "inner_transactions_outfile") and args.inner_transactions_outfile: + save_transaction_to_inner_transactions_file(tx, args) + return + if hasattr(args, "relay") and args.relay: logger.warning("RelayedV1 transactions are deprecated. Please use RelayedV3 instead.") args.outfile.write(compute_relayed_v1_data(tx)) @@ -92,6 +101,30 @@ def create_transaction(args: Any): cli_shared.send_or_simulate(tx, args) +def save_transaction_to_inner_transactions_file(transaction: Transaction, args: Any): + inner_txs_file = Path(args.inner_transactions_outfile).expanduser() + transactions = get_inner_transactions_if_any(inner_txs_file) + transactions.append(transaction) + + tx_converter = TransactionsConverter() + inner_transactions: Dict[str, Any] = {} + inner_transactions["innerTransactions"] = [tx_converter.transaction_to_dictionary(tx) for tx in transactions] + + with open(inner_txs_file, "w") as file: + utils.dump_out_json(inner_transactions, file) + + +def get_inner_transactions_if_any(file: Path) -> List[Transaction]: + if file.is_file(): + return load_inner_transactions_from_file(file) + return [] + + +def check_relayer_transaction_with_data_field_for_relayed_v3(args: Any): + if hasattr(args, "inner_transactions") and args.inner_transactions and args.data: + raise BadUsage("Can't set data field when creating a relayedV3 transaction") + + def send_transaction(args: Any): args = utils.as_object(args) diff --git a/multiversx_sdk_cli/tests/test_cli_transactions.py b/multiversx_sdk_cli/tests/test_cli_transactions.py index 157b181b..252d8146 100644 --- a/multiversx_sdk_cli/tests/test_cli_transactions.py +++ b/multiversx_sdk_cli/tests/test_cli_transactions.py @@ -1,10 +1,12 @@ import json +import os from pathlib import Path -from typing import Any +from typing import Any, List from multiversx_sdk_cli.cli import main testdata_path = Path(__file__).parent / "testdata" +testdata_out = Path(__file__).parent / "testdata-out" def test_relayed_v1_transaction(capsys: Any): @@ -87,5 +89,79 @@ def test_create_multi_transfer_transaction(capsys: Any): assert signature == "575b029d52ff5ffbfb7bab2f04052de88a6f7d022a6ad368459b8af9acaed3717d3f95db09f460649a8f405800838bc2c432496bd03c9039ea166bd32b84660e" +def test_create_and_save_inner_transaction(): + return_code = main([ + "tx", "new", + "--pem", str(testdata_path / "alice.pem"), + "--receiver", "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx", + "--nonce", "77", + "--gas-limit", "500000", + "--relayer", "erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8", + "--inner-transactions-outfile", str(testdata_out / "inner_transactions.json"), + "--chain", "T", + ]) + assert False if return_code else True + assert Path(testdata_out / "inner_transactions.json").is_file() + + +def test_create_and_append_inner_transaction(): + return_code = main([ + "tx", "new", + "--pem", str(testdata_path / "alice.pem"), + "--receiver", "erd1fggp5ru0jhcjrp5rjqyqrnvhr3sz3v2e0fm3ktknvlg7mcyan54qzccnan", + "--nonce", "1234", + "--gas-limit", "50000", + "--relayer", "erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8", + "--inner-transactions-outfile", str(testdata_out / "inner_transactions.json"), + "--chain", "T", + ]) + assert False if return_code else True + + with open(testdata_out / "inner_transactions.json", "r") as file: + json_file = json.load(file) + + inner_txs: List[Any] = json_file["innerTransactions"] + assert len(inner_txs) == 2 + + +def test_create_relayer_transaction(capsys: Any): + return_code = main([ + "tx", "new", + "--pem", str(testdata_path / "testUser.pem"), + "--receiver", "erd1cqqxak4wun7508e0yj9ng843r6hv4mzd0hhpjpsejkpn9wa9yq8sj7u2u5", + "--nonce", "987", + "--gas-limit", "5000000", + "--inner-transactions", str(testdata_out / "inner_transactions.json"), + "--chain", "T", + ]) + # remove test file to ensure consistency when running test file locally + os.remove(testdata_out / "inner_transactions.json") + + assert False if return_code else True + + tx = _read_stdout(capsys) + tx_json = json.loads(tx)["emittedTransaction"] + + assert tx_json["sender"] == "erd1cqqxak4wun7508e0yj9ng843r6hv4mzd0hhpjpsejkpn9wa9yq8sj7u2u5" + assert tx_json["receiver"] == "erd1cqqxak4wun7508e0yj9ng843r6hv4mzd0hhpjpsejkpn9wa9yq8sj7u2u5" + assert tx_json["gasLimit"] == 5000000 + assert tx_json["nonce"] == 987 + assert tx_json["chainID"] == "T" + + # should be the two inner transactions created in the tests above + inner_transactions = tx_json["innerTransactions"] + assert len(inner_transactions) == 2 + + assert inner_transactions[0]["sender"] == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert inner_transactions[0]["receiver"] == "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx" + assert inner_transactions[0]["nonce"] == 77 + assert inner_transactions[0]["relayer"] == "erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8" + + assert inner_transactions[1]["sender"] == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert inner_transactions[1]["receiver"] == "erd1fggp5ru0jhcjrp5rjqyqrnvhr3sz3v2e0fm3ktknvlg7mcyan54qzccnan" + assert inner_transactions[1]["nonce"] == 1234 + assert inner_transactions[1]["relayer"] == "erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8" + + def _read_stdout(capsys: Any) -> str: return capsys.readouterr().out.strip() diff --git a/multiversx_sdk_cli/transactions.py b/multiversx_sdk_cli/transactions.py index 96381258..91b8386c 100644 --- a/multiversx_sdk_cli/transactions.py +++ b/multiversx_sdk_cli/transactions.py @@ -2,10 +2,11 @@ import json import logging import time +from pathlib import Path from typing import Any, Dict, List, Optional, Protocol, TextIO from multiversx_sdk import (Address, Token, TokenComputer, TokenTransfer, - Transaction, TransactionPayload, + Transaction, TransactionsConverter, TransactionsFactoryConfig, TransferTransactionsFactory) @@ -37,28 +38,10 @@ def get_transaction(self, tx_hash: str, with_process_status: Optional[bool] = Fa ... -class JSONTransaction: - def __init__(self) -> None: - self.hash = "" - self.nonce = 0 - self.value = "0" - self.receiver = "" - self.sender = "" - self.senderUsername = "" - self.receiverUsername = "" - self.gasPrice = 0 - self.gasLimit = 0 - self.data: str = "" - self.chainID = "" - self.version = 0 - self.options = 0 - self.signature = "" - self.guardian = "" - self.guardianSignature = "" - - def do_prepare_transaction(args: Any) -> Transaction: account = load_sender_account_from_args(args) + + native_amount = int(args.value) transfers = getattr(args, "token_transfers", None) transfers = prepare_token_transfers(transfers) if transfers else None @@ -66,19 +49,23 @@ def do_prepare_transaction(args: Any) -> Transaction: factory = TransferTransactionsFactory(config) receiver = Address.new_from_bech32(args.receiver) - # will be replaced with 'create_transaction_for_transfer' - if transfers: - tx = factory.create_transaction_for_esdt_token_transfer( + # temporary workaround until proper fix in sdk-py + if native_amount or transfers: + tx = factory.create_transaction_for_transfer( sender=account.address, receiver=receiver, - token_transfers=transfers + native_amount=native_amount, + token_transfers=transfers, + data=str(args.data).encode() ) else: - tx = factory.create_transaction_for_native_token_transfer( - sender=account.address, - receiver=receiver, - native_amount=int(args.value), - data=str(args.data) + tx = Transaction( + sender=account.address.to_bech32(), + receiver=receiver.to_bech32(), + value=native_amount, + data=str(args.data).encode(), + gas_limit=int(args.gas_limit), + chain_id=args.chain ) tx.gas_limit = int(args.gas_limit) @@ -93,6 +80,12 @@ def do_prepare_transaction(args: Any) -> Transaction: if args.guardian: tx.guardian = args.guardian + if args.relayer: + tx.relayer = Address.new_from_bech32(args.relayer).to_bech32() + + if args.inner_transactions: + tx.inner_transactions = load_inner_transactions_from_file(Path(args.inner_transactions).expanduser()) + tx.signature = bytes.fromhex(account.sign_transaction(tx)) tx = sign_tx_by_guardian(args, tx) @@ -231,37 +224,15 @@ def compute_relayed_v1_data(tx: Transaction) -> str: def load_transaction_from_file(f: TextIO) -> Transaction: data_json: bytes = f.read().encode() - fields = json.loads(data_json).get("tx") or json.loads(data_json).get("emittedTransaction") - - instance = JSONTransaction() - instance.__dict__.update(fields) - - loaded_tx = Transaction( - chain_id=instance.chainID, - sender=instance.sender, - receiver=instance.receiver, - sender_username=decode_field_value(instance.senderUsername), - receiver_username=decode_field_value(instance.receiverUsername), - gas_limit=instance.gasLimit, - gas_price=instance.gasPrice, - value=int(instance.value), - data=TransactionPayload.from_encoded_str(instance.data).data, - version=instance.version, - options=instance.options, - nonce=instance.nonce - ) - - if instance.guardian: - loaded_tx.guardian = instance.guardian - - if instance.signature: - loaded_tx.signature = bytes.fromhex(instance.signature) + transaction_dictionary = json.loads(data_json).get("tx") or json.loads(data_json).get("emittedTransaction") - if instance.guardianSignature: - loaded_tx.guardian_signature = bytes.fromhex(instance.guardianSignature) + tx_converter = TransactionsConverter() + return tx_converter.dictionary_to_transaction(transaction_dictionary) - return loaded_tx +def load_inner_transactions_from_file(path: Path) -> List[Transaction]: + data_json = path.read_bytes() + transactions: List[Dict[str, Any]] = json.loads(data_json).get("innerTransactions") -def decode_field_value(value: str) -> str: - return base64.b64decode(value).decode() + tx_converter = TransactionsConverter() + return [tx_converter.dictionary_to_transaction(transaction) for transaction in transactions] From 1cee88f641cdf8340a176c0f0d4dd5f47ed78fb3 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Wed, 3 Jul 2024 17:20:14 +0300 Subject: [PATCH 03/14] remove separate function for adding cli argument --- multiversx_sdk_cli/cli_shared.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/multiversx_sdk_cli/cli_shared.py b/multiversx_sdk_cli/cli_shared.py index 9b9ff606..6a155677 100644 --- a/multiversx_sdk_cli/cli_shared.py +++ b/multiversx_sdk_cli/cli_shared.py @@ -99,7 +99,7 @@ def add_tx_args( if with_relayed_v3: sub.add_argument("--relayer", help="the address of the relayer") sub.add_argument("--inner-transactions", help="a json file containing the inner transactions; should only be provided when creating the relayer's transaction") - add_inner_transaction_outfile_arg(sub) + sub.add_argument("--inner-transactions-outfile", type=str, help="where to save the transaction as an inner transaction (default: stdout)") sub.add_argument("--options", type=int, default=0, help="the transaction options (default: 0)") @@ -140,10 +140,6 @@ def add_outfile_arg(sub: Any, what: str = ""): sub.add_argument("--outfile", type=FileType("w"), default=sys.stdout, help=f"where to save the output {what} (default: stdout)") -def add_inner_transaction_outfile_arg(sub: Any): - sub.add_argument("--inner-transactions-outfile", type=str, help="where to save the transaction as an inner transaction (default: stdout)") - - def add_infile_arg(sub: Any, what: str = ""): what = f"({what})" if what else "" sub.add_argument("--infile", type=FileType("r"), required=True, help=f"input file {what}") From 3686e193f79297a7668780ea6916e05f8f0ed67c Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Thu, 4 Jul 2024 11:15:54 +0300 Subject: [PATCH 04/14] add unit test for invalid relayed transaction --- multiversx_sdk_cli/tests/test_cli_transactions.py | 14 ++++++++++++++ multiversx_sdk_cli/transactions.py | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/multiversx_sdk_cli/tests/test_cli_transactions.py b/multiversx_sdk_cli/tests/test_cli_transactions.py index 252d8146..c2787ad7 100644 --- a/multiversx_sdk_cli/tests/test_cli_transactions.py +++ b/multiversx_sdk_cli/tests/test_cli_transactions.py @@ -124,6 +124,20 @@ def test_create_and_append_inner_transaction(): assert len(inner_txs) == 2 +def test_create_invalid_relayed_transaction(): + return_code = main([ + "tx", "new", + "--pem", str(testdata_path / "testUser.pem"), + "--receiver", "erd1cqqxak4wun7508e0yj9ng843r6hv4mzd0hhpjpsejkpn9wa9yq8sj7u2u5", + "--nonce", "987", + "--gas-limit", "5000000", + "--inner-transactions", str(testdata_out / "inner_transactions.json"), + "--data", "test data", + "--chain", "T", + ]) + assert return_code + + def test_create_relayer_transaction(capsys: Any): return_code = main([ "tx", "new", diff --git a/multiversx_sdk_cli/transactions.py b/multiversx_sdk_cli/transactions.py index 91b8386c..2f951401 100644 --- a/multiversx_sdk_cli/transactions.py +++ b/multiversx_sdk_cli/transactions.py @@ -59,10 +59,10 @@ def do_prepare_transaction(args: Any) -> Transaction: data=str(args.data).encode() ) else: + # this is for transactions with no token transfers(egld/esdt); useful for setting the data field tx = Transaction( sender=account.address.to_bech32(), receiver=receiver.to_bech32(), - value=native_amount, data=str(args.data).encode(), gas_limit=int(args.gas_limit), chain_id=args.chain From 28b172f783a38bf39e2feafd1d0e47e9b26f2eda Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Thu, 4 Jul 2024 11:56:25 +0300 Subject: [PATCH 05/14] remove redundant if else statement --- multiversx_sdk_cli/transactions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multiversx_sdk_cli/transactions.py b/multiversx_sdk_cli/transactions.py index 8cd1f9c9..9ffcc048 100644 --- a/multiversx_sdk_cli/transactions.py +++ b/multiversx_sdk_cli/transactions.py @@ -43,7 +43,7 @@ def do_prepare_transaction(args: Any) -> Transaction: native_amount = int(args.value) transfers = getattr(args, "token_transfers", []) - transfers = prepare_token_transfers(transfers) if transfers else [] + transfers = prepare_token_transfers(transfers) config = TransactionsFactoryConfig(args.chain) factory = TransferTransactionsFactory(config) From 83591d92d14aafed36deae63f73b0311ddf63e34 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Thu, 4 Jul 2024 15:35:25 +0300 Subject: [PATCH 06/14] add check for token transfers --- multiversx_sdk_cli/transactions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multiversx_sdk_cli/transactions.py b/multiversx_sdk_cli/transactions.py index 9ffcc048..0db9ab10 100644 --- a/multiversx_sdk_cli/transactions.py +++ b/multiversx_sdk_cli/transactions.py @@ -43,7 +43,7 @@ def do_prepare_transaction(args: Any) -> Transaction: native_amount = int(args.value) transfers = getattr(args, "token_transfers", []) - transfers = prepare_token_transfers(transfers) + transfers = prepare_token_transfers(transfers) if transfers else None config = TransactionsFactoryConfig(args.chain) factory = TransferTransactionsFactory(config) From 34433910b77fd3a39cbcac74ba40ea3a5c192fef Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Thu, 4 Jul 2024 15:45:04 +0300 Subject: [PATCH 07/14] reference sdk-py from feat breanch --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index ac423476..52bb6b78 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,7 +27,7 @@ dependencies = [ "semver", "requests-cache", "rich==13.3.4", - "multiversx-sdk>=0.9.2,<1.0.0", + "multiversx-sdk@git+https://github.com/multiversx/mx-sdk-py#egg=feat/next", "argcomplete==3.2.2" ] From d9cbc62c959661f06c6cd84af091216a7e656226 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Thu, 4 Jul 2024 15:49:40 +0300 Subject: [PATCH 08/14] fix package reference --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 52bb6b78..2e18c427 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,7 +27,7 @@ dependencies = [ "semver", "requests-cache", "rich==13.3.4", - "multiversx-sdk@git+https://github.com/multiversx/mx-sdk-py#egg=feat/next", + "multiversx-sdk@git+https://github.com/multiversx/mx-sdk-py#egg=multiversx_sdk@feat/next", "argcomplete==3.2.2" ] From 7410fee8868d1e94b60afb9f48eb28b208676622 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Thu, 4 Jul 2024 15:52:43 +0300 Subject: [PATCH 09/14] fix package reference --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 2e18c427..d37412bb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,7 +27,7 @@ dependencies = [ "semver", "requests-cache", "rich==13.3.4", - "multiversx-sdk@git+https://github.com/multiversx/mx-sdk-py#egg=multiversx_sdk@feat/next", + "multiversx-sdk@git+https://github.com/multiversx/mx-sdk-py@feat/next#egg=multiversx_sdk", "argcomplete==3.2.2" ] From bbfba048a3b1c51888e35cc1c5c87835fd405fce Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Thu, 4 Jul 2024 15:54:11 +0300 Subject: [PATCH 10/14] allow direct references --- pyproject.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index d37412bb..7a00392d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,6 +19,10 @@ classifiers = [ "Intended Audience :: Developers" ] + +[tool.hatch.metadata] +allow-direct-references = true + dependencies = [ "toml>=0.10.2", "requests", From 1fb13f371f88284b5272cb697190dc2a99d177ce Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Thu, 4 Jul 2024 15:56:13 +0300 Subject: [PATCH 11/14] change packages order --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 7a00392d..957535e8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,8 +31,8 @@ dependencies = [ "semver", "requests-cache", "rich==13.3.4", - "multiversx-sdk@git+https://github.com/multiversx/mx-sdk-py@feat/next#egg=multiversx_sdk", - "argcomplete==3.2.2" + "argcomplete==3.2.2", + "multiversx-sdk@git+https://github.com/multiversx/mx-sdk-py@feat/next#egg=multiversx_sdk" ] [project.scripts] From a551af905006442f7f9c5d02e522eb4f191ba842 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Thu, 4 Jul 2024 16:58:41 +0300 Subject: [PATCH 12/14] reference beta release --- pyproject.toml | 6 +----- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 957535e8..a87f87be 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,10 +19,6 @@ classifiers = [ "Intended Audience :: Developers" ] - -[tool.hatch.metadata] -allow-direct-references = true - dependencies = [ "toml>=0.10.2", "requests", @@ -32,7 +28,7 @@ dependencies = [ "requests-cache", "rich==13.3.4", "argcomplete==3.2.2", - "multiversx-sdk@git+https://github.com/multiversx/mx-sdk-py@feat/next#egg=multiversx_sdk" + "multiversx-sdk==0.11.0b0" ] [project.scripts] diff --git a/requirements.txt b/requirements.txt index cadf372e..987c82e3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,4 @@ requests-cache rich==13.3.4 argcomplete==3.2.2 -multiversx-sdk @ git+https://github.com/multiversx/mx-sdk-py@feat/next +multiversx-sdk==0.11.0b0 From dbb68ac67cc8d05800da4403c5dec0d80e67c9fc Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Mon, 8 Jul 2024 10:49:52 +0300 Subject: [PATCH 13/14] fixes after review --- multiversx_sdk_cli/cli_contracts.py | 6 +++--- multiversx_sdk_cli/cli_delegation.py | 2 +- multiversx_sdk_cli/cli_dns.py | 2 +- multiversx_sdk_cli/cli_shared.py | 19 +++++++++---------- multiversx_sdk_cli/cli_transactions.py | 2 +- multiversx_sdk_cli/cli_validators.py | 2 +- multiversx_sdk_cli/transactions.py | 3 +-- 7 files changed, 17 insertions(+), 19 deletions(-) diff --git a/multiversx_sdk_cli/cli_contracts.py b/multiversx_sdk_cli/cli_contracts.py index 62cc983b..b1d513e6 100644 --- a/multiversx_sdk_cli/cli_contracts.py +++ b/multiversx_sdk_cli/cli_contracts.py @@ -75,7 +75,7 @@ def setup_parser(args: List[str], subparsers: Any) -> Any: cli_shared.add_outfile_arg(sub) cli_shared.add_wallet_args(args, sub) cli_shared.add_proxy_arg(sub) - cli_shared.add_tx_args(args, sub, with_receiver=False, with_data=False, with_guardian=True) + cli_shared.add_tx_args(args, sub, with_receiver=False, with_data=False) _add_arguments_arg(sub) sub.add_argument("--wait-result", action="store_true", default=False, help="signal to wait for the transaction result - only valid if --send is set") @@ -92,7 +92,7 @@ def setup_parser(args: List[str], subparsers: Any) -> Any: cli_shared.add_outfile_arg(sub) cli_shared.add_wallet_args(args, sub) cli_shared.add_proxy_arg(sub) - cli_shared.add_tx_args(args, sub, with_receiver=False, with_data=False, with_guardian=True) + cli_shared.add_tx_args(args, sub, with_receiver=False, with_data=False) _add_function_arg(sub) _add_arguments_arg(sub) _add_token_transfers_args(sub) @@ -113,7 +113,7 @@ def setup_parser(args: List[str], subparsers: Any) -> Any: _add_metadata_arg(sub) cli_shared.add_wallet_args(args, sub) cli_shared.add_proxy_arg(sub) - cli_shared.add_tx_args(args, sub, with_receiver=False, with_data=False, with_guardian=True) + cli_shared.add_tx_args(args, sub, with_receiver=False, with_data=False) _add_arguments_arg(sub) sub.add_argument("--wait-result", action="store_true", default=False, help="signal to wait for the transaction result - only valid if --send is set") diff --git a/multiversx_sdk_cli/cli_delegation.py b/multiversx_sdk_cli/cli_delegation.py index 9c49d158..7ce579f5 100644 --- a/multiversx_sdk_cli/cli_delegation.py +++ b/multiversx_sdk_cli/cli_delegation.py @@ -182,7 +182,7 @@ def setup_parser(args: List[str], subparsers: Any) -> Any: def _add_common_arguments(args: List[str], sub: Any): cli_shared.add_proxy_arg(sub) cli_shared.add_wallet_args(args, sub) - cli_shared.add_tx_args(args, sub, with_receiver=False, with_data=False, with_estimate_gas=True, with_guardian=True) + cli_shared.add_tx_args(args, sub, with_receiver=False, with_data=False, with_estimate_gas=True) cli_shared.add_broadcast_args(sub, relay=False) cli_shared.add_outfile_arg(sub, what="signed transaction, hash") cli_shared.add_guardian_wallet_args(args, sub) diff --git a/multiversx_sdk_cli/cli_dns.py b/multiversx_sdk_cli/cli_dns.py index a7c8dcd6..c22de0d6 100644 --- a/multiversx_sdk_cli/cli_dns.py +++ b/multiversx_sdk_cli/cli_dns.py @@ -20,7 +20,7 @@ def setup_parser(args: List[str], subparsers: Any) -> Any: cli_shared.add_broadcast_args(sub, relay=True) cli_shared.add_wallet_args(args, sub) cli_shared.add_proxy_arg(sub) - cli_shared.add_tx_args(args, sub, with_receiver=False, with_data=False, with_guardian=True) + cli_shared.add_tx_args(args, sub, with_receiver=False, with_data=False) cli_shared.add_guardian_wallet_args(args, sub) sub.add_argument("--name", help="the name to register") sub.set_defaults(func=register) diff --git a/multiversx_sdk_cli/cli_shared.py b/multiversx_sdk_cli/cli_shared.py index 6a155677..867c2e1f 100644 --- a/multiversx_sdk_cli/cli_shared.py +++ b/multiversx_sdk_cli/cli_shared.py @@ -69,9 +69,7 @@ def add_tx_args( with_nonce: bool = True, with_receiver: bool = True, with_data: bool = True, - with_estimate_gas: bool = False, - with_guardian: bool = False, - with_relayed_v3: bool = True): + with_estimate_gas: bool = False): if with_nonce: sub.add_argument("--nonce", type=int, required=not ("--recall-nonce" in args), help="# the nonce for the transaction") sub.add_argument("--recall-nonce", action="store_true", default=False, help="⭮ whether to recall the nonce when creating the transaction (default: %(default)s)") @@ -93,17 +91,18 @@ def add_tx_args( sub.add_argument("--chain", help="the chain identifier") sub.add_argument("--version", type=int, default=DEFAULT_TX_VERSION, help="the transaction version (default: %(default)s)") - if with_guardian: - add_guardian_args(sub) - - if with_relayed_v3: - sub.add_argument("--relayer", help="the address of the relayer") - sub.add_argument("--inner-transactions", help="a json file containing the inner transactions; should only be provided when creating the relayer's transaction") - sub.add_argument("--inner-transactions-outfile", type=str, help="where to save the transaction as an inner transaction (default: stdout)") + add_guardian_args(sub) + add_relayed_v3_args(sub) sub.add_argument("--options", type=int, default=0, help="the transaction options (default: 0)") +def add_relayed_v3_args(sub: Any): + sub.add_argument("--relayer", help="the address of the relayer") + sub.add_argument("--inner-transactions", help="a json file containing the inner transactions; should only be provided when creating the relayer's transaction") + sub.add_argument("--inner-transactions-outfile", type=str, help="where to save the transaction as an inner transaction (default: stdout)") + + def add_guardian_args(sub: Any): sub.add_argument("--guardian", type=str, help="the address of the guradian", default="") sub.add_argument("--guardian-service-url", type=str, help="the url of the guardian service", default="") diff --git a/multiversx_sdk_cli/cli_transactions.py b/multiversx_sdk_cli/cli_transactions.py index 9484fcf4..924e4c9d 100644 --- a/multiversx_sdk_cli/cli_transactions.py +++ b/multiversx_sdk_cli/cli_transactions.py @@ -64,7 +64,7 @@ def setup_parser(args: List[str], subparsers: Any) -> Any: def _add_common_arguments(args: List[str], sub: Any): cli_shared.add_wallet_args(args, sub) - cli_shared.add_tx_args(args, sub, with_guardian=True) + cli_shared.add_tx_args(args, sub) sub.add_argument("--data-file", type=str, default=None, help="a file containing transaction data") diff --git a/multiversx_sdk_cli/cli_validators.py b/multiversx_sdk_cli/cli_validators.py index e2a73b54..106f403c 100644 --- a/multiversx_sdk_cli/cli_validators.py +++ b/multiversx_sdk_cli/cli_validators.py @@ -88,7 +88,7 @@ def setup_parser(args: List[str], subparsers: Any) -> Any: def _add_common_arguments(args: List[str], sub: Any): cli_shared.add_proxy_arg(sub) cli_shared.add_wallet_args(args, sub) - cli_shared.add_tx_args(args, sub, with_receiver=False, with_data=False, with_estimate_gas=True, with_guardian=True) + cli_shared.add_tx_args(args, sub, with_receiver=False, with_data=False, with_estimate_gas=True) cli_shared.add_broadcast_args(sub, relay=False) cli_shared.add_outfile_arg(sub, what="signed transaction, hash") cli_shared.add_guardian_wallet_args(args, sub) diff --git a/multiversx_sdk_cli/transactions.py b/multiversx_sdk_cli/transactions.py index 0db9ab10..d875be22 100644 --- a/multiversx_sdk_cli/transactions.py +++ b/multiversx_sdk_cli/transactions.py @@ -49,7 +49,6 @@ def do_prepare_transaction(args: Any) -> Transaction: factory = TransferTransactionsFactory(config) receiver = Address.new_from_bech32(args.receiver) - # temporary workaround until proper fix in sdk-py if native_amount or transfers: tx = factory.create_transaction_for_transfer( sender=account.address, @@ -231,7 +230,7 @@ def load_transaction_from_file(f: TextIO) -> Transaction: def load_inner_transactions_from_file(path: Path) -> List[Transaction]: - data_json = path.read_bytes() + data_json = path.read_text() transactions: List[Dict[str, Any]] = json.loads(data_json).get("innerTransactions") tx_converter = TransactionsConverter() From 952cd34e3e8058a6ad29b6ef3b4556b7ff8a18fe Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Mon, 16 Sep 2024 15:23:35 +0300 Subject: [PATCH 14/14] update requirements --- pyproject.toml | 4 ++-- requirements.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a87f87be..0bc30b98 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,14 +21,14 @@ classifiers = [ dependencies = [ "toml>=0.10.2", - "requests", + "requests>=2.32.0,<3.0.0", "prettytable", "ledgercomm[hid]", "semver", "requests-cache", "rich==13.3.4", "argcomplete==3.2.2", - "multiversx-sdk==0.11.0b0" + "multiversx-sdk==0.13.0" ] [project.scripts] diff --git a/requirements.txt b/requirements.txt index 987c82e3..2048553c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ toml>=0.10.2 types-toml -requests~=2.31.0 +requests>=2.32.0,<3.0.0 types-requests prettytable types-prettytable @@ -10,4 +10,4 @@ requests-cache rich==13.3.4 argcomplete==3.2.2 -multiversx-sdk==0.11.0b0 +multiversx-sdk==0.13.0