Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update calls for new no auth case on kp bug #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions jito_searcher_client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ leaders = client.GetConnectedLeaders(ConnectedLeadersRequest())
print(f"{leaders=}")
```

## Sync Client (No Auth)

```python
from jito_searcher_client import get_searcher_client
from jito_searcher_client.generated.searcher_pb2 import ConnectedLeadersRequest

from solders.keypair import Keypair

BLOCK_ENGINE_URL = "frankfurt.mainnet.block-engine.jito.wtf"

client = get_searcher_client(BLOCK_ENGINE_URL)
leaders = client.GetConnectedLeaders(ConnectedLeadersRequest())
print(f"{leaders=}")
```

## Async Client

```python
Expand All @@ -54,6 +69,26 @@ async def main():
asyncio.run(main())
```

## Async Client (No Auth)

```python
import asyncio

from jito_searcher_client import get_async_searcher_client
from jito_searcher_client.generated.searcher_pb2 import ConnectedLeadersRequest

from solders.keypair import Keypair

BLOCK_ENGINE_URL = "frankfurt.mainnet.block-engine.jito.wtf"

async def main():
client = await get_async_searcher_client(BLOCK_ENGINE_URL)
leaders = await client.GetConnectedLeaders(ConnectedLeadersRequest())
print(f"{leaders=}")

asyncio.run(main())
```

# Development

Install pip
Expand Down
29 changes: 16 additions & 13 deletions jito_searcher_client/jito_searcher_client/searcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,24 @@ def __init__(self, url: str, kp: Keypair):
self._refresh_token: Optional[JwtToken] = None

def intercept_unary_stream(self, continuation, client_call_details, request):
self.authenticate_if_needed()
if self._kp != None:
self.authenticate_if_needed()

client_call_details = self._insert_headers(
[("authorization", f"Bearer {self._access_token.token}")],
client_call_details,
)
client_call_details = self._insert_headers(
[("authorization", f"Bearer {self._access_token.token}")],
client_call_details,
)

return continuation(client_call_details, request)

def intercept_unary_unary(self, continuation, client_call_details, request):
self.authenticate_if_needed()
if self._kp != None:
self.authenticate_if_needed()

client_call_details = self._insert_headers(
[("authorization", f"Bearer {self._access_token.token}")],
client_call_details,
)
client_call_details = self._insert_headers(
[("authorization", f"Bearer {self._access_token.token}")],
client_call_details,
)

return continuation(client_call_details, request)

Expand Down Expand Up @@ -147,16 +149,17 @@ def full_authentication(self):
)


def get_searcher_client(url: str, kp: Keypair) -> SearcherServiceStub:
def get_searcher_client(url: str, kp: Keypair=None) -> SearcherServiceStub:
"""
Returns a Searcher Service client that intercepts requests and authenticates with the block engine.
:param url: url of the block engine without http/https
:param kp: keypair of the block engine
:return: SearcherServiceStub which handles authentication on requests
"""
# Authenticate immediately
# Authenticate immediately only if it is required
searcher_interceptor = SearcherInterceptor(url, kp)
searcher_interceptor.authenticate_if_needed()
if kp != None:
searcher_interceptor.authenticate_if_needed()

credentials = ssl_channel_credentials()
channel = secure_channel(url, credentials)
Expand Down