22import json
33import logging
44import time
5- from typing import Any , Dict , List , Optional , Protocol , TextIO
5+ from typing import Any , Dict , List , Optional , Protocol , TextIO , Union
66
77from multiversx_sdk import (Address , Token , TokenComputer , TokenTransfer ,
88 Transaction , TransactionsConverter ,
99 TransactionsFactoryConfig ,
10- TransferTransactionsFactory )
10+ TransferTransactionsFactory , TransactionComputer )
1111
1212from multiversx_sdk_cli import errors
13- from multiversx_sdk_cli .accounts import Account , LedgerAccount
13+ from multiversx_sdk_cli .accounts import Account , AccountBase , LedgerAccount
1414from multiversx_sdk_cli .cli_password import (load_guardian_password ,
1515 load_password )
1616from multiversx_sdk_cli .cosign_transaction import cosign_transaction
@@ -75,6 +75,10 @@ def do_prepare_transaction(args: Any) -> Transaction:
7575 tx .version = int (args .version )
7676 tx .options = int (args .options )
7777
78+ tx_computer = TransactionComputer ()
79+ if isinstance (account , LedgerAccount ):
80+ tx_computer .apply_options_for_hash_signing (tx )
81+
7882 if args .guardian :
7983 tx .guardian = args .guardian
8084
@@ -86,14 +90,25 @@ def do_prepare_transaction(args: Any) -> Transaction:
8690 if relayer_account .address .to_bech32 () != tx .relayer :
8791 raise IncorrectWalletError ("" )
8892
93+ if isinstance (relayer_account , LedgerAccount ):
94+ tx_computer .apply_options_for_hash_signing (tx )
95+
8996 tx .relayer_signature = bytes .fromhex (relayer_account .sign_transaction (tx ))
9097 except NoWalletProvided :
9198 logger .warning ("Relayer wallet not provided. Transaction will not be signed by relayer." )
9299 except IncorrectWalletError :
93100 raise IncorrectWalletError ("Relayer wallet does not match the relayer's address set in the transaction." )
94101
102+ try :
103+ guardian_account = get_guardian_account_from_args (args )
104+ if isinstance (guardian_account , LedgerAccount ):
105+ tx_computer .apply_options_for_hash_signing (tx )
106+
107+ except NoWalletProvided :
108+ guardian_account = None
109+
95110 tx .signature = bytes .fromhex (account .sign_transaction (tx ))
96- tx = sign_tx_by_guardian (args , tx )
111+ tx = sign_tx_by_guardian (args , tx , guardian_account )
97112
98113 return tx
99114
@@ -141,12 +156,7 @@ def prepare_token_transfers(transfers: List[Any]) -> List[TokenTransfer]:
141156 return token_transfers
142157
143158
144- def sign_tx_by_guardian (args : Any , tx : Transaction ) -> Transaction :
145- try :
146- guardian_account = get_guardian_account_from_args (args )
147- except NoWalletProvided :
148- guardian_account = None
149-
159+ def sign_tx_by_guardian (args : Any , tx : Transaction , guardian_account : Union [AccountBase , None ]) -> Transaction :
150160 if guardian_account :
151161 tx .guardian_signature = bytes .fromhex (guardian_account .sign_transaction (tx ))
152162 elif args .guardian :
0 commit comments