buffalu 2 жил өмнө
parent
commit
322909e410

+ 7 - 1
README.md

@@ -43,8 +43,14 @@ $ curl -sSL https://install.python-poetry.org | python3 -
 Setup environment and build protobufs
 ```bash
 $ poetry install
-$ poetry protoc
 $ poetry shell
+$ poetry protoc
+```
+
+Linting
+```bash
+$ poetry run black .
+$ poetry run isort .
 ```
 
 Publishing package

+ 33 - 34
examples/searcher-cli.py

@@ -36,9 +36,9 @@ from jito_searcher_client.searcher import get_searcher_client
     required=True,
 )
 def cli(
-        ctx,
-        keypair_path: str,
-        block_engine_url: str,
+    ctx,
+    keypair_path: str,
+    block_engine_url: str,
 ):
     """
     This script can be used to interface with the block engine as a jito_searcher_client.
@@ -55,16 +55,12 @@ def mempool_accounts(client: SearcherServiceStub, accounts: List[str]):
     """
     Stream pending transactions from write-locked accounts.
     """
-    leader: NextScheduledLeaderResponse = client.GetNextScheduledLeader(
-        NextScheduledLeaderRequest()
-    )
+    leader: NextScheduledLeaderResponse = client.GetNextScheduledLeader(NextScheduledLeaderRequest())
     print(
         f"next scheduled leader is {leader.next_leader_identity} in {leader.next_leader_slot - leader.current_slot} slots"
     )
 
-    for notification in client.SubscribePendingTransactions(
-            PendingTxSubscriptionRequest(accounts=accounts)
-    ):
+    for notification in client.SubscribePendingTransactions(PendingTxSubscriptionRequest(accounts=accounts)):
         for packet in notification.transactions:
             print(VersionedTransaction.from_bytes(packet.data))
 
@@ -138,13 +134,13 @@ def tip_accounts(client: SearcherServiceStub):
     required=True,
 )
 def send_bundle(
-        client: SearcherServiceStub,
-        rpc_url: str,
-        payer: str,
-        message: str,
-        num_txs: int,
-        lamports: int,
-        tip_account: str,
+    client: SearcherServiceStub,
+    rpc_url: str,
+    payer: str,
+    message: str,
+    num_txs: int,
+    lamports: int,
+    tip_account: str,
 ):
     """
     Send a bundle!
