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

Transactions creation refactoring & fixes #478

Merged
merged 9 commits into from
Feb 10, 2025
Merged

Conversation

popenta
Copy link
Collaborator

@popenta popenta commented Feb 5, 2025

No description provided.

@popenta popenta self-assigned this Feb 5, 2025
@popenta popenta marked this pull request as draft February 5, 2025 12:36
Base automatically changed from account-refactoring to feat/next February 7, 2025 11:44
@popenta popenta marked this pull request as ready for review February 7, 2025 11:46
@andreibancioiu andreibancioiu self-requested a review February 7, 2025 13:45
Copy link
Contributor

@andreibancioiu andreibancioiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

"--gas-limit",
"50000",
"--chain",
"integration tests chain ID",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be a little bit more machine-readable (for the sake of the example) e.g. test.

Copy link
Collaborator Author

@popenta popenta Feb 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test was duplicated from an already existing test. Changed it.

@@ -398,23 +402,23 @@ def load_guardian_account(args: Any) -> Union[IAccount, None]:


def get_guardian_address(guardian: Union[IAccount, None], args: Any) -> Union[Address, None]:
if guardian:
return guardian.address
address_pem = guardian.address if guardian else None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suffix _pem is a bit ambiguous, I think. Maybe address_of_loaded_wallet (or something similar)?

address_from_account vs. address_from_args?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed



def get_relayer_address(relayer: Union[IAccount, None], args: Any) -> Union[Address, None]:
if relayer:
return relayer.address
address_pem = relayer.address if relayer else None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above, if applicable.

if hasattr(args, "guardian") and args.guardian:
return Address.new_from_bech32(args.guardian)
if address_pem and address_arg and address_pem != address_arg:
raise IncorrectWalletError("Guardian wallet does not match the guardian's address set in the transaction.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good check!

"... set in the transaction ..." - maybe replace this with, say, "... set in the arguments ..."? Or the one from the arguments gets to be the one "in the transaction", actually?

💭

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the addresses don't match, no address is used since an error is raised. Changed to ... set in the arguments.

@@ -149,7 +201,7 @@ def send_transaction(args: Any):


def get_transaction(args: Any):
args = utils.as_object(args)
# args = utils.as_object(args)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@@ -181,14 +231,12 @@ def sign_transaction(args: Any):
if guardian_account:
tx.guardian_signature = guardian_account.sign_transaction(tx)
elif args.guardian:
tx = cosign_transaction(tx, args.guardian_service_url, args.guardian_2fa_code)
cosign_transaction(tx, args.guardian_service_url, args.guardian_2fa_code)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add some comments around if guardian_account etc. E.g. if the guardian account is provided, we sign locally. Otherwise, we reach for the trusted cosign service.

💭

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now sure, at some point can we use the transactions controller here, as well (e.g. the if-else from above is implemented in the base controller's sign facility, as well)?

💭

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added the comment. Indeed, I think the BaseTransactionsController can be used and will be used in a later PR.

@@ -70,8 +71,12 @@ def prepare_deploy_transaction(
nonce: int,
version: int,
options: int,
guardian: Union[Address, None],
relayer: Union[Address, None],
guardian_account: Optional[IAccount] = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Good refactoring.

@@ -37,6 +38,67 @@ def get_transaction(self, transaction_hash: Union[bytes, str]) -> TransactionOnN
# fmt: on


class TransactionsController(BaseTransactionsController):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good refactoring! args isn't to be handled by this component, indeed, it's a concern of the "CLI" components (closer to "presentation layer") 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

guardian_service_url: str = "",
guardian_2fa_code: str = "",
):
"""Signs the transaction with the sender's account and if necessarry, signs with guardian's account and relayer's account. Also sets proper transaction options if needed."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

hrp = config.get_address_hrp()

if args.pem:
return Account.new_from_pem(file_path=Path(args.pem), index=args.pem_index, hrp=hrp)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question: when loading a key from a PEM file, shouldn't we learn the HRP directly from the comment within the PEM file (i.e. the label)? Oh, I don't think the SDK is wired that way anyway 💭

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, the sdk is not wired that way.

@@ -88,7 +89,8 @@ def setup_parser(args: list[str], subparsers: Any) -> Any:
"sign",
f"Sign a previously saved transaction.{CLIOutputBuilder.describe()}",
)
cli_shared.add_wallet_args(args, sub)
# we add the wallet args, but don't make the args mandatory
cli_shared.add_wallet_args(args, sub, True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use the named parameter, skip_...=True.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do in the next PR.

@popenta popenta merged commit baf60bb into feat/next Feb 10, 2025
12 checks passed
@popenta popenta deleted the transaction-refactoring branch February 10, 2025 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants