Skip to content

Commit 1fe5fb8

Browse files
author
abel
committed
Merge branch 'master' of https://github.com/InjectiveLabs/sdk-python into dev
2 parents 241f1e9 + 7b85dbb commit 1fe5fb8

File tree

6 files changed

+74
-17
lines changed

6 files changed

+74
-17
lines changed

Pipfile.lock

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ make tests
9292
* Solved issue preventing requesting spot and derivative historical orders for more than one market_id
9393
* Add `pytest` as a development dependency to implement and run unit tests
9494

95+
**0.6.3.3**
96+
* Update the code to the new structure of transaction responses
97+
9598
**0.6.3.1**
9699
* Update the code to the new structure of transaction simulation responses
97100

examples/exchange_client/explorer_rpc/1_GetTxByHash.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,22 @@
22
import logging
33

44
from pyinjective.async_client import AsyncClient
5+
from pyinjective.composer import Composer
56
from pyinjective.constant import Network
67

78
async def main() -> None:
89
# select network: local, testnet, mainnet
910
network = Network.testnet()
1011
client = AsyncClient(network, insecure=False)
12+
composer = Composer(network=network.string())
1113
tx_hash = "0F3EBEC1882E1EEAC5B7BDD836E976250F1CD072B79485877CEACCB92ACDDF52"
12-
account = await client.get_tx_by_hash(tx_hash=tx_hash)
13-
print(account)
14+
transaction_response = await client.get_tx_by_hash(tx_hash=tx_hash)
15+
print(transaction_response)
16+
17+
transaction_messages = composer.UnpackTransactionMessages(transaction=transaction_response.data)
18+
print(transaction_messages)
19+
first_message = transaction_messages[0]
20+
print(first_message)
1421

1522
if __name__ == '__main__':
1623
asyncio.get_event_loop().run_until_complete(main())

examples/exchange_client/explorer_rpc/2_AccountTxs.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@
22
import logging
33

44
from pyinjective.async_client import AsyncClient
5+
from pyinjective.composer import Composer
56
from pyinjective.constant import Network
67

78
async def main() -> None:
89
# select network: local, testnet, mainnet
910
network = Network.testnet()
1011
client = AsyncClient(network, insecure=False)
12+
composer = Composer(network=network.string())
1113
address = "inj1phd706jqzd9wznkk5hgsfkrc8jqxv0kmlj0kex"
12-
type = "cosmos.bank.v1beta1.MsgSend"
14+
message_type = "cosmos.bank.v1beta1.MsgSend"
1315
limit = 2
14-
account = await client.get_account_txs(address=address, type=type, limit=limit)
15-
print(account)
16+
transactions_response = await client.get_account_txs(address=address, type=message_type, limit=limit)
17+
print(transactions_response)
18+
first_transaction_messages = composer.UnpackTransactionMessages(transaction=transactions_response.data[0])
19+
print(first_transaction_messages)
20+
first_message = first_transaction_messages[0]
21+
print(first_message)
1622

1723
if __name__ == '__main__':
1824
asyncio.get_event_loop().run_until_complete(main())

pyinjective/composer.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import json
33
import logging
44

5-
from google.protobuf import any_pb2, message, timestamp_pb2
5+
from google.protobuf import any_pb2, timestamp_pb2, json_format
66

77
from .proto.cosmos.authz.v1beta1 import authz_pb2 as cosmos_authz_pb
88
from .proto.cosmos.authz.v1beta1 import tx_pb2 as cosmos_authz_tx_pb
@@ -13,7 +13,6 @@
1313

1414
from .proto.injective.exchange.v1beta1 import tx_pb2 as injective_exchange_tx_pb
1515
from pyinjective.proto.injective.exchange.v1beta1 import exchange_pb2 as injective_dot_exchange_dot_v1beta1_dot_exchange__pb2
16-
from .proto.injective.types.v1beta1 import tx_response_pb2 as tx_response_pb
1716

1817
from .proto.injective.auction.v1beta1 import tx_pb2 as injective_auction_tx_pb
1918

@@ -958,3 +957,45 @@ def UnpackMsgExecResponse(msg_type, data):
958957

