Skip to content

Commit

Permalink
Handle both int and ClientTimeout-based values for Async timeout (#54)
Browse files Browse the repository at this point in the history
* Handle both int and ClientTimeout-based values

Timeout values are ints, but an attribute `.total` was being called, leading to errors when passing in web3 instances into Call

* chore: refactor

---------

Co-authored-by: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com>
  • Loading branch information
DefiDebauchery and BobTheBuidler authored Feb 1, 2023
1 parent a69aad7 commit e19471a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion multicall/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Any, Awaitable, Callable, Coroutine, Dict, Iterable

import eth_retry
from aiohttp import ClientTimeout
from web3 import AsyncHTTPProvider, Web3
from web3.eth import AsyncEth
from web3.providers.async_base import AsyncBaseProvider
Expand Down Expand Up @@ -38,8 +39,13 @@ def get_async_w3(w3: Web3) -> Web3:
if w3 in async_w3s:
return async_w3s[w3]
if w3.eth.is_async and isinstance(w3.provider, AsyncBaseProvider):
if w3.provider._request_kwargs["timeout"].total < AIOHTTP_TIMEOUT.total:
timeout = w3.provider._request_kwargs["timeout"]
if isinstance(timeout, ClientTimeout):
timeout = timeout.total

if timeout < AIOHTTP_TIMEOUT.total:
w3.provider._request_kwargs["timeout"] = AIOHTTP_TIMEOUT

async_w3s[w3] = w3
return w3
request_kwargs = {'timeout': AIOHTTP_TIMEOUT}
Expand Down

0 comments on commit e19471a

Please sign in to comment.