Skip to content

Commit 741944e

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

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

phoenix/client.py

Lines changed: 24 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,8 @@
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
68+
from solders.transaction import VersionedTransaction as SoldersVersionedTransaction
6669
from solders.pubkey import Pubkey
6770
from solders.hash import Hash
6871
from solders.signature import Signature
@@ -324,12 +327,16 @@ async def order_subscribe(
324327
"transactionSubscribe",
325328
params=[
326329
{
327-
"mentions": [str(market_pubkey)],
330+
"accounts":
331+
{
332+
"include": [str(market_pubkey)]
333+
},
328334
"failed": False,
329335
"vote": False,
330336
},
331337
{
332338
"commitment": str(commitment),
339+
"maxSupportedTransactionVersion": 1,
333340
},
334341
],
335342
)
@@ -385,15 +392,26 @@ async def order_subscribe(
385392
def __process_transaction_event(
386393
self, response, market_pubkey: Pubkey, trader_pubkey: Pubkey
387394
) -> [OrderSubscribeResponse]:
388-
payload = response["params"]["result"]["value"]
395+
if "error" in response["params"]["result"]["value"]:
396+
error = response["params"]["result"]["value"]["error"]
397+
print("Order subscription returned an error %s", error)
398+
return []
399+
400+
payload = response["params"]["result"]["value"]["transaction"]
389401
meta = payload["meta"]
390402
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
403+
version = payload["version"]
404+
405+
if version == "legacy":
406+
tx = SoldersTransaction.from_bytes(base64.b64decode(payload["transaction"][0]))
407+
else:
408+
tx = SoldersVersionedTransaction.from_bytes(base64.b64decode(payload["transaction"][0]))
409+
410+
message = tx.message
393411
base_account_keys = list(
394412
map(
395413
lambda l: Pubkey.from_bytes(bytes(l)),
396-
message["accountKeys"][1:],
414+
message.account_keys,
397415
)
398416
)
399417
lookup_table_keys = list(
@@ -417,7 +435,7 @@ def __process_transaction_event(
417435

418436
phoenix_tx = PhoenixTransaction(
419437
instructions,
420-
signature=Signature.from_bytes(payload["transaction"]["signatures"][1]),
438+
signature=tx.signatures[0],
421439
txReceived=True,
422440
txFailed=False,
423441
)

0 commit comments

Comments
 (0)