Skip to content

Commit

Permalink
Pass requests kwargs in create_multi_provider_web3 (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
miohtama authored Sep 25, 2023
1 parent 8d80c84 commit 9265489
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Current

- Allow passing `request_kwargs` to [create_multi_provider_web3](https://web3-ethereum-defi.readthedocs.io/api/provider/_autosummary_provider/eth_defi.provider.multi_provider.create_multi_provider_web3.html#eth_defi.provider.multi_provider.create_multi_provider_web3)

# 0.22.12

- Retry [nonce too low errors](https://github.com/tradingstrategy-ai/web3-ethereum-defi/pull/153),
Expand Down
14 changes: 11 additions & 3 deletions eth_defi/provider/multi_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

import logging
from typing import List
from typing import List, Optional, Any

from urllib3.util import parse_url, Url
from web3 import Web3, HTTPProvider
Expand Down Expand Up @@ -90,6 +90,7 @@ def create_multi_provider_web3(
configuration_line: str,
fallback_sleep=0.1,
fallback_backoff=1.1,
request_kwargs: Optional[Any] = None,
) -> MultiProviderWeb3:
"""Create a Web3 instance with multi-provider support.
Expand Down Expand Up @@ -133,6 +134,13 @@ def create_multi_provider_web3(
:param fallback_backoff:
Sleep increase multiplier.
:param request_kwargs:
Passed to HTTPProvider, arguments for ``request`` library when doing HTTP requests.
See :py:class:`web3.HTTPProvider` for details.
Example: ``request_kwargs={"timeout": 10.0}``
:return:
Configured Web3 instance with multiple providers
"""
Expand Down Expand Up @@ -170,7 +178,7 @@ def create_multi_provider_web3(
if len(call_endpoints) < 0:
raise MultiProviderConfigurationError(f"At least one call endpoint must be specified, configuration was {configuration_line}")

call_providers = [HTTPProvider(url) for url in call_endpoints]
call_providers = [HTTPProvider(url, request_kwargs=request_kwargs) for url in call_endpoints]

# Do uJSON patching
for p in call_providers:
Expand All @@ -180,7 +188,7 @@ def create_multi_provider_web3(
transact_provider = None
if len(transact_endpoints) > 0:
transact_endpoint = transact_endpoints[0]
transact_provider = HTTPProvider(transact_endpoint)
transact_provider = HTTPProvider(transact_endpoint, request_kwargs=request_kwargs)

_fix_provider(transact_provider)

Expand Down

0 comments on commit 9265489

Please sign in to comment.