Skip to content

Commit a76d2a7

Browse files
client.py: Adapt to transactionSubscribe api using "accounts" filter
1 parent e3ab693 commit a76d2a7

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

phoenix/client.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import traceback
33
from dataclasses import dataclass
44
import base58
5+
import base64
56
import json
67
from typing import Any, Callable, Dict, Iterator, Tuple, TypedDict, Union, List
78
from uuid import uuid4
@@ -63,6 +64,7 @@
6364
from solana.rpc.commitment import Commitment
6465
from solana.rpc.async_api import AsyncClient
6566
from solana.rpc.types import TxOpts
67+
from solders.transaction import Transaction as SoldersTransaction
6668
from solders.pubkey import Pubkey
6769
from solders.hash import Hash
6870
from solders.signature import Signature
@@ -324,7 +326,10 @@ async def order_subscribe(
324326
"transactionSubscribe",
325327
params=[
326328
{
327-
"mentions": [str(market_pubkey)],
329+
"accounts":
330+
{
331+
"include": [str(market_pubkey)]
332+
},
328333
"failed": False,
329334
"vote": False,
330335
},
@@ -385,15 +390,21 @@ async def order_subscribe(
385390
def __process_transaction_event(
386391
self, response, market_pubkey: Pubkey, trader_pubkey: Pubkey
387392
) -> [OrderSubscribeResponse]:
388-
payload = response["params"]["result"]["value"]
393+
if "error" in response["params"]["result"]["value"]:
394+
error = response["params"]["result"]["value"]["error"]
395+
print("Order subscription returned an error %s", error)
396+
return []
397+
398+
payload = response["params"]["result"]["value"]["transaction"]
389399
meta = payload["meta"]
390400
loaded_addresses = meta.get("loadedAddresses", {"readonly": [], "writable": []})
391-
tx_message = payload["transaction"]["message"]
392-
message = tx_message[-1] if isinstance(tx_message, list) else tx_message
401+
tx_message = SoldersTransaction.from_bytes(
402+
base64.b64decode(payload["transaction"][0])
403+
).message
393404
base_account_keys = list(
394405
map(
395406
lambda l: Pubkey.from_bytes(bytes(l)),
396-
message["accountKeys"][1:],
407+
message.account_keys,
397408
)
398409
)
399410
lookup_table_keys = list(
@@ -417,7 +428,7 @@ def __process_transaction_event(
417428

418429
phoenix_tx = PhoenixTransaction(
419430
instructions,
420-
signature=Signature.from_bytes(payload["transaction"]["signatures"][1]),
431+
signature=tx.signatures[0],
421432
txReceived=True,
422433
txFailed=False,
423434
)

0 commit comments

Comments
 (0)