Skip to content

Commit 3e7c6cd

Browse files
authored
Merge pull request #294 from crytic/corymichaelmurray-master
Add Mumbai (Polygon testnet)
2 parents 99a1de5 + e52139c commit 3e7c6cd

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

crytic_compile/cryticparser/cryticparser.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,14 @@ def _init_etherscan(parser: ArgumentParser) -> None:
328328
default=DEFAULTS_FLAG_IN_CONFIG["etherscan_api_key"],
329329
)
330330

331+
group_etherscan.add_argument(
332+
"--test-polygonscan-apikey",
333+
help="Etherscan API key.",
334+
action="store",
335+
dest="test_polygonscan_api_key",
336+
default=DEFAULTS_FLAG_IN_CONFIG["etherscan_api_key"],
337+
)
338+
331339
group_etherscan.add_argument(
332340
"--avax-apikey",
333341
help="Etherscan API key.",

crytic_compile/platform/etherscan.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"arbi:": (".arbiscan.io", "arbiscan.io"),
4646
"testnet.arbi:": ("-testnet.arbiscan.io", "testnet.arbiscan.io"),
4747
"poly:": (".polygonscan.com", "polygonscan.com"),
48+
"mumbai:": ("-testnet.polygonscan.com", "testnet.polygonscan.com"),
4849
"avax:": (".snowtrace.io", "snowtrace.io"),
4950
"testnet.avax:": ("-testnet.snowtrace.io", "testnet.snowtrace.io"),
5051
"ftm:": (".ftmscan.com", "ftmscan.com"),
@@ -215,6 +216,7 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
215216
etherscan_api_key = kwargs.get("etherscan_api_key", None)
216217
arbiscan_api_key = kwargs.get("arbiscan_api_key", None)
217218
polygonscan_api_key = kwargs.get("polygonscan_api_key", None)
219+
test_polygonscan_api_key = kwargs.get("test_polygonscan_api_key", None)
218220
avax_api_key = kwargs.get("avax_api_key", None)
219221
ftmscan_api_key = kwargs.get("ftmscan_api_key", None)
220222
bscan_api_key = kwargs.get("bscan_api_key", None)
@@ -234,6 +236,9 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
234236
if polygonscan_api_key and "polygonscan" in etherscan_url:
235237
etherscan_url += f"&apikey={polygonscan_api_key}"
236238
etherscan_bytecode_url += f"&apikey={polygonscan_api_key}"
239+
if test_polygonscan_api_key and "polygonscan" in etherscan_url:
240+
etherscan_url += f"&apikey={test_polygonscan_api_key}"
241+
etherscan_bytecode_url += f"&apikey={test_polygonscan_api_key}"
237242
if avax_api_key and "snowtrace" in etherscan_url:
238243
etherscan_url += f"&apikey={avax_api_key}"
239244
etherscan_bytecode_url += f"&apikey={avax_api_key}"
@@ -252,8 +257,16 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
252257
contract_name: str = ""
253258

254259
if not only_bytecode:
255-
with urllib.request.urlopen(etherscan_url) as response:
256-
html = response.read()
260+
if "polygon" in etherscan_url:
261+
# build object with headers, then send request
262+
new_etherscan_url = urllib.request.Request(
263+
etherscan_url, headers={"User-Agent": "Mozilla/5.0"}
264+
)
265+
with urllib.request.urlopen(new_etherscan_url) as response:
266+
html = response.read()
267+
else:
268+
with urllib.request.urlopen(etherscan_url) as response:
269+
html = response.read()
257270

258271
info = json.loads(html)
259272

crytic_compile/platform/foundry.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,16 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
140140
compilation_unit.bytecodes_runtime[contract_name] = target_loaded[
141141
"deployedBytecode"
142142
]["object"].replace("0x", "")
143-
compilation_unit.srcmaps_init[contract_name] = target_loaded["bytecode"][
144-
"sourceMap"
145-
].split(";") if target_loaded["bytecode"].get("sourceMap") else []
146-
compilation_unit.srcmaps_runtime[contract_name] = target_loaded["deployedBytecode"][
147-
"sourceMap"
148-
].split(";") if target_loaded["deployedBytecode"].get("sourceMap") else []
143+
compilation_unit.srcmaps_init[contract_name] = (
144+
target_loaded["bytecode"]["sourceMap"].split(";")
145+
if target_loaded["bytecode"].get("sourceMap")
146+
else []
147+
)
148+
compilation_unit.srcmaps_runtime[contract_name] = (
149+
target_loaded["deployedBytecode"]["sourceMap"].split(";")
150+
if target_loaded["deployedBytecode"].get("sourceMap")
151+
else []
152+
)
149153

150154
version, optimized, runs = _get_config_info(self._target)
151155

0 commit comments

Comments
 (0)