@@ -161,9 +157,7 @@ def send_bundle(
     print("waiting for jito leader...")
     while not is_leader_slot:
         time.sleep(0.5)
-        next_leader: NextScheduledLeaderResponse = client.GetNextScheduledLeader(
-            NextScheduledLeaderRequest()
-        )
+        next_leader: NextScheduledLeaderResponse = client.GetNextScheduledLeader(NextScheduledLeaderRequest())
         num_slots_to_leader = next_leader.next_leader_slot - next_leader.current_slot
         print(f"waiting {num_slots_to_leader} slots to jito leader")
         is_leader_slot = num_slots_to_leader <= 2
@@ -174,21 +168,23 @@ def send_bundle(
     # Build bundle
     txs: List[Transaction] = []
     for idx in range(num_txs):
-        ixs = [create_memo(MemoParams(program_id=Pubkey.from_string("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),
-                                      signer=payer_kp.pubkey(),
-                                      message=bytes(f"jito bundle {idx}: {message}", "utf-8")))]
+        ixs = [
+            create_memo(
+                MemoParams(
+                    program_id=Pubkey.from_string("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),
+                    signer=payer_kp.pubkey(),
+                    message=bytes(f"jito bundle {idx}: {message}", "utf-8"),
+                )
+            )
+        ]
         if idx == num_txs - 1:
             # Adds searcher tip on last tx
-            ixs.append(transfer(TransferParams(
-                from_pubkey=payer_kp.pubkey(),
-                to_pubkey=tip_account,
-                lamports=lamports
-            )))
-        tx = Transaction.new_signed_with_payer(instructions=ixs,
-                                               payer=payer_kp.pubkey(),
-                                               signing_keypairs=[payer_kp],
-                                               recent_blockhash=blockhash
-                                               )
+            ixs.append(
+                transfer(TransferParams(from_pubkey=payer_kp.pubkey(), to_pubkey=tip_account, lamports=lamports))
+            )
+        tx = Transaction.new_signed_with_payer(
+            instructions=ixs, payer=payer_kp.pubkey(), signing_keypairs=[payer_kp], recent_blockhash=blockhash
+        )
         print(f"{idx=} signature={tx.signatures[0]}")
         txs.append(tx)
 
@@ -199,8 +195,11 @@ def send_bundle(
     print(f"bundle uuid: {uuid_response.uuid}")
 
     for tx in txs:
-        print(rpc_client.confirm_transaction(tx.signatures[0], Processed, sleep_seconds=0.5,
-                                             last_valid_block_height=block_height + 10))
+        print(
+            rpc_client.confirm_transaction(
+                tx.signatures[0], Processed, sleep_seconds=0.5, last_valid_block_height=block_height + 10
+            )
+        )
 
 
 if __name__ == "__main__":

+ 14 - 22
jito_searcher_client/searcher.py

@@ -73,9 +73,7 @@ class SearcherInterceptor(
 
         return continuation(client_call_details, request)
 
-    def intercept_stream_unary(
-            self, continuation, client_call_details, request_iterator
-    ):
+    def intercept_stream_unary(self, continuation, client_call_details, request_iterator):
         self.authenticate_if_needed()
 
         client_call_details = self._insert_headers(
@@ -85,9 +83,7 @@ class SearcherInterceptor(
 
         return continuation(client_call_details, request_iterator)
 
-    def intercept_stream_stream(
-            self, continuation, client_call_details, request_iterator
-    ):
+    def intercept_stream_stream(self, continuation, client_call_details, request_iterator):
         self.authenticate_if_needed()
 
         client_call_details = self._insert_headers(
@@ -108,9 +104,7 @@ class SearcherInterceptor(
         return continuation(client_call_details, request)
 
     @staticmethod
-    def _insert_headers(
-            new_metadata: List[Tuple[str, str]], client_call_details
-    ) -> ClientCallDetails:
+    def _insert_headers(new_metadata: List[Tuple[str, str]], client_call_details) -> ClientCallDetails:
         metadata = []
         if client_call_details.metadata is not None:
             metadata = list(client_call_details.metadata)
@@ -144,9 +138,11 @@ class SearcherInterceptor(
         auth_client = AuthServiceStub(channel)
 
         new_access_token: RefreshAccessTokenResponse = auth_client.RefreshAccessToken(
-            RefreshAccessTokenRequest(refresh_token=self._refresh_token.token))
-        self._access_token = JwtToken(token=new_access_token.access_token.value,
-                                      expiration=new_access_token.access_token.expires_at_utc.seconds)
+            RefreshAccessTokenRequest(refresh_token=self._refresh_token.token)
+        )
+        self._access_token = JwtToken(
+            token=new_access_token.access_token.value, expiration=new_access_token.access_token.expires_at_utc.seconds
+        )
 
     def full_authentication(self):
         """
@@ -157,22 +153,18 @@ class SearcherInterceptor(
         auth_client = AuthServiceStub(channel)
 
         challenge = auth_client.GenerateAuthChallenge(
-            GenerateAuthChallengeRequest(
-                role=Role.SEARCHER, pubkey=bytes(self._kp.pubkey())
-            )
+            GenerateAuthChallengeRequest(role=Role.SEARCHER, pubkey=bytes(self._kp.pubkey()))
         ).challenge
 
         challenge_to_sign = f"{str(self._kp.pubkey())}-{challenge}"
 
         signed = self._kp.sign_message(bytes(challenge_to_sign, "utf8"))
 
-        auth_tokens_response: GenerateAuthTokensResponse = (
-            auth_client.GenerateAuthTokens(
-                GenerateAuthTokensRequest(
-                    challenge=challenge_to_sign,
-                    client_pubkey=bytes(self._kp.pubkey()),
-                    signed_challenge=bytes(signed),
-                )
+        auth_tokens_response: GenerateAuthTokensResponse = auth_client.GenerateAuthTokens(
+            GenerateAuthTokensRequest(
+                challenge=challenge_to_sign,
+                client_pubkey=bytes(self._kp.pubkey()),
+                signed_challenge=bytes(signed),
             )
         )
 

+ 1 - 0
pyproject.toml

@@ -27,6 +27,7 @@ python_out = "./jito_searcher_client/generated"
 line-length = 120
 target-version = ['py37']
 include = '\.pyi?$'
+extend-exclude = '''generated'''
 
 [tool.isort]
 profile = "black"