Skip to content

Commit

Permalink
fix: limit to websocket capable ecosystems
Browse files Browse the repository at this point in the history
  • Loading branch information
fubuloubu authored Nov 1, 2023
1 parent d7fbbf6 commit 63b1a8f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions ape_infura/provider.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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")

Expand Down

0 comments on commit 63b1a8f

Please sign in to comment.