From 9fe2302c9815db20e7349d24dc8b2bef3e887db6 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Fri, 19 Apr 2024 12:10:15 +0300 Subject: [PATCH] fix transaction signing --- multiversx_sdk_cli/accounts.py | 5 ++++- multiversx_sdk_cli/cli_shared.py | 2 +- multiversx_sdk_cli/interfaces.py | 2 +- multiversx_sdk_cli/transactions.py | 6 +++--- requirements.txt | 6 +++--- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/multiversx_sdk_cli/accounts.py b/multiversx_sdk_cli/accounts.py index bb563ae5..515093b1 100644 --- a/multiversx_sdk_cli/accounts.py +++ b/multiversx_sdk_cli/accounts.py @@ -72,6 +72,9 @@ def sign_transaction(self, transaction: ITransaction) -> str: assert self.signer is not None transaction_computer = TransactionComputer() + if transaction.options & TX_HASH_SIGN_OPTIONS == TX_HASH_SIGN_OPTIONS: + return self.signer.sign(transaction_computer.compute_hash_for_signing(transaction)).hex() + return self.signer.sign(transaction_computer.compute_bytes_for_signing(transaction)).hex() def sign_message(self, data: bytes) -> str: @@ -96,7 +99,7 @@ def sign_transaction(self, transaction: ITransaction) -> str: should_use_hash_signing = compare_versions(ledger_version, SIGN_USING_HASH_VERSION) >= 0 if should_use_hash_signing: transaction.version = TX_HASH_SIGN_VERSION - transaction.options = TX_HASH_SIGN_OPTIONS + transaction.options = transaction.options | TX_HASH_SIGN_OPTIONS transaction_computer = TransactionComputer() diff --git a/multiversx_sdk_cli/cli_shared.py b/multiversx_sdk_cli/cli_shared.py index 1f5dc517..48d04f2f 100644 --- a/multiversx_sdk_cli/cli_shared.py +++ b/multiversx_sdk_cli/cli_shared.py @@ -246,7 +246,7 @@ def should_sign_with_guardian_key(args: Any) -> bool: def check_options_for_guarded_tx(options: int): if not options & TRANSACTION_OPTIONS_TX_GUARDED == TRANSACTION_OPTIONS_TX_GUARDED: - raise errors.BadUsage("Invalid guarded transaction's options. The second least significant bit must be set.") + raise errors.BadUsage("Invalid guarded transaction's options. The second least significant bit must be set") def send_or_simulate(tx: ITransaction, args: Any, dump_output: bool = True) -> CLIOutputBuilder: diff --git a/multiversx_sdk_cli/interfaces.py b/multiversx_sdk_cli/interfaces.py index 9e736b17..e59c3c8f 100644 --- a/multiversx_sdk_cli/interfaces.py +++ b/multiversx_sdk_cli/interfaces.py @@ -15,7 +15,7 @@ class ITransaction(Protocol): gas_limit: int chain_id: str nonce: int - amount: int + value: int sender_username: str receiver_username: str gas_price: int diff --git a/multiversx_sdk_cli/transactions.py b/multiversx_sdk_cli/transactions.py index c9430396..6f32c511 100644 --- a/multiversx_sdk_cli/transactions.py +++ b/multiversx_sdk_cli/transactions.py @@ -74,7 +74,7 @@ def do_prepare_transaction(args: Any) -> Transaction: gas_price=int(args.gas_price), data=str(args.data).encode(), nonce=int(args.nonce), - amount=int(args.value), + value=int(args.value), version=int(args.version), options=int(args.options) ) @@ -150,7 +150,7 @@ def tx_to_dictionary_as_inner_for_relayed_V1(tx: Transaction) -> Dict[str, Any]: dictionary["nonce"] = tx.nonce dictionary["sender"] = base64.b64encode(Address.new_from_bech32(tx.sender).get_public_key()).decode() dictionary["receiver"] = base64.b64encode(Address.new_from_bech32(tx.receiver).get_public_key()).decode() - dictionary["value"] = tx.amount + dictionary["value"] = tx.value dictionary["gasPrice"] = tx.gas_price dictionary["gasLimit"] = tx.gas_limit dictionary["data"] = base64.b64encode(tx.data).decode() @@ -204,7 +204,7 @@ def load_transaction_from_file(f: TextIO) -> Transaction: receiver_username=decode_field_value(instance.receiverUsername), gas_limit=instance.gasLimit, gas_price=instance.gasPrice, - amount=int(instance.value), + value=int(instance.value), data=TransactionPayload.from_encoded_str(instance.data).data, version=instance.version, options=instance.options, diff --git a/requirements.txt b/requirements.txt index 028aa23d..26f1d5b4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,6 +9,6 @@ semver requests-cache rich==13.3.4 -multiversx-sdk-core>=0.7.0,<0.8.0 -multiversx-sdk-network-providers>=0.12.0,<0.13.0 -multiversx-sdk-wallet>=0.8.0,<0.9.0 +multiversx-sdk-core>=0.8.0,<0.9.0 +multiversx-sdk-network-providers>=0.13.0,<0.14.0 +multiversx-sdk-wallet>=0.9.0,<0.10.0