Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/explorer config 2 #135

Merged
merged 2 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion moccasin/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,10 @@ def generate_main_parser_and_sub_parsers() -> (

network_uri_or_chain = get_parser.add_mutually_exclusive_group()
network_uri_or_chain.add_argument(
"--uri", help="API URI endpoint for explorer.", type=str
"--explorer-uri", help="API URI endpoint for explorer.", type=str
)
network_uri_or_chain.add_argument(
"--explorer-type", help="blockscout, etherscan, or zksyncexplorer.", type=str
)
network_uri_or_chain.add_argument(
"--network",
Expand Down
30 changes: 21 additions & 9 deletions moccasin/commands/explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def main(args: Namespace) -> int:
boa_get_abi_from_explorer(
args.address,
name=args.name,
uri=args.uri,
explorer_uri=args.explorer_uri,
explorer_type=args.explorer_type,
api_key=args.api_key,
save_abi_path=args.save_abi_path,
save=args.save,
Expand All @@ -42,7 +43,8 @@ def main(args: Namespace) -> int:
def boa_get_abi_from_explorer(
address: str,
name: str | None = None,
uri: str | None = None,
explorer_uri: str | None = None,
explorer_type: str | None = None,
api_key: str | None = None,
save_abi_path: str | None = None,
save: bool = False,
Expand All @@ -63,22 +65,28 @@ def boa_get_abi_from_explorer(
if network.chain_id:
network_name_or_id = str(network.chain_id)
if network is not None:
if not uri:
uri = network.explorer_uri
if not explorer_uri:
explorer_uri = network.explorer_uri
if not explorer_type:
explorer_type = network.explorer_type
if not api_key:
api_key = network.explorer_api_key
if not save_abi_path:
save_abi_path = network.save_abi_path
if not save_abi_path:
save_abi_path = config.project.get("save_abi_path", None)

# 2. If you still don't have a uri, check the default networks
if not uri:
# 2. If you still don't have a explorer_uri, check the default networks
if not explorer_uri:
if str(network_name_or_id).isdigit():
chain_id = int(network_name_or_id)
uri = DEFAULT_NETWORKS_BY_CHAIN_ID.get(chain_id, {}).get("explorer")
explorer_uri = DEFAULT_NETWORKS_BY_CHAIN_ID.get(chain_id, {}).get(
"explorer_uri"
)
else:
uri = DEFAULT_NETWORKS_BY_NAME.get(network_name_or_id, {}).get("explorer")
explorer_uri = DEFAULT_NETWORKS_BY_NAME.get(network_name_or_id, {}).get(
"explorer_uri"
)

# 3. Only for api, finally, check ENV variable
if not api_key:
Expand All @@ -94,7 +102,11 @@ def boa_get_abi_from_explorer(
)

abi: list = []
with boa.set_etherscan(uri, api_key=api_key):
if explorer_type != "etherscan":
logger.warning(
"As of today, fetching only works with Etherscan style explorers."
)
with boa.set_etherscan(explorer_uri, api_key=api_key):
explorer = boa.explorer.get_etherscan()
abi = explorer.fetch_abi(address)
if len(abi) == 0:
Expand Down
Loading