From a7806ecdb6a2dceedfcf38153d9a304695921af9 Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Thu, 5 Dec 2024 11:27:05 -0600 Subject: [PATCH] feat: missing ws --- ape_alchemy/provider.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/ape_alchemy/provider.py b/ape_alchemy/provider.py index 8ff90c0..ddecf5f 100644 --- a/ape_alchemy/provider.py +++ b/ape_alchemy/provider.py @@ -33,7 +33,30 @@ # Alchemy will try to publish private transactions for 25 blocks. PRIVATE_TX_BLOCK_WAIT = 25 -NETWORKS_SUPPORTING_WEBSOCKETS = ("ethereum", "arbitrum", "base", "optimism", "polygon", "fantom") +# NOTE: "*" means "all networks". +NETWORKS_SUPPORTING_WEBSOCKETS = { + "abstract": "*", + "arbitrum": "*", + "avalanche": "*", + "base": "*", + "bsc": ("mainnet", "testnet"), + "berachain": "*", + "blast": "*", + "ethereum": "*", + "fantom": "*", + "geist": ("polter",), + "gnosis": "*", + "lens": "*", + "linea": "*", + "optimism": "*", + "polygon": "*", + "scroll": "*", + "shape": "*", + "soneium": "*", + "unichain": "*", + "world-chain": "*", + "zksync": "*", +} class Alchemy(Web3Provider, UpstreamProvider): @@ -119,7 +142,13 @@ def http_uri(self) -> str: return self.uri @property - def ws_uri(self) -> str: + def ws_uri(self) -> Optional[str]: + ecosystem_name = self.network.ecosystem.name + network_name = self.network.name + supported_networks = NETWORKS_SUPPORTING_WEBSOCKETS.get(ecosystem_name, []) + if supported_networks != "*" and network_name not in supported_networks: + return None + # NOTE: Overriding `Web3Provider.ws_uri` implementation return "ws" + self.uri[4:] # Remove `http` in default URI w/ `ws`