959958
responses = [header_map[msg_type].FromString(result) for result in data.results]
960959
return responses
960+
961+
@staticmethod
962+
def UnpackTransactionMessages(transaction):
963+
meta_messages = json.loads(transaction.messages.decode())
964+
965+
header_map = {
966+
"/injective.exchange.v1beta1.MsgCreateSpotLimitOrder": injective_exchange_tx_pb.MsgCreateSpotLimitOrderResponse,
967+
"/injective.exchange.v1beta1.MsgCreateSpotMarketOrder": injective_exchange_tx_pb.MsgCreateSpotMarketOrderResponse,
968+
"/injective.exchange.v1beta1.MsgCreateDerivativeLimitOrder": injective_exchange_tx_pb.MsgCreateDerivativeLimitOrderResponse,
969+
"/injective.exchange.v1beta1.MsgCreateDerivativeMarketOrder": injective_exchange_tx_pb.MsgCreateDerivativeMarketOrderResponse,
970+
"/injective.exchange.v1beta1.MsgCancelSpotOrder": injective_exchange_tx_pb.MsgCancelSpotOrderResponse,
971+
"/injective.exchange.v1beta1.MsgCancelDerivativeOrder": injective_exchange_tx_pb.MsgCancelDerivativeOrderResponse,
972+
"/injective.exchange.v1beta1.MsgBatchCancelSpotOrders": injective_exchange_tx_pb.MsgBatchCancelSpotOrdersResponse,
973+
"/injective.exchange.v1beta1.MsgBatchCancelDerivativeOrders": injective_exchange_tx_pb.MsgBatchCancelDerivativeOrdersResponse,
974+
"/injective.exchange.v1beta1.MsgBatchCreateSpotLimitOrders": injective_exchange_tx_pb.MsgBatchCreateSpotLimitOrders,
975+
"/injective.exchange.v1beta1.MsgBatchCreateDerivativeLimitOrders": injective_exchange_tx_pb.MsgBatchCreateDerivativeLimitOrders,
976+
"/injective.exchange.v1beta1.MsgBatchUpdateOrders": injective_exchange_tx_pb.MsgBatchUpdateOrders,
977+
"/injective.exchange.v1beta1.MsgDeposit": injective_exchange_tx_pb.MsgDeposit,
978+
"/injective.exchange.v1beta1.MsgWithdraw": injective_exchange_tx_pb.MsgWithdraw,
979+
"/injective.exchange.v1beta1.MsgSubaccountTransfer": injective_exchange_tx_pb.MsgSubaccountTransfer,
980+
"/injective.exchange.v1beta1.MsgLiquidatePosition": injective_exchange_tx_pb.MsgLiquidatePosition,
981+
"/injective.exchange.v1beta1.MsgIncreasePositionMargin": injective_exchange_tx_pb.MsgIncreasePositionMargin,
982+
"/injective.auction.v1beta1.MsgBid": injective_auction_tx_pb.MsgBid,
983+
"/injective.exchange.v1beta1.MsgCreateBinaryOptionsLimitOrder": injective_exchange_tx_pb.MsgCreateBinaryOptionsLimitOrder,
984+
"/injective.exchange.v1beta1.MsgCreateBinaryOptionsMarketOrder": injective_exchange_tx_pb.MsgCreateBinaryOptionsMarketOrder,
985+
"/injective.exchange.v1beta1.MsgCancelBinaryOptionsOrder": injective_exchange_tx_pb.MsgCancelBinaryOptionsOrder,
986+
"/injective.exchange.v1beta1.MsgAdminUpdateBinaryOptionsMarket": injective_exchange_tx_pb.MsgAdminUpdateBinaryOptionsMarket,
987+
"/injective.exchange.v1beta1.MsgInstantBinaryOptionsMarketLaunch": injective_exchange_tx_pb.MsgInstantBinaryOptionsMarketLaunch,
988+
"/cosmos.bank.v1beta1.MsgSend": cosmos_bank_tx_pb.MsgSend,
989+
"/cosmos.authz.v1beta1.MsgGrant": cosmos_authz_tx_pb.MsgGrant,
990+
"/cosmos.authz.v1beta1.MsgExec": cosmos_authz_tx_pb.MsgExec,
991+
"/cosmos.authz.v1beta1.MsgRevoke": cosmos_authz_tx_pb.MsgRevoke,
992+
"/injective.oracle.v1beta1.MsgRelayPriceFeedPrice": injective_oracle_tx_pb.MsgRelayPriceFeedPrice,
993+
"/injective.oracle.v1beta1.MsgRelayProviderPrices": injective_oracle_tx_pb.MsgRelayProviderPrices,
994+
}
995+
996+
msgs = []
997+
for msg in meta_messages:
998+
msg_as_string_dict = json.dumps(msg["value"])
999+
msgs.append(json_format.Parse(msg_as_string_dict, header_map[msg["type"]]()))
1000+
1001+
return msgs

pyinjective/transaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def with_messages(self, *msgs: message.Message) -> "Transaction":
4646

4747
def with_sender(self, client: Client, sender: str) -> "Transaction":
4848
if len(self.msgs) == 0:
49-
raise EmptyMsgError("messsage is empty, please use with_messages at least 1 message")
49+
raise EmptyMsgError("message is empty, please use with_messages at least 1 message")
5050
account = client.get_account(sender)
5151
if account:
5252
self.account_num = account.account_number

0 commit comments

Comments
 (0)