Skip to content

Commit

Permalink
feat(account): add method to propose a SafeTx directly
Browse files Browse the repository at this point in the history
  • Loading branch information
fubuloubu committed Mar 12, 2024
1 parent d33d396 commit d28f656
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions ape_safe/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit d28f656

Please sign in to comment.