diff --git a/src/solana/rpc/api.py b/src/solana/rpc/api.py index 12fbc7b5..f6703c32 100644 --- a/src/solana/rpc/api.py +++ b/src/solana/rpc/api.py @@ -83,7 +83,7 @@ class Client(_ClientCore): # pylint: disable=too-many-public-methods commitment: Default bank state to query. It can be either "finalized", "confirmed" or "processed". timeout: HTTP request timeout in seconds. extra_headers: Extra headers to pass for HTTP request. - + proxy: Proxy URL to pass to the HTTP client. """ def __init__( @@ -92,10 +92,11 @@ def __init__( commitment: Optional[Commitment] = None, timeout: float = 10, extra_headers: Optional[Dict[str, str]] = None, + proxy: Optional[str] = None, ): """Init API client.""" super().__init__(commitment) - self._provider = http.HTTPProvider(endpoint, timeout=timeout, extra_headers=extra_headers) + self._provider = http.HTTPProvider(endpoint, timeout=timeout, extra_headers=extra_headers, proxy=proxy) def is_connected(self) -> bool: """Health check. diff --git a/src/solana/rpc/async_api.py b/src/solana/rpc/async_api.py index 3a3a37ce..ce8af10f 100644 --- a/src/solana/rpc/async_api.py +++ b/src/solana/rpc/async_api.py @@ -80,6 +80,7 @@ class AsyncClient(_ClientCore): # pylint: disable=too-many-public-methods commitment: Default bank state to query. It can be either "finalized", "confirmed" or "processed". timeout: HTTP request timeout in seconds. extra_headers: Extra headers to pass for HTTP request. + proxy: Proxy URL to pass to the HTTP client. """ def __init__( @@ -88,10 +89,13 @@ def __init__( commitment: Optional[Commitment] = None, timeout: float = 10, extra_headers: Optional[Dict[str, str]] = None, + proxy: Optional[str] = None, ) -> None: """Init API client.""" super().__init__(commitment) - self._provider = async_http.AsyncHTTPProvider(endpoint, timeout=timeout, extra_headers=extra_headers) + self._provider = async_http.AsyncHTTPProvider( + endpoint, timeout=timeout, extra_headers=extra_headers, proxy=proxy + ) async def __aenter__(self) -> "AsyncClient": """Use as a context manager.""" diff --git a/src/solana/rpc/providers/async_http.py b/src/solana/rpc/providers/async_http.py index 1ac8c8dd..1b3c85a4 100644 --- a/src/solana/rpc/providers/async_http.py +++ b/src/solana/rpc/providers/async_http.py @@ -45,10 +45,11 @@ def __init__( endpoint: Optional[str] = None, extra_headers: Optional[Dict[str, str]] = None, timeout: float = DEFAULT_TIMEOUT, + proxy: Optional[str] = None, ): """Init AsyncHTTPProvider.""" super().__init__(endpoint, extra_headers) - self.session = httpx.AsyncClient(timeout=timeout) + self.session = httpx.AsyncClient(timeout=timeout, proxy=proxy) def __str__(self) -> str: """String definition for HTTPProvider.""" diff --git a/src/solana/rpc/providers/http.py b/src/solana/rpc/providers/http.py index d0522f23..50694c77 100644 --- a/src/solana/rpc/providers/http.py +++ b/src/solana/rpc/providers/http.py @@ -45,10 +45,11 @@ def __init__( endpoint: Optional[str] = None, extra_headers: Optional[Dict[str, str]] = None, timeout: float = DEFAULT_TIMEOUT, + proxy: Optional[str] = None, ): """Init HTTPProvider.""" super().__init__(endpoint, extra_headers) - self.session = httpx.Client(timeout=timeout) + self.session = httpx.Client(timeout=timeout, proxy=proxy) def __str__(self) -> str: """String definition for HTTPProvider."""