From 63b1a8fb9abfffe240c4704b09e514b826874395 Mon Sep 17 00:00:00 2001 From: El De-dog-lo <3859395+fubuloubu@users.noreply.github.com> Date: Wed, 1 Nov 2023 16:23:07 -0400 Subject: [PATCH] fix: limit to websocket capable ecosystems --- ape_infura/provider.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ape_infura/provider.py b/ape_infura/provider.py index d91d073..4a4c4b7 100644 --- a/ape_infura/provider.py +++ b/ape_infura/provider.py @@ -1,5 +1,5 @@ import os -from typing import Dict, Tuple +from typing import Dict, Optional, Tuple from ape.api import UpstreamProvider, Web3Provider from ape.exceptions import ContractLogicError, ProviderError, VirtualMachineError @@ -9,6 +9,12 @@ from web3.middleware import geth_poa_middleware _ENVIRONMENT_VARIABLE_NAMES = ("WEB3_INFURA_PROJECT_ID", "WEB3_INFURA_API_KEY") +# NOTE: https://docs.infura.io/learn/websockets#supported-networks +_WEBSOCKET_CAPABLE_ECOSYSTEMS = { + "ethereum", + "polygon", + "linea", +} class InfuraProviderError(ProviderError): @@ -54,8 +60,11 @@ def http_uri(self) -> str: return self.uri @property - def ws_uri(self) -> str: + def ws_uri(self) -> Optional[str]: # NOTE: Overriding `Web3Provider.ws_uri` implementation + if self.network.ecosystem.name not in _WEBSOCKET_CAPABLE_ECOSYSTEMS: + return None + # Remove `http` in default URI w/ `ws`, also infura adds `/ws` to URI return "ws" + self.uri[4:].replace("v3", "ws/v3")