Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve flow for guarded accounts #495

Merged
merged 6 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
20 changes: 16 additions & 4 deletions multiversx_sdk_cli/base_transactions_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

from multiversx_sdk import LedgerAccount, Transaction, TransactionComputer

from multiversx_sdk_cli.constants import (
EXTRA_GAS_LIMIT_FOR_GUARDED_TRANSACTIONS,
EXTRA_GAS_LIMIT_FOR_RELAYED_TRANSACTIONS,
)
from multiversx_sdk_cli.cosign_transaction import cosign_transaction
from multiversx_sdk_cli.interfaces import IAccount

Expand All @@ -16,8 +20,8 @@ def sign_transaction(
sender: Optional[IAccount] = None,
guardian: Optional[IAccount] = None,
relayer: Optional[IAccount] = None,
guardian_service_url: str = "",
guardian_2fa_code: str = "",
guardian_service_url: Optional[str] = None,
guardian_2fa_code: Optional[str] = None,
):
"""Signs the transaction using the sender's account and, if required, additionally signs with the guardian's and relayer's accounts. Ensures the appropriate transaction options are set as needed."""
self._set_options_for_guarded_transaction_if_needed(transaction)
Expand All @@ -34,6 +38,14 @@ def sign_transaction(
)
self._sign_relayed_transaction_if_relayer(transaction, relayer)

def add_extra_gas_limit_if_required(self, transaction: Transaction):
"""In case of guarded or relayed transactions, extra gas limit is added."""
if transaction.guardian:
transaction.gas_limit += EXTRA_GAS_LIMIT_FOR_GUARDED_TRANSACTIONS

if transaction.relayer:
transaction.gas_limit += EXTRA_GAS_LIMIT_FOR_RELAYED_TRANSACTIONS

def _set_options_for_guarded_transaction_if_needed(self, transaction: Transaction):
if transaction.guardian:
transaction_computer = TransactionComputer()
Expand All @@ -58,8 +70,8 @@ def _sign_guarded_transaction_if_guardian(
self,
transaction: Transaction,
guardian: Union[IAccount, None],
guardian_service_url: str,
guardian_2fa_code: str,
guardian_service_url: Union[str, None],
guardian_2fa_code: Union[str, None],
) -> Transaction:
# If the guardian account is provided, we sign locally. Otherwise, we reach for the trusted cosign service.
if guardian:
Expand Down
Loading
Loading