Skip to content

Commit

Permalink
Improve docs for Sourcify and Etherscan clients
Browse files Browse the repository at this point in the history
  • Loading branch information
Uxio0 committed Dec 16, 2024
1 parent 27f89be commit 2535f9d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
26 changes: 25 additions & 1 deletion safe_eth/eth/clients/etherscan_client_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@


class EtherscanClientV2(EtherscanClient):
"""
Etherscan API V2 supports multiple chains in the same url.
Reference: https://docs.etherscan.io/etherscan-v2
"""

BASE_API_V2_URL = "https://api.etherscan.io"

def __init__(
Expand All @@ -35,6 +41,24 @@ def get_supported_networks(cls) -> List[Dict[str, Any]]:
Fetches a list of supported networks by the Etherscan API v2.
:return: List of supported networks, or empty list if request fails.
Example response
```
{
"chainname":"Ethereum Mainnet",
"chainid":"1",
"blockexplorer":"https://etherscan.io",
"apiurl":"https://api.etherscan.io/v2/api?chainid=1",
"status":1
},
{
"chainname":"Sepolia Testnet",
"chainid":"11155111",
"blockexplorer":"https://sepolia.etherscan.io",
"apiurl":"https://api.etherscan.io/v2/api?chainid=11155111",
"status":1
}
```
"""
url = urljoin(cls.BASE_API_V2_URL, "v2/chainlist")
response = requests.get(url)
Expand All @@ -48,7 +72,7 @@ def is_supported_network(cls, network: EthereumNetwork) -> bool:
Checks if a given Ethereum network is supported by the Etherscan API v2.
:param network: The Ethereum network to check.
:return: True if the network is supported; False otherwise.
:return: `True` if the network is supported; `False` otherwise.
"""
supported_networks = cls.get_supported_networks()
return any(
Expand Down
5 changes: 3 additions & 2 deletions safe_eth/eth/clients/sourcify_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ class SourcifyClient:
"""
Get contract metadata from Sourcify. Matches can be full or partial:
- Full: Both the source files as well as the meta data files were an exact match between the deployed bytecode
- Full: Both the source files and the metadata files were an exact match between the deployed bytecode
and the published files.
- Partial: Source code compiles to the same bytecode and thus the contract behaves in the same way,
but the source code can be different: Variables can have misleading names,
but the source code can be different: variables can have misleading names,
comments can be different and especially the NatSpec comments could have been modified.
Reference: https://docs.sourcify.dev/docs/api/
"""

def __init__(
Expand Down

0 comments on commit 2535f9d

Please sign in to comment.