Skip to content

Commit c25c029

Browse files
committed
Fix header issue for tx response parser, improve error log for client node selector
1 parent ffe9ff2 commit c25c029

File tree

2 files changed

+15
-25
lines changed

2 files changed

+15
-25
lines changed

pyinjective/composer.py

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,11 @@
33

44
from .proto.injective.exchange.v1beta1 import tx_pb2 as injective_exchange_tx_pb
55
from .proto.injective.exchange.v1beta1 import exchange_pb2 as injective_exchange_pb
6+
from .proto.injective.types.v1beta1 import tx_response_pb2 as tx_response_pb
67

78
from .constant import Denom
89
from .utils import *
910

10-
def split_data(data, seps):
11-
output = [data]
12-
for sep in seps:
13-
data, output = output, []
14-
for seq in data:
15-
output += seq.split(sep)
16-
return output
17-
1811
class Composer:
1912
def __init__(self, network: str):
2013
self.network = network
@@ -350,23 +343,20 @@ def MsgResponses(data, simulation=False):
350343
if not simulation:
351344
data = bytes.fromhex(data)
352345

353-
prefix_map = {
354-
b'\n{\n3/injective.exchange.v1beta1.MsgCreateSpotLimitOrder\x12D': injective_exchange_tx_pb.MsgCreateSpotLimitOrderResponse,
355-
b'\n|\n4/injective.exchange.v1beta1.MsgCreateSpotMarketOrder\x12D': injective_exchange_tx_pb.MsgCreateSpotMarketOrderResponse,
356-
b'\n\x81\x01\n9/injective.exchange.v1beta1.MsgCreateDerivativeLimitOrder\x12D': injective_exchange_tx_pb.MsgCreateDerivativeLimitOrderResponse,
357-
b'\n\x82\x01\n:/injective.exchange.v1beta1.MsgCreateDerivativeMarketOrder\x12D': injective_exchange_tx_pb.MsgCreateDerivativeMarketOrderResponse,
358-
b'\n=\n4/injective.exchange.v1beta1.MsgBatchCancelSpotOrders\x12\x05': injective_exchange_tx_pb.MsgBatchCancelSpotOrdersResponse,
359-
b'\nB\n:/injective.exchange.v1beta1.MsgBatchCancelDerivativeOrders\x12\x04': injective_exchange_tx_pb.MsgBatchCancelDerivativeOrdersResponse,
360-
b'\n\xc6\x01\n9/injective.exchange.v1beta1.MsgBatchCreateSpotLimitOrders\x12\x88\x01': injective_exchange_tx_pb.MsgBatchCreateSpotLimitOrdersResponse,
361-
b'\n\xcc\x01\n?/injective.exchange.v1beta1.MsgBatchCreateDerivativeLimitOrders\x12\x88\x01': injective_exchange_tx_pb.MsgBatchCreateDerivativeLimitOrdersResponse
346+
header_map = {
347+
'/injective.exchange.v1beta1.MsgCreateSpotLimitOrder': injective_exchange_tx_pb.MsgCreateSpotLimitOrderResponse,
348+
'/injective.exchange.v1beta1.MsgCreateSpotMarketOrder': injective_exchange_tx_pb.MsgCreateSpotMarketOrderResponse,
349+
'/injective.exchange.v1beta1.MsgCreateDerivativeLimitOrder': injective_exchange_tx_pb.MsgCreateDerivativeLimitOrderResponse,
350+
'/injective.exchange.v1beta1.MsgCreateDerivativeMarketOrder': injective_exchange_tx_pb.MsgCreateDerivativeMarketOrderResponse,
351+
'/injective.exchange.v1beta1.MsgBatchCancelSpotOrders': injective_exchange_tx_pb.MsgBatchCancelSpotOrdersResponse,
352+
'/injective.exchange.v1beta1.MsgBatchCancelDerivativeOrders': injective_exchange_tx_pb.MsgBatchCancelDerivativeOrdersResponse,
353+
'/injective.exchange.v1beta1.MsgBatchCreateSpotLimitOrders': injective_exchange_tx_pb.MsgBatchCreateSpotLimitOrdersResponse,
354+
'/injective.exchange.v1beta1.MsgBatchCreateDerivativeLimitOrders': injective_exchange_tx_pb.MsgBatchCreateDerivativeLimitOrdersResponse
362355
}
363356

364-
responses = split_data(data, prefix_map.keys())[1:]
365-
headers = split_data(data, responses)[:-1]
366-
357+
response = tx_response_pb.TxResponseData.FromString(data)
367358
msgs = []
368-
for i in range(len(headers)):
369-
proto_response = prefix_map[headers[i]].FromString(responses[i])
370-
msgs.append(proto_response)
359+
for msg in response.messages:
360+
msgs.append(header_map[msg.header].FromString(msg.data))
371361

372362
return msgs

pyinjective/constant.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def devnet(cls):
9191
def testnet(cls, node='sentry1'):
9292
nodes = ['sentry0', 'sentry1']
9393
if node not in nodes:
94-
raise ValueError("Must one of {}".format(nodes))
94+
raise ValueError("Must be one of {}".format(nodes))
9595

9696
return cls(
9797
lcd_endpoint='https://testnet.lcd.injective.dev',
@@ -110,7 +110,7 @@ def mainnet(cls, node='sentry2'):
110110
'sentry2' # us
111111
]
112112
if node not in nodes:
113-
raise ValueError("Must one of {}".format(nodes))
113+
raise ValueError("Must be one of {}".format(nodes))
114114

115115
return cls(
116116
lcd_endpoint='https://lcd.injective.network',

0 commit comments

Comments
 (0)