Skip to content

Commit 86484cb

Browse files
author
abel
committed
Merge branch 'dev' of https://github.com/InjectiveLabs/sdk-python into feat/refactor_markets_and_tokens
2 parents 6dedca5 + 308b5fc commit 86484cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+916
-916
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ copy-proto:
2121
mkdir -p proto/exchange
2222
buf export buf.build/cosmos/cosmos-sdk:v0.47.0 --output=third_party
2323
buf export https://github.com/cosmos/ibc-go.git --exclude-imports --output=third_party
24-
buf export https://github.com/tendermint/tendermint.git --exclude-imports --output=third_party
24+
buf export https://github.com/cometbft/cometbft.git --exclude-imports --output=third_party
2525
buf export https://github.com/CosmWasm/wasmd.git --exclude-imports --output=./third_party
2626
buf export https://github.com/cosmos/ics23.git --exclude-imports --output=./third_party
2727

Pipfile.lock

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

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,27 @@ make tests
8787
```
8888

8989
### Changelogs
90-
**0.7**(change before release)
90+
**0.7.1**(change before release)
9191
* Refactor Composer to be created with all the markets and tokens. The Composer now uses the real markets and tokens to convert human-readable values to chain format
9292
* The Composer can still be instantiated without markets and tokens. When markets and tokens are not provided the Composer loads the required information from the Denoms used in previous versions
9393
* Change in AsyncClient to be able to create Composer instances for the client network, markets and tokens
9494
* Examples have been adapted to create Composer instances using the AsyncClient
9595

96+
**0.7**
97+
* Removed references to pysha3 library (and also eip712-struct that required it) and replaced it with other implementation to allow the project to work with Python 3.11
98+
* Updated sentry nodes LCD URL, for each sentry node to use its own service
99+
100+
**0.6.5**
101+
* Removed `k8s` from the list of supported mainnet nodes (`lb` should be used instead)
102+
96103
**0.6.4**
97104
* Change logging logic to use different loggers for each module and class
98105
* Solved issue preventing requesting spot and derivative historical orders for more than one market_id
99-
* Removed references to pysha3 library (and also eip712-struct that required it) and replaced it with other implementation to allow the project to work with Python 3.11
100106
* Add `pytest` as a development dependency to implement and run unit tests
101107

108+
**0.6.3.3**
109+
* Update the code to the new structure of transaction responses
110+
102111
**0.6.3.1**
103112
* Update the code to the new structure of transaction simulation responses
104113

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
from decimal import Decimal
33
from time import time
44

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

77
from .core.market import BinaryOptionMarket, DerivativeMarket, SpotMarket
88
from .core.token import Token
@@ -15,7 +15,6 @@
1515

1616
from .proto.injective.exchange.v1beta1 import tx_pb2 as injective_exchange_tx_pb
1717
from pyinjective.proto.injective.exchange.v1beta1 import exchange_pb2 as injective_dot_exchange_dot_v1beta1_dot_exchange__pb2
18-
from .proto.injective.types.v1beta1 import tx_response_pb2 as tx_response_pb
1918

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

@@ -966,6 +965,48 @@ def UnpackMsgExecResponse(msg_type, data):
966965
responses = [header_map[msg_type].FromString(result) for result in data.results]
967966
return responses
968967

968+
@staticmethod
969+
def UnpackTransactionMessages(transaction):
970+
meta_messages = json.loads(transaction.messages.decode())
971+
972+
header_map = {
973+
"/injective.exchange.v1beta1.MsgCreateSpotLimitOrder": injective_exchange_tx_pb.MsgCreateSpotLimitOrderResponse,
974+
"/injective.exchange.v1beta1.MsgCreateSpotMarketOrder": injective_exchange_tx_pb.MsgCreateSpotMarketOrderResponse,
975+
"/injective.exchange.v1beta1.MsgCreateDerivativeLimitOrder": injective_exchange_tx_pb.MsgCreateDerivativeLimitOrderResponse,
976+
"/injective.exchange.v1beta1.MsgCreateDerivativeMarketOrder": injective_exchange_tx_pb.MsgCreateDerivativeMarketOrderResponse,
977+
"/injective.exchange.v1beta1.MsgCancelSpotOrder": injective_exchange_tx_pb.MsgCancelSpotOrderResponse,
978+
"/injective.exchange.v1beta1.MsgCancelDerivativeOrder": injective_exchange_tx_pb.MsgCancelDerivativeOrderResponse,
979+
"/injective.exchange.v1beta1.MsgBatchCancelSpotOrders": injective_exchange_tx_pb.MsgBatchCancelSpotOrdersResponse,
980+
"/injective.exchange.v1beta1.MsgBatchCancelDerivativeOrders": injective_exchange_tx_pb.MsgBatchCancelDerivativeOrdersResponse,
981+
"/injective.exchange.v1beta1.MsgBatchCreateSpotLimitOrders": injective_exchange_tx_pb.MsgBatchCreateSpotLimitOrders,
982+
"/injective.exchange.v1beta1.MsgBatchCreateDerivativeLimitOrders": injective_exchange_tx_pb.MsgBatchCreateDerivativeLimitOrders,
983+
"/injective.exchange.v1beta1.MsgBatchUpdateOrders": injective_exchange_tx_pb.MsgBatchUpdateOrders,
984+
"/injective.exchange.v1beta1.MsgDeposit": injective_exchange_tx_pb.MsgDeposit,
985+
"/injective.exchange.v1beta1.MsgWithdraw": injective_exchange_tx_pb.MsgWithdraw,
986+
"/injective.exchange.v1beta1.MsgSubaccountTransfer": injective_exchange_tx_pb.MsgSubaccountTransfer,
987+
"/injective.exchange.v1beta1.MsgLiquidatePosition": injective_exchange_tx_pb.MsgLiquidatePosition,
988+
"/injective.exchange.v1beta1.MsgIncreasePositionMargin": injective_exchange_tx_pb.MsgIncreasePositionMargin,
989+
"/injective.auction.v1beta1.MsgBid": injective_auction_tx_pb.MsgBid,
990+
"/injective.exchange.v1beta1.MsgCreateBinaryOptionsLimitOrder": injective_exchange_tx_pb.MsgCreateBinaryOptionsLimitOrder,
991+
"/injective.exchange.v1beta1.MsgCreateBinaryOptionsMarketOrder": injective_exchange_tx_pb.MsgCreateBinaryOptionsMarketOrder,
992+
"/injective.exchange.v1beta1.MsgCancelBinaryOptionsOrder": injective_exchange_tx_pb.MsgCancelBinaryOptionsOrder,
993+
"/injective.exchange.v1beta1.MsgAdminUpdateBinaryOptionsMarket": injective_exchange_tx_pb.MsgAdminUpdateBinaryOptionsMarket,
994+
"/injective.exchange.v1beta1.MsgInstantBinaryOptionsMarketLaunch": injective_exchange_tx_pb.MsgInstantBinaryOptionsMarketLaunch,
995+
"/cosmos.bank.v1beta1.MsgSend": cosmos_bank_tx_pb.MsgSend,
996+
"/cosmos.authz.v1beta1.MsgGrant": cosmos_authz_tx_pb.MsgGrant,
997+
"/cosmos.authz.v1beta1.MsgExec": cosmos_authz_tx_pb.MsgExec,
998+
"/cosmos.authz.v1beta1.MsgRevoke": cosmos_authz_tx_pb.MsgRevoke,
999+
"/injective.oracle.v1beta1.MsgRelayPriceFeedPrice": injective_oracle_tx_pb.MsgRelayPriceFeedPrice,
1000+
"/injective.oracle.v1beta1.MsgRelayProviderPrices": injective_oracle_tx_pb.MsgRelayProviderPrices,
1001+
}
1002+
1003+
msgs = []
1004+
for msg in meta_messages:
1005+
msg_as_string_dict = json.dumps(msg["value"])
1006+
msgs.append(json_format.Parse(msg_as_string_dict, header_map[msg["type"]]()))
1007+
1008+
return msgs
1009+
9691010
def _initialize_markets_and_tokens_from_files(self):
9701011
config: ConfigParser = constant.CONFIGS[self.network]
9711012
spot_markets = dict()

pyinjective/constant.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ def testnet(cls):
121121
@classmethod
122122
def mainnet(cls, node='lb'):
123123
nodes = [
124-
'k8s', # us, prod
125124
'lb', # us, asia, prod
126125
'sentry0', # ca, prod
127126
'sentry1', # ca, prod
@@ -137,7 +136,7 @@ def mainnet(cls, node='lb'):
137136
grpc_exchange_endpoint = 'k8s.global.mainnet.exchange.grpc.injective.network:443'
138137
grpc_explorer_endpoint = 'k8s.global.mainnet.explorer.grpc.injective.network:443'
139138
else:
140-
lcd_endpoint='https://lcd.injective.network'
139+
lcd_endpoint=f'http://{node}.injective.network:10337'
141140
tm_websocket_endpoint=f'ws://{node}.injective.network:26657/websocket'
142141
grpc_endpoint=f'{node}.injective.network:9900'
143142
grpc_exchange_endpoint=f'{node}.injective.network:9910'

pyinjective/proto/cosmos/base/store/v1beta1/commit_info_pb2.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

pyinjective/proto/cosmos/base/store/v1beta1/commit_info_pb2_grpc.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

pyinjective/proto/cosmos/base/store/v1beta1/listening_pb2.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)