Skip to content

Commit 9d965d8

Browse files
author
DrunkRandomWalker
committed
merge from master
2 parents 66ef74c + dfa9cc8 commit 9d965d8

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

examples/sync/chain_client/20_MsgExec.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ async def main() -> None:
5858
print(sim_res)
5959
return
6060

61+
# We need to unpack 2 layers of response when using MsgExec
62+
# response bytes -> response msgs
63+
# exec msg response -> grantee msg response
64+
sim_res_msg = ProtoMsgComposer.MsgResponses(sim_res.result.data, simulation=True)
65+
unpacked_msg_res = ProtoMsgComposer.UnpackMsgExecResponse(
66+
msg_type=msg0.__class__.__name__,
67+
data=sim_res_msg[0].grantee
68+
)
69+
print(unpacked_msg_res)
70+
6171
# build tx
6272
gas_price = 500000000
6373
gas_limit = sim_res.gas_info.gas_used + 15000 # add 15k for gas, fee computation

pyinjective/composer.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ def MsgGrant(self, granter: str, grantee: str, msg_type: str, expire_in: int):
371371

372372
def MsgExec(self, grantee: str, msgs: List):
373373
any_msgs: List[any_pb2.Any] = []
374+
374375
for msg in msgs:
375376
any_msg = any_pb2.Any()
376377
any_msg.Pack(msg, type_url_prefix="")
@@ -409,8 +410,9 @@ def MsgResponses(data, simulation=False):
409410
"/injective.exchange.v1beta1.MsgIncreasePositionMargin": injective_exchange_tx_pb.MsgIncreasePositionMarginResponse,
410411
"/injective.auction.v1beta1.MsgBid": injective_auction_tx_pb.MsgBidResponse,
411412
"/cosmos.bank.v1beta1.MsgSend": cosmos_bank_tx_pb.MsgSendResponse,
412-
"/cosmos.authz.v1beta1.MsgGrant": cosmos_authz_tx_pb.MsgGrantResponse,
413-
"/cosmos.authz.v1beta1.MsgRevoke": cosmos_authz_tx_pb.MsgRevokeResponse,
413+
"/cosmos.authz.v1beta1.MsgGrant": cosmos_authz_tx_pb.MsgGrant,
414+
"/cosmos.authz.v1beta1.MsgExec": cosmos_authz_tx_pb.MsgExec,
415+
"/cosmos.authz.v1beta1.MsgRevoke": cosmos_authz_tx_pb.MsgRevoke,
414416
}
415417

416418
response = tx_response_pb.TxResponseData.FromString(data)
@@ -419,3 +421,27 @@ def MsgResponses(data, simulation=False):
419421
msgs.append(header_map[msg.header].FromString(msg.data))
420422

421423
return msgs
424+
425+
@staticmethod
426+
def UnpackMsgExecResponse(msg_type, data):
427+
header_map = {
428+
"MsgCreateSpotLimitOrder": injective_exchange_tx_pb.MsgCreateSpotLimitOrderResponse,
429+
"MsgCreateSpotMarketOrder": injective_exchange_tx_pb.MsgCreateSpotMarketOrderResponse,
430+
"MsgCreateDerivativeLimitOrder": injective_exchange_tx_pb.MsgCreateDerivativeLimitOrderResponse,
431+
"MsgCreateDerivativeMarketOrder": injective_exchange_tx_pb.MsgCreateDerivativeMarketOrderResponse,
432+
"MsgCancelSpotOrder": injective_exchange_tx_pb.MsgCancelSpotOrderResponse,
433+
"MsgCancelDerivativeOrder": injective_exchange_tx_pb.MsgCancelDerivativeOrderResponse,
434+
"MsgBatchCancelSpotOrders": injective_exchange_tx_pb.MsgBatchCancelSpotOrdersResponse,
435+
"MsgBatchCancelDerivativeOrders": injective_exchange_tx_pb.MsgBatchCancelDerivativeOrdersResponse,
436+
"MsgBatchCreateSpotLimitOrders": injective_exchange_tx_pb.MsgBatchCreateSpotLimitOrdersResponse,
437+
"MsgBatchCreateDerivativeLimitOrders": injective_exchange_tx_pb.MsgBatchCreateDerivativeLimitOrdersResponse,
438+
"MsgBatchUpdateOrders": injective_exchange_tx_pb.MsgBatchUpdateOrdersResponse,
439+
"MsgDeposit": injective_exchange_tx_pb.MsgDepositResponse,
440+
"MsgWithdraw": injective_exchange_tx_pb.MsgWithdrawResponse,
441+
"MsgSubaccountTransfer": injective_exchange_tx_pb.MsgSubaccountTransferResponse,
442+
"MsgLiquidatePosition": injective_exchange_tx_pb.MsgLiquidatePositionResponse,
443+
"MsgIncreasePositionMargin": injective_exchange_tx_pb.MsgIncreasePositionMarginResponse,
444+
"MsgBid": injective_auction_tx_pb.MsgBidResponse,
445+
}
446+
447+
return header_map[msg_type].FromString(bytes(data, "utf-8"))

0 commit comments

Comments
 (0)