Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ urllib3 = "<2"
[dev-packages]

[requires]
python_version = "3.8"
python_version = "3.9"
40 changes: 9 additions & 31 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ Note that the [sync client](https://github.com/InjectiveLabs/sdk-python/blob/mas


### Changelogs
**0.6.3.3**
* Update the code to the new structure of transaction responses

**0.6.3.1**
* Update the code to the new structure of transaction simulation responses

Expand Down
11 changes: 9 additions & 2 deletions examples/exchange_client/explorer_rpc/1_GetTxByHash.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@
import logging

from pyinjective.async_client import AsyncClient
from pyinjective.composer import Composer
from pyinjective.constant import Network

async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
client = AsyncClient(network, insecure=False)
composer = Composer(network=network.string())
tx_hash = "0F3EBEC1882E1EEAC5B7BDD836E976250F1CD072B79485877CEACCB92ACDDF52"
account = await client.get_tx_by_hash(tx_hash=tx_hash)
print(account)
transaction_response = await client.get_tx_by_hash(tx_hash=tx_hash)
print(transaction_response)

transaction_messages = composer.UnpackTransactionMessages(transaction=transaction_response.data)
print(transaction_messages)
first_message = transaction_messages[0]
print(first_message)

if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
Expand Down
12 changes: 9 additions & 3 deletions examples/exchange_client/explorer_rpc/2_AccountTxs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@
import logging

from pyinjective.async_client import AsyncClient
from pyinjective.composer import Composer
from pyinjective.constant import Network

async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
client = AsyncClient(network, insecure=False)
composer = Composer(network=network.string())
address = "inj1phd706jqzd9wznkk5hgsfkrc8jqxv0kmlj0kex"
type = "cosmos.bank.v1beta1.MsgSend"
message_type = "cosmos.bank.v1beta1.MsgSend"
limit = 2
account = await client.get_account_txs(address=address, type=type, limit=limit)
print(account)
transactions_response = await client.get_account_txs(address=address, type=message_type, limit=limit)
print(transactions_response)
first_transaction_messages = composer.UnpackTransactionMessages(transaction=transactions_response.data[0])
print(first_transaction_messages)
first_message = first_transaction_messages[0]
print(first_message)

if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
Expand Down
45 changes: 43 additions & 2 deletions pyinjective/composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
import logging

from google.protobuf import any_pb2, message, timestamp_pb2
from google.protobuf import any_pb2, timestamp_pb2, json_format

from .proto.cosmos.authz.v1beta1 import authz_pb2 as cosmos_authz_pb
from .proto.cosmos.authz.v1beta1 import tx_pb2 as cosmos_authz_tx_pb
Expand All @@ -13,7 +13,6 @@

from .proto.injective.exchange.v1beta1 import tx_pb2 as injective_exchange_tx_pb
from pyinjective.proto.injective.exchange.v1beta1 import exchange_pb2 as injective_dot_exchange_dot_v1beta1_dot_exchange__pb2
from .proto.injective.types.v1beta1 import tx_response_pb2 as tx_response_pb

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

Expand Down Expand Up @@ -969,3 +968,45 @@ def UnpackMsgExecResponse(msg_type, data):

responses = [header_map[msg_type].FromString(result) for result in data.results]
return responses

@staticmethod
def UnpackTransactionMessages(transaction):
meta_messages = json.loads(transaction.messages.decode())

header_map = {
"/injective.exchange.v1beta1.MsgCreateSpotLimitOrder": injective_exchange_tx_pb.MsgCreateSpotLimitOrderResponse,
"/injective.exchange.v1beta1.MsgCreateSpotMarketOrder": injective_exchange_tx_pb.MsgCreateSpotMarketOrderResponse,
"/injective.exchange.v1beta1.MsgCreateDerivativeLimitOrder": injective_exchange_tx_pb.MsgCreateDerivativeLimitOrderResponse,
"/injective.exchange.v1beta1.MsgCreateDerivativeMarketOrder": injective_exchange_tx_pb.MsgCreateDerivativeMarketOrderResponse,
"/injective.exchange.v1beta1.MsgCancelSpotOrder": injective_exchange_tx_pb.MsgCancelSpotOrderResponse,
"/injective.exchange.v1beta1.MsgCancelDerivativeOrder": injective_exchange_tx_pb.MsgCancelDerivativeOrderResponse,
"/injective.exchange.v1beta1.MsgBatchCancelSpotOrders": injective_exchange_tx_pb.MsgBatchCancelSpotOrdersResponse,
"/injective.exchange.v1beta1.MsgBatchCancelDerivativeOrders": injective_exchange_tx_pb.MsgBatchCancelDerivativeOrdersResponse,
"/injective.exchange.v1beta1.MsgBatchCreateSpotLimitOrders": injective_exchange_tx_pb.MsgBatchCreateSpotLimitOrders,
"/injective.exchange.v1beta1.MsgBatchCreateDerivativeLimitOrders": injective_exchange_tx_pb.MsgBatchCreateDerivativeLimitOrders,
"/injective.exchange.v1beta1.MsgBatchUpdateOrders": injective_exchange_tx_pb.MsgBatchUpdateOrders,
"/injective.exchange.v1beta1.MsgDeposit": injective_exchange_tx_pb.MsgDeposit,
"/injective.exchange.v1beta1.MsgWithdraw": injective_exchange_tx_pb.MsgWithdraw,
"/injective.exchange.v1beta1.MsgSubaccountTransfer": injective_exchange_tx_pb.MsgSubaccountTransfer,
"/injective.exchange.v1beta1.MsgLiquidatePosition": injective_exchange_tx_pb.MsgLiquidatePosition,
"/injective.exchange.v1beta1.MsgIncreasePositionMargin": injective_exchange_tx_pb.MsgIncreasePositionMargin,
"/injective.auction.v1beta1.MsgBid": injective_auction_tx_pb.MsgBid,
"/injective.exchange.v1beta1.MsgCreateBinaryOptionsLimitOrder": injective_exchange_tx_pb.MsgCreateBinaryOptionsLimitOrder,
"/injective.exchange.v1beta1.MsgCreateBinaryOptionsMarketOrder": injective_exchange_tx_pb.MsgCreateBinaryOptionsMarketOrder,
"/injective.exchange.v1beta1.MsgCancelBinaryOptionsOrder": injective_exchange_tx_pb.MsgCancelBinaryOptionsOrder,
"/injective.exchange.v1beta1.MsgAdminUpdateBinaryOptionsMarket": injective_exchange_tx_pb.MsgAdminUpdateBinaryOptionsMarket,
"/injective.exchange.v1beta1.MsgInstantBinaryOptionsMarketLaunch": injective_exchange_tx_pb.MsgInstantBinaryOptionsMarketLaunch,
"/cosmos.bank.v1beta1.MsgSend": cosmos_bank_tx_pb.MsgSend,
"/cosmos.authz.v1beta1.MsgGrant": cosmos_authz_tx_pb.MsgGrant,
"/cosmos.authz.v1beta1.MsgExec": cosmos_authz_tx_pb.MsgExec,
"/cosmos.authz.v1beta1.MsgRevoke": cosmos_authz_tx_pb.MsgRevoke,
"/injective.oracle.v1beta1.MsgRelayPriceFeedPrice": injective_oracle_tx_pb.MsgRelayPriceFeedPrice,
"/injective.oracle.v1beta1.MsgRelayProviderPrices": injective_oracle_tx_pb.MsgRelayProviderPrices,
}

msgs = []
for msg in meta_messages:
msg_as_string_dict = json.dumps(msg["value"])
msgs.append(json_format.Parse(msg_as_string_dict, header_map[msg["type"]]()))

return msgs
2 changes: 1 addition & 1 deletion pyinjective/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def with_messages(self, *msgs: message.Message) -> "Transaction":

def with_sender(self, client: Client, sender: str) -> "Transaction":
if len(self.msgs) == 0:
raise EmptyMsgError("messsage is empty, please use with_messages at least 1 message")
raise EmptyMsgError("message is empty, please use with_messages at least 1 message")
account = client.get_account(sender)
if account:
self.account_num = account.account_number
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
EMAIL = "achilleas@injectivelabs.com"
AUTHOR = "Injective Labs"
REQUIRES_PYTHON = ">=3.7.0"
VERSION = "0.6.3.2"
VERSION = "0.6.3.3"

REQUIRED = [
"protobuf",
Expand Down