Skip to content

Commit

Permalink
fix: more tx fix and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Dec 20, 2023
1 parent 9f5c939 commit 2a0a883
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
21 changes: 10 additions & 11 deletions ape_safe/_cli/pending.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import click
import rich
from ape.api import AccountAPI
from ape.cli import ConnectedProviderCommand, network_option, select_account
from ape.cli import ConnectedProviderCommand
from ape.exceptions import SignatureError
from ape.types import AddressType, MessageSignature
from click.exceptions import BadOptionUsage
Expand Down Expand Up @@ -157,13 +157,9 @@ def propose(cli_ctx, ecosystem, safe, data, gas_price, value, receiver, nonce, e
if do_execute:
# The user did provider a value for `--execute` however we are able to
# So we prompt them.
submitter = select_account(prompt_message="Select a submitter", key=safe.local_signers)
submitter = safe.select_signer(for_="submitter")

owner = (
submitter
if isinstance(submitter, AccountAPI)
else select_account(prompt_message="Select an `owner`", key=safe.local_signers)
)
owner = submitter if isinstance(submitter, AccountAPI) else safe.select_signer(for_="owner")

safe.client.post_transaction(
safe_tx, signatures, sender=owner.address, contractTransactionHash=safe_tx_hash
Expand Down Expand Up @@ -206,7 +202,7 @@ def _load_submitter(ctx, param, val):
if not safe.local_signers:
ctx.obj.abort("Cannot use `--execute TRUE` without a local signer.")

return select_account(key=safe.local_signers)
return safe.select_signer(for_="submitter")

return None

Expand Down Expand Up @@ -253,7 +249,7 @@ def approve(cli_ctx: SafeCliContext, safe, txn_ids, execute):
if do_execute:
# The user did provider a value for `--execute` however we are able to
# So we prompt them.
submitter = select_account(key=safe.local_signers)
submitter = safe.select_signer(for_="submitter")

if submitter:
txn.confirmations = {**txn.confirmations, **signatures_added}
Expand All @@ -279,7 +275,7 @@ def execute(cli_ctx, safe, txn_ids, submitter):
)

if not submitter:
submitter = select_account("Select a submitter", key=safe.local_signers)
submitter = safe.select_signer(for_="submitter")

for txn in pending_transactions:
# Figure out which given ID(s) we are handling.
Expand Down Expand Up @@ -317,8 +313,11 @@ def reject(cli_ctx: SafeCliContext, safe, txn_ids, execute):
"""
Reject one or more pending transactions
"""
submit = False if execute is False else True
submit = False if execute in (False, None) else True
submitter = execute if isinstance(execute, AccountAPI) else None
if submitter is None and submit:
submitter = safe.select_signer(for_="submitter")

pending_transactions = safe.client.get_transactions(
confirmed=False, starting_nonce=safe.next_nonce
)
Expand Down
5 changes: 5 additions & 0 deletions ape_safe/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from ape.api import AccountAPI, AccountContainerAPI, ReceiptAPI, TransactionAPI
from ape.api.address import BaseAddress
from ape.api.networks import LOCAL_NETWORK_NAME, ForkedNetworkAPI
from ape.cli import select_account
from ape.contracts import ContractInstance
from ape.exceptions import ProviderNotConnectedError
from ape.logging import logger
Expand Down Expand Up @@ -706,6 +707,10 @@ def add_signatures(

return signatures

def select_signer(self, for_: str = None) -> AccountAPI:
for_ = for_ or "submitter"
return select_account(prompt_message=f"Select a {for_}", key=self.local_signers)


def _get_safe_tx_id(safe_tx: SafeTx, confirmations: List[SafeTxConfirmation]) -> SafeTxID:
if tx_hash_result := next((c.transaction_hash for c in confirmations), None):
Expand Down

0 comments on commit 2a0a883

Please sign in to comment.