Skip to content

Commit dc9db95

Browse files
committed
refactor(Client): standardize around pre-pending forward slash paths
1 parent 4fc6829 commit dc9db95

2 files changed

Lines changed: 19 additions & 20 deletions

File tree

ape_safe/client/__init__.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def __init__(
6767

6868
@property
6969
def safe_details(self) -> SafeDetails:
70-
response = self._get(f"safes/{self.address}/")
70+
response = self._get(f"/safes/{self.address}")
7171
return SafeDetails.model_validate(response.json())
7272

7373
def get_next_nonce(self) -> int:
@@ -78,7 +78,7 @@ def _all_transactions(self) -> Iterator[SafeApiTxData]:
7878
Get all transactions from safe, both confirmed and unconfirmed
7979
"""
8080

81-
url = f"safes/{self.address}/all-transactions/"
81+
url = f"/safes/{self.address}/all-transactions"
8282
while url:
8383
response = self._get(url)
8484
data = response.json()
@@ -97,7 +97,7 @@ def _all_transactions(self) -> Iterator[SafeApiTxData]:
9797
url = data.get("next")
9898

9999
def get_confirmations(self, safe_tx_hash: SafeTxID) -> Iterator[SafeTxConfirmation]:
100-
url = f"multisig-transactions/{str(safe_tx_hash)}/confirmations/"
100+
url = f"/multisig-transactions/{str(safe_tx_hash)}/confirmations"
101101
while url:
102102
response = self._get(url)
103103
data = response.json()
@@ -135,7 +135,7 @@ def post_transaction(
135135
# Signature handled above.
136136
post_dict.pop("signatures")
137137

138-
url = f"safes/{tx_data.safe}/multisig-transactions/"
138+
url = f"/safes/{tx_data.safe}/multisig-transactions"
139139
response = self._post(url, json=post_dict)
140140
return response
141141

@@ -151,7 +151,7 @@ def post_signatures(
151151
safe_tx_hash = safe_tx_or_hash
152152

153153
safe_tx_hash = cast(SafeTxID, to_hex(HexBytes(safe_tx_hash)))
154-
url = f"multisig-transactions/{safe_tx_hash}/confirmations/"
154+
url = f"/multisig-transactions/{safe_tx_hash}/confirmations"
155155
signature = to_hex(
156156
HexBytes(b"".join([x.encode_rsv() for x in order_by_signer(signatures)]))
157157
)
@@ -166,7 +166,7 @@ def post_signatures(
166166
def estimate_gas_cost(
167167
self, receiver: AddressType, value: int, data: bytes, operation: int = 0
168168
) -> Optional[int]:
169-
url = f"safes/{self.address}/multisig-transactions/estimations/"
169+
url = f"/safes/{self.address}/multisig-transactions/estimations"
170170
request: dict = {
171171
"to": receiver,
172172
"value": value,
@@ -178,7 +178,7 @@ def estimate_gas_cost(
178178
return int(to_hex(HexBytes(gas)), 16)
179179

180180
def get_delegates(self) -> dict["AddressType", list["AddressType"]]:
181-
url = "delegates/"
181+
url = "/delegates"
182182
delegates: dict[AddressType, list[AddressType]] = {}
183183

184184
while url:
@@ -209,7 +209,7 @@ def add_delegate(self, delegate: "AddressType", label: str, delegator: "AccountA
209209
"label": label,
210210
"signature": sig.encode_rsv().hex(),
211211
}
212-
self._post("delegates/", json=payload)
212+
self._post("/delegates", json=payload)
213213

214214
def remove_delegate(self, delegate: "AddressType", delegator: "AccountAPI"):
215215
msg_hash = self.create_delegate_message(delegate)
@@ -222,7 +222,7 @@ def remove_delegate(self, delegate: "AddressType", delegator: "AccountAPI"):
222222
"delegator": delegator.address,
223223
"signature": sig.encode_rsv().hex(),
224224
}
225-
self._delete(f"delegates/{delegate}/", json=payload)
225+
self._delete(f"/delegates/{delegate}", json=payload)
226226

227227

228228
__all__ = [

ape_safe/client/base.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,19 +163,18 @@ def _request(self, method: str, url: str, json: Optional[dict] = None, **kwargs)
163163
api_version = kwargs.pop("api_version", "v1")
164164

165165
# NOTE: paged requests include full url already
166-
if url.startswith(f"{self.base_url}/"):
166+
if url.startswith(self.base_url):
167167
api_url = url
168+
169+
elif (
170+
hasattr(self, "use_client_gateway")
171+
and self.use_client_gateway
172+
and hasattr(self, "chain_id")
173+
):
174+
api_url = f"{self.base_url}/{api_version}/chains/{self.chain_id}{url}"
175+
168176
else:
169-
if (
170-
hasattr(self, "use_client_gateway")
171-
and self.use_client_gateway
172-
and hasattr(self, "chain_id")
173-
):
174-
# **WARNING**: The trailing slash in the URL is CRITICAL!
175-
# If you remove it, things will not work as expected.
176-
api_url = f"{self.base_url}/{api_version}/chains/{self.chain_id}/{url}/"
177-
else:
178-
api_url = f"{self.base_url}/api/v1/{url}/"
177+
api_url = f"{self.base_url}/{api_version}{url}"
179178

180179
do_fail = not kwargs.pop("allow_failure", False)
181180

0 commit comments

Comments
 (0)