Skip to content

Commit b1b076d

Browse files
Update blockscout url validation in github flow
1 parent fb0185a commit b1b076d

File tree

4 files changed

+52
-37
lines changed

4 files changed

+52
-37
lines changed

.github/ISSUE_TEMPLATE/add_safe_address_new_chain.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,19 @@ body:
4545
id: blockscout_client_url
4646
attributes:
4747
label: Blockscout Client URL
48-
description: Blockscout URL.
49-
placeholder: ex. https://gnosis.blockscout.com/api/v1/graphql
48+
description: Blockscout REST API URL.
49+
placeholder: ex. https://gnosis.blockscout.com/api/v2
5050
- type: input
5151
id: etherscan_client_url
5252
attributes:
53-
label: Etherscan Client URL
54-
description: Etherscan URL.
53+
label: Etherscan Client V1 URL
54+
description: Etherscan URL (Etherscan V2 does not require a different URL for each chain. https://docs.etherscan.io/etherscan-v2).
5555
placeholder: ex. https://etherscan.io
5656
- type: input
5757
id: etherscan_client_api_url
5858
attributes:
59-
label: Etherscan Client API URL
60-
description: Etherscan URL.
59+
label: Etherscan Client V1 API URL
60+
description: Etherscan API URL (Etherscan V2 does not require a different URL for each chain. https://docs.etherscan.io/etherscan-v2).
6161
placeholder: ex. https://api.etherscan.io
6262
- type: dropdown
6363
id: version

.github/scripts/github_adding_addresses/validate_new_address_issue_input_data.py

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from safe_eth.eth.utils import mk_contract_address_2
2020

2121
ERRORS = []
22+
WARNINGS = []
2223

2324

2425
def convert_chain_name(name: str) -> str:
@@ -164,26 +165,21 @@ def validate_blockscout_client_url(
164165
]
165166

166167
if client_url_domain not in chain_explorers_urls_domains:
167-
ERRORS.append(
168+
WARNINGS.append(
168169
f"Blockscout Client URL ({url}) not contained in the list of explorers urls in the chain."
169170
)
170-
return None
171171
try:
172-
body = {"query": '{transaction(hash: "%s") {status}}' % tx_hash}
173-
response = requests.post(url, json=body, verify=False)
172+
request_url = url.rstrip("/") + f"/transactions/{tx_hash}"
173+
response = requests.get(request_url, verify=False)
174174
if response.status_code == 200:
175-
tx_status = (
176-
response.json()
177-
.get("data", {})
178-
.get("transaction", {})
179-
.get("status", {})
180-
)
181-
if tx_status.lower() == "ok":
175+
tx_status = response.json().get("status", "").lower()
176+
if tx_status == "ok":
182177
return None
183-
except (IOError, ConnectionError) as e:
178+
except (IOError, ConnectionError, AttributeError) as e:
184179
print(f"Error validating Blockscout Client URL: {e}")
185180

186181
ERRORS.append(f"Blockscout Client URL ({url}) not valid.")
182+
return None
187183

188184

189185
def validate_etherscan_client_urls(
@@ -204,10 +200,9 @@ def validate_etherscan_client_urls(
204200
f"{extract(base_url).domain}.{extract(base_url).suffix}"
205201
)
206202
if client_base_url_domain not in chain_explorers_urls_domains:
207-
ERRORS.append(
203+
WARNINGS.append(
208204
f"Etherscan Client URL ({base_url}) not contained in the list of explorers urls in the chain"
209205
)
210-
return None
211206

212207
if api_url:
213208
parsed_api_url = urlparse(api_url)
@@ -218,23 +213,30 @@ def validate_etherscan_client_urls(
218213
return None
219214
client_api_url_domain = f"{extract(api_url).domain}.{extract(api_url).suffix}"
220215
if client_api_url_domain not in chain_explorers_urls_domains:
221-
ERRORS.append(
216+
WARNINGS.append(
222217
f"Etherscan Client URL API ({api_url}) not contained in the list of explorers urls in the chain"
223218
)
224-
return None
225219

226220
try:
227221
url = f"{api_url}/api?module=transaction&action=gettxreceiptstatus&txhash={tx_hash}"
228222
response = requests.get(url, verify=False)
229223

230224
if response.status_code == 200:
225+
request_status = response.json().get("status", "")
226+
if request_status == "0":
227+
request_failure_message = response.json().get("result", "")
228+
ERRORS.append(
229+
f"Error validating Etherscan Client API URL: {request_failure_message}"
230+
)
231+
return None
231232
tx_status = response.json().get("result", {}).get("status", "")
232233
if tx_status == "1":
233234
return None
234-
except (IOError, ConnectionError) as e:
235+
except (IOError, ConnectionError, AttributeError) as e:
235236
print(f"Error validating Etherscan Client API URL: {e}")
236237

237238
ERRORS.append(f"Etherscan Client API URL ({api_url}) not valid.")
239+
return None
238240

239241

240242
def validate_version(version: str) -> None:
@@ -363,8 +365,8 @@ def validate_issue_inputs() -> None:
363365
print("Inputs to validate:")
364366
print(f"Chain ID: {chain_id_input}")
365367
print(f"RPC URL: {rpc_url}")
366-
print(f"Blockscout Client URL: {blockscout_client_url}")
367-
print(f"Etherscan Client URL: {etherscan_client_url}")
368+
print(f"Blockscout Client V1 URL: {blockscout_client_url}")
369+
print(f"Etherscan Client V1 URL: {etherscan_client_url}")
368370
print(f"Etherscan Client API URL: {etherscan_client_api_url}")
369371
print(f"Version: {version}")
370372
print(f"Address (Master copy): {address_master_copy}")
@@ -424,28 +426,40 @@ def validate_issue_inputs() -> None:
424426
"Proxy factory", address_proxy, tx_hash_proxy, rpc_url
425427
)
426428

429+
result_comments = []
430+
431+
if len(WARNINGS) > 0:
432+
warnings_comment = "\n- ".join(WARNINGS)
433+
result_comments.append(
434+
"⚠️ Validation has detected the following warnings:"
435+
+ f"\n- {warnings_comment}"
436+
+ "\n\n"
437+
)
438+
427439
if len(ERRORS) > 0:
428440
errors_comment = "\n- ".join(ERRORS)
429-
add_message_to_env(
430-
"Validation has failed with the following errors:"
441+
result_comments.append(
442+
"Validation has failed with the following errors:"
431443
+ f"\n- {errors_comment}"
432-
+ "\n\n Validation failed!"
444+
+ "\n\n Validation failed!"
433445
)
446+
add_message_to_env("\n".join(result_comments))
434447
return None
448+
435449
chain_name_comment = chain_name if chain_name else "N/A"
436450
tx_master_block_comment = tx_master_info.get("block") if tx_master_info else "N/A"
437451
tx_master_l2_block_comment = (
438452
tx_master_l2_info.get("block") if tx_master_l2_info else "N/A"
439453
)
440454
tx_proxy_block_comment = tx_proxy_info.get("block") if tx_proxy_info else "N/A"
441-
add_message_to_env(
442-
"All elements have been validated and are correct:"
455+
result_comments.append(
456+
"All elements have been validated and are correct:"
443457
+ f"\n- Chain ID: {chain_id}"
444458
+ f"\n- Chain Name: {chain_name_comment}"
445459
+ f"\n- RPC URL: {rpc_url}"
446460
+ f"\n- Blockscout Client URL: {blockscout_client_url}"
447-
+ f"\n- Etherscan Client URL: {etherscan_client_url}"
448-
+ f"\n- Etherscan Client API URL: {etherscan_client_api_url}"
461+
+ f"\n- Etherscan Client V1 URL: {etherscan_client_url}"
462+
+ f"\n- Etherscan Client V1 API URL: {etherscan_client_api_url}"
449463
+ f"\n- Version: {version}"
450464
+ f"\n- Address Master Copy: {address_master_copy}"
451465
+ f"\n- Tx Hash Master Copy: {tx_hash_master_copy}"
@@ -456,8 +470,9 @@ def validate_issue_inputs() -> None:
456470
+ f"\n- Address Proxy: {address_proxy}"
457471
+ f"\n- Tx Hash Proxy: {tx_hash_proxy}"
458472
+ f"\n- Tx Block Proxy: {tx_proxy_block_comment}"
459-
+ "\n\n Validation successful!"
473+
+ "\n\n Validation successful!"
460474
)
475+
add_message_to_env("\n".join(result_comments))
461476

462477

463478
if __name__ == "__main__":

.github/workflows/create_pr_with_new_address.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ jobs:
7272
chainDetailUrl: 'Chain detail URL',
7373
rpcUrl: 'RPC URL',
7474
blockscoutClientUrl: 'Blockscout Client URL',
75-
etherscanClientUrl: 'Etherscan Client URL',
76-
etherscanClientApiUrl: 'Etherscan Client API URL',
75+
etherscanClientUrl: 'Etherscan Client V1 URL',
76+
etherscanClientApiUrl: 'Etherscan Client V1 API URL',
7777
version: 'Version',
7878
addressMasterCopy: 'Address \\(Master copy\\)',
7979
txHashMasterCopy: 'Deployment Tx hash \\(Master copy\\)',

.github/workflows/validate_new_address_issue_input_data.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ jobs:
2323
chainDetailUrl: 'Chain detail URL',
2424
rpcUrl: 'RPC URL',
2525
blockscoutClientUrl: 'Blockscout Client URL',
26-
etherscanClientUrl: 'Etherscan Client URL',
27-
etherscanClientApiUrl: 'Etherscan Client API URL',
26+
etherscanClientUrl: 'Etherscan Client V1 URL',
27+
etherscanClientApiUrl: 'Etherscan Client V1 API URL',
2828
version: 'Version',
2929
addressMasterCopy: 'Address \\(Master copy\\)',
3030
txHashMasterCopy: 'Deployment Tx hash \\(Master copy\\)',

0 commit comments

Comments
 (0)