Skip to content

Commit

Permalink
Allow configuration of internal parameters (#947)
Browse files Browse the repository at this point in the history
* Make timeouts configurable via envvars

* Add environment var into child class

* Add doc for new env variables
  • Loading branch information
falvaradorodriguez authored May 7, 2024
1 parent bc2f1c3 commit e9acdf2
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 7 deletions.
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---------------------------------------------------
Expand Down
8 changes: 8 additions & 0 deletions docs/source/gnosis.eth.clients.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------------------------------------

Expand Down
26 changes: 25 additions & 1 deletion docs/source/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)``.
Expand Down Expand Up @@ -160,7 +169,7 @@ Gnosis Products
---------------
Safe
~~~~
On ``gnosis.safe`` there're classes to work with `Gnosis Safe <https://safe.global/>`_
On ``gnosis.safe`` there're classes to work with `Safe <https://safe.global/>`_

.. code-block:: python
Expand All @@ -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 <https://docs.cowswap.app>`_
Expand Down
5 changes: 4 additions & 1 deletion gnosis/eth/clients/ens_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from typing import Any, Dict, List, Optional, Union

import requests
Expand All @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion gnosis/eth/clients/etherscan_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os
import time
from typing import Any, Dict, Optional
from urllib.parse import urljoin
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion gnosis/eth/clients/sourcify_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from typing import Any, Dict, List, Optional
from urllib.parse import urljoin

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit e9acdf2

Please sign in to comment.