Skip to content

Commit

Permalink
Merge pull request #294 from crytic/corymichaelmurray-master
Browse files Browse the repository at this point in the history
Add Mumbai (Polygon testnet)
  • Loading branch information
montyly authored Oct 4, 2022
2 parents 99a1de5 + e52139c commit 3e7c6cd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
8 changes: 8 additions & 0 deletions crytic_compile/cryticparser/cryticparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,14 @@ def _init_etherscan(parser: ArgumentParser) -> None:
default=DEFAULTS_FLAG_IN_CONFIG["etherscan_api_key"],
)

group_etherscan.add_argument(
"--test-polygonscan-apikey",
help="Etherscan API key.",
action="store",
dest="test_polygonscan_api_key",
default=DEFAULTS_FLAG_IN_CONFIG["etherscan_api_key"],
)

group_etherscan.add_argument(
"--avax-apikey",
help="Etherscan API key.",
Expand Down
17 changes: 15 additions & 2 deletions crytic_compile/platform/etherscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"arbi:": (".arbiscan.io", "arbiscan.io"),
"testnet.arbi:": ("-testnet.arbiscan.io", "testnet.arbiscan.io"),
"poly:": (".polygonscan.com", "polygonscan.com"),
"mumbai:": ("-testnet.polygonscan.com", "testnet.polygonscan.com"),
"avax:": (".snowtrace.io", "snowtrace.io"),
"testnet.avax:": ("-testnet.snowtrace.io", "testnet.snowtrace.io"),
"ftm:": (".ftmscan.com", "ftmscan.com"),
Expand Down Expand Up @@ -215,6 +216,7 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
etherscan_api_key = kwargs.get("etherscan_api_key", None)
arbiscan_api_key = kwargs.get("arbiscan_api_key", None)
polygonscan_api_key = kwargs.get("polygonscan_api_key", None)
test_polygonscan_api_key = kwargs.get("test_polygonscan_api_key", None)
avax_api_key = kwargs.get("avax_api_key", None)
ftmscan_api_key = kwargs.get("ftmscan_api_key", None)
bscan_api_key = kwargs.get("bscan_api_key", None)
Expand All @@ -234,6 +236,9 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
if polygonscan_api_key and "polygonscan" in etherscan_url:
etherscan_url += f"&apikey={polygonscan_api_key}"
etherscan_bytecode_url += f"&apikey={polygonscan_api_key}"
if test_polygonscan_api_key and "polygonscan" in etherscan_url:
etherscan_url += f"&apikey={test_polygonscan_api_key}"
etherscan_bytecode_url += f"&apikey={test_polygonscan_api_key}"
if avax_api_key and "snowtrace" in etherscan_url:
etherscan_url += f"&apikey={avax_api_key}"
etherscan_bytecode_url += f"&apikey={avax_api_key}"
Expand All @@ -252,8 +257,16 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
contract_name: str = ""

if not only_bytecode:
with urllib.request.urlopen(etherscan_url) as response:
html = response.read()
if "polygon" in etherscan_url:
# build object with headers, then send request
new_etherscan_url = urllib.request.Request(
etherscan_url, headers={"User-Agent": "Mozilla/5.0"}
)
with urllib.request.urlopen(new_etherscan_url) as response:
html = response.read()
else:
with urllib.request.urlopen(etherscan_url) as response:
html = response.read()

info = json.loads(html)

Expand Down
16 changes: 10 additions & 6 deletions crytic_compile/platform/foundry.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,16 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
compilation_unit.bytecodes_runtime[contract_name] = target_loaded[
"deployedBytecode"
]["object"].replace("0x", "")
compilation_unit.srcmaps_init[contract_name] = target_loaded["bytecode"][
"sourceMap"
].split(";") if target_loaded["bytecode"].get("sourceMap") else []
compilation_unit.srcmaps_runtime[contract_name] = target_loaded["deployedBytecode"][
"sourceMap"
].split(";") if target_loaded["deployedBytecode"].get("sourceMap") else []
compilation_unit.srcmaps_init[contract_name] = (
target_loaded["bytecode"]["sourceMap"].split(";")
if target_loaded["bytecode"].get("sourceMap")
else []
)
compilation_unit.srcmaps_runtime[contract_name] = (
target_loaded["deployedBytecode"]["sourceMap"].split(";")
if target_loaded["deployedBytecode"].get("sourceMap")
else []
)

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

Expand Down

0 comments on commit 3e7c6cd

Please sign in to comment.