Skip to content

Commit 7b85dbb

Browse files
Merge pull request #212 from InjectiveLabs/fix/adapt_code_to_transaction_responses_v046
fix/adapt code to transaction responses v046
2 parents 5dce67a + 81ca1ef commit 7b85dbb

File tree

8 files changed

+76
-41
lines changed

8 files changed

+76
-41
lines changed

Pipfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ urllib3 = "<2"
2424
[dev-packages]
2525

2626
[requires]
27-
python_version = "3.8"
27+
python_version = "3.9"

Pipfile.lock

Lines changed: 9 additions & 31 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
@@ -78,6 +78,9 @@ Note that the [sync client](https://github.com/InjectiveLabs/sdk-python/blob/mas
7878

7979

8080
### Changelogs
81+
**0.6.3.3**
82+
* Update the code to the new structure of transaction responses
83+
8184
**0.6.3.1**
8285
* Update the code to the new structure of transaction simulation responses
8386

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
logging.basicConfig(level=logging.INFO)

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
logging.basicConfig(level=logging.INFO)

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

@@ -969,3 +968,45 @@ def UnpackMsgExecResponse(msg_type, data):
969968

970969
responses = [header_map[msg_type].FromString(result) for result in data.results]
971970
return responses
971+
972+
@staticmethod
973+
def UnpackTransactionMessages(transaction):
974+
meta_messages = json.loads(transaction.messages.decode())
975+
976+
header_map = {
977+
"/injective.exchange.v1beta1.MsgCreateSpotLimitOrder": injective_exchange_tx_pb.MsgCreateSpotLimitOrderResponse,
978+
"/injective.exchange.v1beta1.MsgCreateSpotMarketOrder": injective_exchange_tx_pb.MsgCreateSpotMarketOrderResponse,
979+
"/injective.exchange.v1beta1.MsgCreateDerivativeLimitOrder": injective_exchange_tx_pb.MsgCreateDerivativeLimitOrderResponse,
980+
"/injective.exchange.v1beta1.MsgCreateDerivativeMarketOrder": injective_exchange_tx_pb.MsgCreateDerivativeMarketOrderResponse,
981+
"/injective.exchange.v1beta1.MsgCancelSpotOrder": injective_exchange_tx_pb.MsgCancelSpotOrderResponse,
982+
"/injective.exchange.v1beta1.MsgCancelDerivativeOrder": injective_exchange_tx_pb.MsgCancelDerivativeOrderResponse,
983+
"/injective.exchange.v1beta1.MsgBatchCancelSpotOrders": injective_exchange_tx_pb.MsgBatchCancelSpotOrdersResponse,
984+
"/injective.exchange.v1beta1.MsgBatchCancelDerivativeOrders": injective_exchange_tx_pb.MsgBatchCancelDerivativeOrdersResponse,
985+
"/injective.exchange.v1beta1.MsgBatchCreateSpotLimitOrders": injective_exchange_tx_pb.MsgBatchCreateSpotLimitOrders,
986+
"/injective.exchange.v1beta1.MsgBatchCreateDerivativeLimitOrders": injective_exchange_tx_pb.MsgBatchCreateDerivativeLimitOrders,
987+
"/injective.exchange.v1beta1.MsgBatchUpdateOrders": injective_exchange_tx_pb.MsgBatchUpdateOrders,
988+
"/injective.exchange.v1beta1.MsgDeposit": injective_exchange_tx_pb.MsgDeposit,
989+
"/injective.exchange.v1beta1.MsgWithdraw": injective_exchange_tx_pb.MsgWithdraw,
990+
"/injective.exchange.v1beta1.MsgSubaccountTransfer": injective_exchange_tx_pb.MsgSubaccountTransfer,
991+
"/injective.exchange.v1beta1.MsgLiquidatePosition": injective_exchange_tx_pb.MsgLiquidatePosition,
992+
"/injective.exchange.v1beta1.MsgIncreasePositionMargin": injective_exchange_tx_pb.MsgIncreasePositionMargin,
993+
"/injective.auction.v1beta1.MsgBid": injective_auction_tx_pb.MsgBid,
994+
"/injective.exchange.v1beta1.MsgCreateBinaryOptionsLimitOrder": injective_exchange_tx_pb.MsgCreateBinaryOptionsLimitOrder,
995+
"/injective.exchange.v1beta1.MsgCreateBinaryOptionsMarketOrder": injective_exchange_tx_pb.MsgCreateBinaryOptionsMarketOrder,
996+
"/injective.exchange.v1beta1.MsgCancelBinaryOptionsOrder": injective_exchange_tx_pb.MsgCancelBinaryOptionsOrder,
997+
"/injective.exchange.v1beta1.MsgAdminUpdateBinaryOptionsMarket": injective_exchange_tx_pb.MsgAdminUpdateBinaryOptionsMarket,
998+
"/injective.exchange.v1beta1.MsgInstantBinaryOptionsMarketLaunch": injective_exchange_tx_pb.MsgInstantBinaryOptionsMarketLaunch,
999+
"/cosmos.bank.v1beta1.MsgSend": cosmos_bank_tx_pb.MsgSend,
1000+
"/cosmos.authz.v1beta1.MsgGrant": cosmos_authz_tx_pb.MsgGrant,
1001+
"/cosmos.authz.v1beta1.MsgExec": cosmos_authz_tx_pb.MsgExec,
1002+
"/cosmos.authz.v1beta1.MsgRevoke": cosmos_authz_tx_pb.MsgRevoke,
1003+
"/injective.oracle.v1beta1.MsgRelayPriceFeedPrice": injective_oracle_tx_pb.MsgRelayPriceFeedPrice,
1004+
"/injective.oracle.v1beta1.MsgRelayProviderPrices": injective_oracle_tx_pb.MsgRelayProviderPrices,
1005+
}
1006+
1007+
msgs = []
1008+
for msg in meta_messages:
1009+
msg_as_string_dict = json.dumps(msg["value"])
1010+
msgs.append(json_format.Parse(msg_as_string_dict, header_map[msg["type"]]()))
1011+
1012+
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

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
1818
AUTHOR = "Injective Labs"
1919
REQUIRES_PYTHON = ">=3.7.0"
20-
VERSION = "0.6.3.2"
20+
VERSION = "0.6.3.3"
2121

2222
REQUIRED = [
2323
"protobuf",

0 commit comments

Comments
 (0)