Skip to content

Commit e2746a8

Browse files
authored
Merge pull request #495 from multiversx/improve-guarded-accounts-flow
Improve flow for guarded accounts
2 parents 1b10263 + 4a6eac6 commit e2746a8

15 files changed

Lines changed: 662 additions & 726 deletions

multiversx_sdk_cli/base_transactions_controller.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
from multiversx_sdk import LedgerAccount, Transaction, TransactionComputer
44

5+
from multiversx_sdk_cli.constants import (
6+
EXTRA_GAS_LIMIT_FOR_GUARDED_TRANSACTIONS,
7+
EXTRA_GAS_LIMIT_FOR_RELAYED_TRANSACTIONS,
8+
)
59
from multiversx_sdk_cli.cosign_transaction import cosign_transaction
610
from multiversx_sdk_cli.interfaces import IAccount
711

@@ -16,8 +20,8 @@ def sign_transaction(
1620
sender: Optional[IAccount] = None,
1721
guardian: Optional[IAccount] = None,
1822
relayer: Optional[IAccount] = None,
19-
guardian_service_url: str = "",
20-
guardian_2fa_code: str = "",
23+
guardian_service_url: Optional[str] = None,
24+
guardian_2fa_code: Optional[str] = None,
2125
):
2226
"""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."""
2327
self._set_options_for_guarded_transaction_if_needed(transaction)
@@ -34,6 +38,14 @@ def sign_transaction(
3438
)
3539
self._sign_relayed_transaction_if_relayer(transaction, relayer)
3640

41+
def add_extra_gas_limit_if_required(self, transaction: Transaction):
42+
"""In case of guarded or relayed transactions, extra gas limit is added."""
43+
if transaction.guardian:
44+
transaction.gas_limit += EXTRA_GAS_LIMIT_FOR_GUARDED_TRANSACTIONS
45+
46+
if transaction.relayer:
47+
transaction.gas_limit += EXTRA_GAS_LIMIT_FOR_RELAYED_TRANSACTIONS
48+
3749
def _set_options_for_guarded_transaction_if_needed(self, transaction: Transaction):
3850
if transaction.guardian:
3951
transaction_computer = TransactionComputer()
@@ -58,8 +70,8 @@ def _sign_guarded_transaction_if_guardian(
5870
self,
5971
transaction: Transaction,
6072
guardian: Union[IAccount, None],
61-
guardian_service_url: str,
62-
guardian_2fa_code: str,
73+
guardian_service_url: Union[str, None],
74+
guardian_2fa_code: Union[str, None],
6375
) -> Transaction:
6476
# If the guardian account is provided, we sign locally. Otherwise, we reach for the trusted cosign service.
6577
if guardian:

0 commit comments

Comments
 (0)