Skip to content

Commit f9a6bf2

Browse files
authored
fix: unhandle invalid api key and multi api key set
1 parent 42aedf6 commit f9a6bf2

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

crytic_compile/platform/etherscan.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,25 +246,25 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
246246
if etherscan_api_key and "etherscan" in etherscan_url:
247247
etherscan_url += f"&apikey={etherscan_api_key}"
248248
etherscan_bytecode_url += f"&apikey={etherscan_api_key}"
249-
if arbiscan_api_key and "arbiscan" in etherscan_url:
249+
elif arbiscan_api_key and "arbiscan" in etherscan_url:
250250
etherscan_url += f"&apikey={arbiscan_api_key}"
251251
etherscan_bytecode_url += f"&apikey={arbiscan_api_key}"
252-
if polygonscan_api_key and "polygonscan" in etherscan_url:
252+
elif polygonscan_api_key and "polygonscan" in etherscan_url:
253253
etherscan_url += f"&apikey={polygonscan_api_key}"
254254
etherscan_bytecode_url += f"&apikey={polygonscan_api_key}"
255-
if test_polygonscan_api_key and "polygonscan" in etherscan_url:
255+
elif test_polygonscan_api_key and "polygonscan" in etherscan_url:
256256
etherscan_url += f"&apikey={test_polygonscan_api_key}"
257257
etherscan_bytecode_url += f"&apikey={test_polygonscan_api_key}"
258-
if avax_api_key and "snowtrace" in etherscan_url:
258+
elif avax_api_key and "snowtrace" in etherscan_url:
259259
etherscan_url += f"&apikey={avax_api_key}"
260260
etherscan_bytecode_url += f"&apikey={avax_api_key}"
261-
if ftmscan_api_key and "ftmscan" in etherscan_url:
261+
elif ftmscan_api_key and "ftmscan" in etherscan_url:
262262
etherscan_url += f"&apikey={ftmscan_api_key}"
263263
etherscan_bytecode_url += f"&apikey={ftmscan_api_key}"
264-
if bscan_api_key and "bscscan" in etherscan_url:
264+
elif bscan_api_key and "bscscan" in etherscan_url:
265265
etherscan_url += f"&apikey={bscan_api_key}"
266266
etherscan_bytecode_url += f"&apikey={bscan_api_key}"
267-
if optim_api_key and "optim" in etherscan_url:
267+
elif optim_api_key and "optim" in etherscan_url:
268268
etherscan_url += f"&apikey={optim_api_key}"
269269
etherscan_bytecode_url += f"&apikey={optim_api_key}"
270270

@@ -298,6 +298,10 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
298298
if "message" not in info:
299299
LOGGER.error("Incorrect etherscan request")
300300
raise InvalidCompilation("Incorrect etherscan request " + etherscan_url)
301+
302+
if not info["message"].startswith("OK") and "Invalid API Key" in info["result"]:
303+
LOGGER.error("Invalid etherscan API Key")
304+
raise InvalidCompilation("Invalid etherscan API Key: " + etherscan_url)
301305

302306
if not info["message"].startswith("OK"):
303307
LOGGER.error("Contract has no public source code")

0 commit comments

Comments
 (0)