Skip to content

Commit 9c39059

Browse files
committed
v0.1.44 added __deepcopy__ to Web3Advanced, which skips lengthy init checks but still recreates the entire Web3Advanced object
1 parent 5bf9397 commit 9c39059

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

IceCreamSwapWeb3/Web3Advanced.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,7 @@ def __init__(
6060
self.should_retry = should_retry
6161
self.unstable_blocks = unstable_blocks
6262

63-
provider = self._construct_provider(node_url=self.node_url)
64-
65-
# use the EthAdvanced class instead of the Eth class for w3.eth
66-
modules = get_default_modules()
67-
modules["eth"] = EthAdvanced
68-
69-
super().__init__(provider=provider, modules=modules)
63+
super().__init__(provider=self._construct_provider(node_url=self.node_url), modules=self._get_modules())
7064

7165
self.middleware_onion.inject(ExtraDataToPOAMiddleware, layer=0, name="poa") # required for pos chains
7266

@@ -83,6 +77,34 @@ def __init__(
8377

8478
self.middleware_onion.inject(BatchRetryMiddleware, layer=0, name="batch_retry") # split and retry batch requests
8579

80+
def __deepcopy__(self, memo):
81+
# create new instance, but only call init of Web3.py, not our custom one.
82+
new_instance = self.__class__.__new__(self.__class__)
83+
memo[id(self)] = new_instance
84+
Web3.__init__(new_instance, provider=self._construct_provider(node_url=self.node_url), modules=self._get_modules())
85+
86+
# Copy over all our custom data instead of running the lengthy checks of our init again
87+
new_instance.manager.middleware_onion = self.manager.middleware_onion
88+
new_instance.node_url = self.node_url
89+
new_instance.should_retry = self.should_retry
90+
new_instance.unstable_blocks = self.unstable_blocks
91+
new_instance.latest_seen_block = self.latest_seen_block
92+
new_instance.filter_block_range = self.filter_block_range
93+
new_instance.rpc_batch_max_size = self.rpc_batch_max_size
94+
new_instance.revert_reason_available = self.revert_reason_available
95+
new_instance.is_archive = self.is_archive
96+
new_instance.overwrites_available = self.overwrites_available
97+
new_instance.subsquid_available = self.subsquid_available
98+
99+
return new_instance
100+
101+
@staticmethod
102+
def _get_modules():
103+
# use the EthAdvanced class instead of the Eth class for w3.eth
104+
modules = get_default_modules()
105+
modules["eth"] = EthAdvanced
106+
return modules
107+
86108
@staticmethod
87109
def _construct_provider(node_url):
88110
assert "://" in node_url

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.43'
3+
VERSION = '0.1.44'
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)