Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions multiversx_sdk_cli/base_transactions_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
TRUE_STR_LOWER,
)
from multiversx_sdk_cli.cosign_transaction import cosign_transaction
from multiversx_sdk_cli.errors import BadUserInput
from multiversx_sdk_cli.errors import BadUserInput, TransactionSigningError
from multiversx_sdk_cli.guardian_relayer_data import GuardianRelayerData
from multiversx_sdk_cli.interfaces import IAccount

Expand All @@ -47,7 +47,10 @@ def sign_transaction(
self._set_options_for_hash_signing_if_needed(transaction, sender, guardian, relayer)

if sender:
transaction.signature = sender.sign_transaction(transaction)
try:
transaction.signature = sender.sign_transaction(transaction)
except Exception as e:
raise TransactionSigningError(f"Could not sign transaction: {str(e)}")

self._sign_guarded_transaction_if_guardian(
transaction,
Expand Down Expand Up @@ -94,15 +97,21 @@ def _sign_guarded_transaction_if_guardian(
) -> Transaction:
# If the guardian account is provided, we sign locally. Otherwise, we reach for the trusted cosign service.
if guardian:
transaction.guardian_signature = guardian.sign_transaction(transaction)
try:
transaction.guardian_signature = guardian.sign_transaction(transaction)
except Exception as e:
raise TransactionSigningError(f"Could not sign transaction: {str(e)}")
elif transaction.guardian and guardian_service_url and guardian_2fa_code:
cosign_transaction(transaction, guardian_service_url, guardian_2fa_code)

return transaction

def _sign_relayed_transaction_if_relayer(self, transaction: Transaction, relayer: Union[IAccount, None]):
if relayer and transaction.relayer:
transaction.relayer_signature = relayer.sign_transaction(transaction)
try:
transaction.relayer_signature = relayer.sign_transaction(transaction)
except Exception as e:
raise TransactionSigningError(f"Could not sign transaction: {str(e)}")

def _convert_args_to_typed_values(self, arguments: list[str]) -> list[Any]:
args: list[Any] = []
Expand Down
16 changes: 13 additions & 3 deletions multiversx_sdk_cli/cli_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
ArgumentsNotProvidedError,
BadUsage,
IncorrectWalletError,
LedgerError,
)
from multiversx_sdk_cli.guardian_relayer_data import GuardianRelayerData
from multiversx_sdk_cli.interfaces import IAccount
Expand Down Expand Up @@ -346,7 +347,10 @@ def prepare_account(args: Any):
hrp=hrp,
)
elif args.ledger:
return LedgerAccount(address_index=args.sender_wallet_index)
try:
return LedgerAccount(address_index=args.sender_wallet_index)
except Exception as e:
raise LedgerError(str(e))
else:
raise errors.NoWalletProvided()

Expand Down Expand Up @@ -402,7 +406,10 @@ def load_guardian_account(args: Any) -> Union[IAccount, None]:
hrp=hrp,
)
elif args.guardian_ledger:
return LedgerAccount(address_index=args.guardian_wallet_index)
try:
return LedgerAccount(address_index=args.guardian_wallet_index)
except Exception as e:
raise LedgerError(str(e))

return None

Expand Down Expand Up @@ -533,7 +540,10 @@ def load_relayer_account(args: Any) -> Union[IAccount, None]:
hrp=hrp,
)
elif args.relayer_ledger:
return LedgerAccount(address_index=args.relayer_wallet_index)
try:
return LedgerAccount(address_index=args.relayer_wallet_index)
except Exception as e:
raise LedgerError(str(e))

return None

Expand Down
10 changes: 10 additions & 0 deletions multiversx_sdk_cli/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,13 @@ def __init__(self, message: str):
class InvalidArgumentsError(KnownError):
def __init__(self, message: str):
super().__init__(message)


class LedgerError(KnownError):
def __init__(self, message: str):
super().__init__(message)


class TransactionSigningError(KnownError):
def __init__(self, message: str):
super().__init__(message)
Loading