Skip to content

Commit c4ffae9

Browse files
committed
using lru cache for caching chain id.
1 parent c357e35 commit c4ffae9

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

IceCreamSwapWeb3/EthAdvanced.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
from functools import lru_cache
23
from time import sleep
34
from typing import Optional, TypedDict, Sequence
45

@@ -76,8 +77,6 @@ def __init__(self, w3):
7677
if self.w3.should_retry:
7778
self._wrap_methods_with_retry()
7879

79-
self.chain_id_cached = super()._chain_id()
80-
8180
def _wrap_methods_with_retry(self):
8281
for method_name in self.METHODS_TO_RETRY:
8382
method = getattr(self, method_name)
@@ -292,9 +291,10 @@ def get_logs_inner(self, filter_params: FilterParams, no_retry: bool = False):
292291
no_retry = True
293292
return exponential_retry(func_name="get_logs")(self._get_logs)(filter_params, no_retry=no_retry)
294293

294+
@lru_cache
295295
def _chain_id(self):
296-
# usually this causes an RPC call and is used in every eth_call. Getting it once in the init and then not again.
297-
return self.chain_id_cached
296+
# usually this causes an RPC call and is used in every eth_call. Getting it once and then caching it.
297+
return super()._chain_id()
298298

299299

300300
def main(

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import setup, find_packages
22

3-
VERSION = '0.1.46'
3+
VERSION = '0.1.47'
44
DESCRIPTION = 'IceCreamSwap Web3.py wrapper'
55
LONG_DESCRIPTION = 'IceCreamSwap Web3.py wrapper with automatic retries, multicall and other advanced functionality'
66

0 commit comments

Comments
 (0)