Skip to content

Commit

Permalink
Merge branch 'main' into refactor/api/user-agent
Browse files Browse the repository at this point in the history
  • Loading branch information
fubuloubu authored Jun 6, 2024
2 parents 8a9df63 + 6797e66 commit bf2e46f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
8 changes: 6 additions & 2 deletions ape_safe/_cli/safe_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,16 @@ def remove(cli_ctx: SafeCliContext, safe, skip_confirmation):

@click.command(cls=ConnectedProviderCommand)
@safe_cli_ctx()
@click.argument("address", type=ChecksumAddress)
@click.argument("account")
@click.option("--confirmed", is_flag=True, default=None)
def all_txns(cli_ctx: SafeCliContext, address, confirmed):
def all_txns(cli_ctx: SafeCliContext, account, confirmed):
"""
View and filter all transactions for a given Safe using Safe API
"""
if account in cli_ctx.account_manager.aliases:
account = cli_ctx.account_manager.load(account)

address = cli_ctx.conversion_manager.convert(account, AddressType)

# NOTE: Create a client to support non-local safes.
client = cli_ctx.safes.create_client(address)
Expand Down
16 changes: 9 additions & 7 deletions ape_safe/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,24 @@ def get_next_nonce(self) -> int:

def _all_transactions(self) -> Iterator[SafeApiTxData]:
"""
confirmed: Confirmed if True, not confirmed if False, both if None
Get all transactions from safe, both confirmed and unconfirmed
"""

url = f"safes/{self.address}/transactions"
url = f"safes/{self.address}/all-transactions"
while url:
response = self._get(url)
data = response.json()

for txn in data.get("results"):
# TODO: Replace with `model_validate()` after ape 0.7.
# NOTE: Using construct because of pydantic v2 back import validation error.
if "isExecuted" in txn and txn["isExecuted"]:
yield ExecutedTxData.model_validate(txn)
if "isExecuted" in txn:
if txn["isExecuted"]:
yield ExecutedTxData.model_validate(txn)

else:
yield UnexecutedTxData.model_validate(txn)
else:
yield UnexecutedTxData.model_validate(txn)

# else it is an incoming transaction

url = data.get("next")

Expand Down
14 changes: 9 additions & 5 deletions ape_safe/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def get_transactions(
elif confirmed and not is_confirmed:
continue # NOTE: Skip not confirmed transactions

if txn.nonce < next_nonce and isinstance(txn, UnexecutedTxData):
# NOTE: use `type(txn) is ...` because ExecutedTxData is a subclass of UnexecutedTxData
if txn.nonce < next_nonce and type(txn) is UnexecutedTxData:
continue # NOTE: Skip orphaned transactions

if filter_by_ids and txn.safe_tx_hash not in filter_by_ids:
Expand Down Expand Up @@ -136,10 +137,13 @@ def _http(self):
return urllib3.PoolManager(ca_certs=certifi.where())

def _request(self, method: str, url: str, json: Optional[dict] = None, **kwargs) -> Response:
# **WARNING**: The trailing slash in the URL is CRITICAL!
# If you remove it, things will not work as expected.

api_url = f"{self.transaction_service_url}/api/v1/{url}/"
# NOTE: paged requests include full url already
if url.startswith(f"{self.transaction_service_url}/api/v1/"):
api_url = url
else:
# **WARNING**: The trailing slash in the URL is CRITICAL!
# If you remove it, things will not work as expected.
api_url = f"{self.transaction_service_url}/api/v1/{url}/"
do_fail = not kwargs.pop("allow_failure", False)

# Use `or 10` to handle when None is explicit.
Expand Down

0 comments on commit bf2e46f

Please sign in to comment.