From ec4820085f02db47bf09f6b5be39a4ffe12e770d Mon Sep 17 00:00:00 2001 From: Felipe Alvarado Date: Tue, 30 Apr 2024 21:59:52 +0200 Subject: [PATCH 1/3] Make timeouts configurable via envvars --- gnosis/eth/clients/ens_client.py | 5 ++++- gnosis/eth/clients/etherscan_client.py | 5 ++++- gnosis/eth/clients/sourcify_client.py | 5 ++++- gnosis/safe/api/base_api.py | 3 ++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/gnosis/eth/clients/ens_client.py b/gnosis/eth/clients/ens_client.py index 5cbb48c3b..9f6df7b27 100644 --- a/gnosis/eth/clients/ens_client.py +++ b/gnosis/eth/clients/ens_client.py @@ -1,3 +1,4 @@ +import os from typing import Any, Dict, List, Optional, Union import requests @@ -22,7 +23,9 @@ def __init__(self, network_id: int): else: # Fallback to mainnet url = "https://api.thegraph.com/subgraphs/name/ensdomains/ens/" self.url = url - self.request_timeout = 5 # Seconds + self.request_timeout = int( + os.environ.get("ENS_CLIENT_REQUEST_TIMEOUT", 5) + ) # Seconds self.request_session = requests.Session() def is_available(self) -> bool: diff --git a/gnosis/eth/clients/etherscan_client.py b/gnosis/eth/clients/etherscan_client.py index 00563fde6..43ad903a7 100644 --- a/gnosis/eth/clients/etherscan_client.py +++ b/gnosis/eth/clients/etherscan_client.py @@ -1,4 +1,5 @@ import json +import os import time from typing import Any, Dict, Optional from urllib.parse import urljoin @@ -115,7 +116,9 @@ def __init__( self, network: EthereumNetwork, api_key: Optional[str] = None, - request_timeout: int = 10, + request_timeout: int = int( + os.environ.get("ETHERSCAN_CLIENT_REQUEST_TIMEOUT", 10) + ), ): self.network = network self.api_key = api_key diff --git a/gnosis/eth/clients/sourcify_client.py b/gnosis/eth/clients/sourcify_client.py index 1ce8ad9ec..2709477b5 100644 --- a/gnosis/eth/clients/sourcify_client.py +++ b/gnosis/eth/clients/sourcify_client.py @@ -1,3 +1,4 @@ +import os from typing import Any, Dict, List, Optional from urllib.parse import urljoin @@ -34,7 +35,9 @@ def __init__( network: EthereumNetwork = EthereumNetwork.MAINNET, base_url_api: str = "https://sourcify.dev", base_url_repo: str = "https://repo.sourcify.dev/", - request_timeout: int = 10, + request_timeout: int = int( + os.environ.get("SOURCIFY_CLIENT_REQUEST_TIMEOUT", 10) + ), ): self.network = network self.base_url_api = base_url_api diff --git a/gnosis/safe/api/base_api.py b/gnosis/safe/api/base_api.py index 705380c7f..0bf464f2a 100644 --- a/gnosis/safe/api/base_api.py +++ b/gnosis/safe/api/base_api.py @@ -1,3 +1,4 @@ +import os from abc import ABC from typing import Dict, Optional from urllib.parse import urljoin @@ -24,7 +25,7 @@ def __init__( network: EthereumNetwork, ethereum_client: Optional[EthereumClient] = None, base_url: Optional[str] = None, - request_timeout: int = 10, + request_timeout: int = int(os.environ.get("SAFE_BASE_API_REQUEST_TIMEOUT", 10)), ): """ :param network: Network for the transaction service From 2e49de1d93de1c0062425f1d532770dea34d73e2 Mon Sep 17 00:00:00 2001 From: Felipe Alvarado Date: Fri, 3 May 2024 15:26:48 +0200 Subject: [PATCH 2/3] Add environment var into child class --- gnosis/safe/api/base_api.py | 3 +-- .../transaction_service_api.py | 14 +++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/gnosis/safe/api/base_api.py b/gnosis/safe/api/base_api.py index 0bf464f2a..705380c7f 100644 --- a/gnosis/safe/api/base_api.py +++ b/gnosis/safe/api/base_api.py @@ -1,4 +1,3 @@ -import os from abc import ABC from typing import Dict, Optional from urllib.parse import urljoin @@ -25,7 +24,7 @@ def __init__( network: EthereumNetwork, ethereum_client: Optional[EthereumClient] = None, base_url: Optional[str] = None, - request_timeout: int = int(os.environ.get("SAFE_BASE_API_REQUEST_TIMEOUT", 10)), + request_timeout: int = 10, ): """ :param network: Network for the transaction service diff --git a/gnosis/safe/api/transaction_service_api/transaction_service_api.py b/gnosis/safe/api/transaction_service_api/transaction_service_api.py index 7cb1c1851..73c3934fe 100644 --- a/gnosis/safe/api/transaction_service_api/transaction_service_api.py +++ b/gnosis/safe/api/transaction_service_api/transaction_service_api.py @@ -1,11 +1,12 @@ import logging +import os from typing import Any, Dict, List, Optional, Tuple, Union from eth_account.signers.local import LocalAccount from eth_typing import ChecksumAddress, HexStr from hexbytes import HexBytes -from gnosis.eth import EthereumNetwork +from gnosis.eth import EthereumClient, EthereumNetwork from gnosis.eth.utils import fast_keccak_text from gnosis.safe import SafeTx @@ -35,6 +36,17 @@ class TransactionServiceApi(SafeBaseAPI): EthereumNetwork.ZKSYNC_MAINNET: "https://safe-transaction-zksync.safe.global", } + def __init__( + self, + network: EthereumNetwork, + ethereum_client: Optional[EthereumClient] = None, + base_url: Optional[str] = None, + request_timeout: int = int( + os.environ.get("SAFE_TRANSACTION_SERVICE_REQUEST_TIMEOUT", 10) + ), + ): + super().__init__(network, ethereum_client, base_url, request_timeout) + @classmethod def create_delegate_message_hash(cls, delegate_address: ChecksumAddress) -> str: return fast_keccak_text(get_delegate_message(delegate_address)) From 8c06d42686394b8b201df34038594553b67dbf5e Mon Sep 17 00:00:00 2001 From: Felipe Alvarado Date: Mon, 6 May 2024 13:59:54 +0200 Subject: [PATCH 3/3] Add doc for new env variables --- docs/source/conf.py | 4 ++-- docs/source/gnosis.eth.clients.rst | 8 ++++++++ docs/source/quickstart.rst | 26 +++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index ef678456d..538fdb943 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -19,8 +19,8 @@ # -- Project information ----------------------------------------------------- project = "Safe-eth-py" -copyright = "2018-2023" -author = "Uxio, Moisés" +copyright = "2018-2024" +author = "Uxio, Moisés, Felipe" # -- General configuration --------------------------------------------------- diff --git a/docs/source/gnosis.eth.clients.rst b/docs/source/gnosis.eth.clients.rst index 8c8574420..b13e32f27 100644 --- a/docs/source/gnosis.eth.clients.rst +++ b/docs/source/gnosis.eth.clients.rst @@ -20,6 +20,14 @@ gnosis.eth.clients.contract\_metadata module :undoc-members: :show-inheritance: +gnosis.eth.clients.ens\_client module +------------------------------------------- + +.. automodule:: gnosis.eth.clients.ens_client + :members: + :undoc-members: + :show-inheritance: + gnosis.eth.clients.etherscan\_client module ------------------------------------------- diff --git a/docs/source/quickstart.rst b/docs/source/quickstart.rst index 063f71552..28dc49af8 100644 --- a/docs/source/quickstart.rst +++ b/docs/source/quickstart.rst @@ -70,6 +70,15 @@ You can modify timeouts (in seconds) for the RPC endpoints by setting By default every RPC request will be retried `3` times. You can modify that by setting `ETHEREUM_RPC_RETRY_COUNT`. +gnosis.eth.clients +~~~~~~~~~~ + +You can modify timeouts (in seconds) for the gnosis.eth.clients by setting the following environment variables: + +- ``class EnsClient``: `ENS_CLIENT_REQUEST_TIMEOUT`. +- ``class EtherscanClient``: `ETHERSCAN_CLIENT_REQUEST_TIMEOUT`. +- ``class SourcifyClient``: `SOURCIFY_CLIENT_REQUEST_TIMEOUT`. + gnosis.eth.constants ~~~~~~~~~~~~~~~~~~~~ - ``NULL_ADDRESS (0x000...0)``: Solidity ``address(0)``. @@ -160,7 +169,7 @@ Gnosis Products --------------- Safe ~~~~ -On ``gnosis.safe`` there're classes to work with `Gnosis Safe `_ +On ``gnosis.safe`` there're classes to work with `Safe `_ .. code-block:: python @@ -182,6 +191,21 @@ To work with Multisig Transactions: safe_tx.call() # Check it works safe_tx.execute(tx_sender_private_key) +To interact with the Transaction Service API: + +.. code-block:: python + + from gnosis.eth import EthereumClient + from gnosis.safe import Safe + ethereum_client = EthereumClient(ETHEREUM_NODE_URL) + transaction_service_api = TransactionServiceApi( + network=EthereumNetwork.SEPOLIA, + ethereum_client=ethereum_client + ) + delegates_for_safe = transaction_service_api.get_delegates(SAFE_ADDRESS) + +You can modify the request timeout (in seconds) by setting `SAFE_TRANSACTION_SERVICE_REQUEST_TIMEOUT` as environment variable. + CowSwap ~~~~~~~~ On ``gnosis.cowswap`` there're classes to work with `CowSwap `_