From d28f656e33c26eb5bb063ba6ace62b6834016d8e Mon Sep 17 00:00:00 2001 From: fubuloubu <3859395+fubuloubu@users.noreply.github.com> Date: Mon, 11 Mar 2024 22:40:11 -0400 Subject: [PATCH] feat(account): add method to propose a SafeTx directly --- ape_safe/accounts.py | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/ape_safe/accounts.py b/ape_safe/accounts.py index 4770d00..bd55bec 100644 --- a/ape_safe/accounts.py +++ b/ape_safe/accounts.py @@ -372,6 +372,38 @@ def create_safe_tx(self, txn: Optional[TransactionAPI] = None, **safe_tx_kwargs) } return self.safe_tx_def(**safe_tx) + def propose_safe_tx( + self, + safe_tx: SafeTx, + submitter: Union[AccountAPI, AddressType, str, None] = None, + sigs_by_signer: Optional[Dict[AddressType, MessageSignature]] = None, + contractTransactionHash: Optional[SafeTxID] = None, + ) -> SafeTxID: + """ + Propose a transaction to the Safe API client + """ + if not contractTransactionHash: + contractTransactionHash = get_safe_tx_hash(safe_tx) + + if not sigs_by_signer: + sigs_by_signer = {} + + sender = self.conversion_manager.convert(submitter, AddressType) + + if sender not in sigs_by_signer: + if sig := self.account_manager[sender].sign_message(safe_tx): + sigs_by_signer[sender] = sig + + # NOTE: Signatures don't have to be in order for Safe API post + self.client.post_transaction( + safe_tx, + sigs_by_signer, + sender=sender, + contractTransactionHash=contractTransactionHash, + ) + + return contractTransactionHash + def pending_transactions(self) -> Iterator[Tuple[SafeTx, List[SafeTxConfirmation]]]: for executed_tx in self.client.get_transactions(confirmed=False): yield self.create_safe_tx( @@ -719,12 +751,11 @@ def skip_signer(signer: AccountAPI): f"for Safe {self.address}#{safe_tx.nonce}" # TODO: put URI ) - # NOTE: Signatures don't have to be in order for Safe API post - self.client.post_transaction( + self.propose_safe_tx( safe_tx, - sigs_by_signer, + submitter=submitter_account, + sigs_by_signer=sigs_by_signer, contractTransactionHash=safe_tx_hash, - sender=submitter_account.address, ) # Return None so that Ape does not try to submit the transaction.