Skip to content

Commit 40564fe

Browse files
committed
v0.1.39 Web3 now has a flag whether SubSquid is available on the chain. Used in eth.get_logs to only try SubSquid if it's generally available
1 parent 3ab3827 commit 40564fe

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

IceCreamSwapWeb3/EthAdvanced.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def get_logs(
181181
use_subsquid=use_subsquid,
182182
)
183183

184-
if use_subsquid and from_block < self.w3.latest_seen_block - self.w3.unstable_blocks:
184+
if use_subsquid and self.w3.subsquid_available and from_block < self.w3.latest_seen_block - self.w3.unstable_blocks:
185185
kwargs["use_subsquid"] = False # make sure we only try once with Subsquid
186186
try:
187187
# trying to get logs from SubSquid

IceCreamSwapWeb3/Web3Advanced.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from .BatchRetryMiddleware import BatchRetryMiddleware
1111
from .EthAdvanced import EthAdvanced
1212
from .Multicall import MultiCall
13+
from .Subsquid import get_endpoints
1314
from .Web3ErrorHandlerPatch import patch_error_formatters
1415
from .FastChecksumAddress import to_checksum_address
1516

@@ -77,6 +78,7 @@ def __init__(
7778
if not self.revert_reason_available:
7879
print(f"RPC {self.node_url} does not return revert reasons")
7980
self.overwrites_available: bool = self._check_overwrites_available()
81+
self.subsquid_available: bool = self._check_subsquid_available()
8082

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

@@ -166,3 +168,17 @@ def _check_overwrites_available(self) -> bool:
166168
print(f"RPC does not support state overwrites, got: {repr(e)}")
167169
return False
168170
return response == test_value
171+
172+
def _check_subsquid_available(self) -> bool:
173+
try:
174+
endpoints = get_endpoints()
175+
except Exception as e:
176+
print(f"Could not get supported chains from SubSquid: {repr(e)}")
177+
return False
178+
179+
chain_id = self.eth.chain_id
180+
if chain_id not in endpoints:
181+
print(f"SubSquid does not support chain {chain_id}")
182+
return False
183+
184+
return True

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.38'
3+
VERSION = '0.1.39'
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)