|
3 | 3 |
|
4 | 4 | from .proto.injective.exchange.v1beta1 import tx_pb2 as injective_exchange_tx_pb |
5 | 5 | 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 |
6 | 7 |
|
7 | 8 | from .constant import Denom |
8 | 9 | from .utils import * |
9 | 10 |
|
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 | | - |
18 | 11 | class Composer: |
19 | 12 | def __init__(self, network: str): |
20 | 13 | self.network = network |
@@ -350,23 +343,20 @@ def MsgResponses(data, simulation=False): |
350 | 343 | if not simulation: |
351 | 344 | data = bytes.fromhex(data) |
352 | 345 |
|
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 |
362 | 355 | } |
363 | 356 |
|
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) |
367 | 358 | 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)) |
371 | 361 |
|
372 | 362 | return msgs |
0 commit comments