-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Analyze if we can easily develop an AsyncEthereumClient
#1269
Comments
Hi @Uxio0, I would like to assist with the analysis of this issue. What are your thoughts on adding an I think it could look like this: class EthereumClient:
def __init__(
self, ..., is_async: bool = False):
...
self.is_async = is_async
self._initialize_providers()
...
def _initialize_providers(self):
if self.is_async:
self.w3_provider = AsyncHTTPProvider(
self.ethereum_node_url,
request_kwargs={"timeout": self.provider_timeout},
)
self.w3_slow_provider = AsyncHTTPProvider(
self.ethereum_node_url,
request_kwargs={"timeout": self.slow_provider_timeout},
)
self.w3 = AsyncWeb3(self.w3_provider)
self.slow_w3 = AsyncWeb3(self.w3_slow_provider)
else:
self.w3_provider = HTTPProvider(
self.ethereum_node_url,
request_kwargs={"timeout": self.provider_timeout},
)
self.w3_slow_provider = HTTPProvider(
self.ethereum_node_url,
request_kwargs={"timeout": self.slow_provider_timeout},
)
self.w3 = Web3(self.w3_provider)
self.slow_w3 = Web3(self.w3_slow_provider)
@property
def current_block_number(self):
if self.is_async:
return self._async_current_block_number()
else:
return self._sync_current_block_number()
def _sync_current_block_number(self):
return self.w3.eth.block_number
async def _async_current_block_number(self):
return await self.w3.eth.block_number |
Hi @DavidRomanovizc and thanks for the help! Your solution looks good, but for me it would be a little confusing to add an |
Context
FastAPI
to use ourEthereumClient
AsyncWeb3
must be used instead ofWeb3
self.http_session.post
should be refactored to something similar toself.post_request
or similar, so we don't expose what library are we usingrequests
, we aioHTTP must be usedAnalyze if we can implement something similar with not much overhead. That might not be posible with our current implementation. If after the analysis we decide it takes more than one sprint to implement, we should meet and decide what to do
The text was updated successfully, but these errors were encountered: