-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #321 from InjectiveLabs/feat/ibc_client_module_que…
…ries feat/ibc_client_module_queries
- Loading branch information
Showing
20 changed files
with
1,035 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import asyncio | ||
|
||
from google.protobuf import symbol_database | ||
|
||
from pyinjective.async_client import AsyncClient | ||
from pyinjective.core.network import Network | ||
|
||
|
||
async def main() -> None: | ||
network = Network.testnet() | ||
client = AsyncClient(network) | ||
|
||
client_id = "07-tendermint-0" | ||
|
||
state = await client.fetch_ibc_client_state(client_id=client_id) | ||
print(state) | ||
|
||
|
||
if __name__ == "__main__": | ||
symbol_db = symbol_database.Default() | ||
asyncio.get_event_loop().run_until_complete(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import asyncio | ||
|
||
from google.protobuf import symbol_database | ||
|
||
from pyinjective.async_client import AsyncClient | ||
from pyinjective.client.model.pagination import PaginationOption | ||
from pyinjective.core.network import Network | ||
|
||
|
||
async def main() -> None: | ||
network = Network.testnet() | ||
client = AsyncClient(network) | ||
|
||
pagination = PaginationOption(skip=2, limit=4) | ||
|
||
states = await client.fetch_ibc_client_states(pagination=pagination) | ||
print(states) | ||
|
||
|
||
if __name__ == "__main__": | ||
symbol_db = symbol_database.Default() | ||
asyncio.get_event_loop().run_until_complete(main()) |
25 changes: 25 additions & 0 deletions
25
examples/chain_client/ibc/client/query/3_ConsensusState.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import asyncio | ||
|
||
from google.protobuf import symbol_database | ||
|
||
from pyinjective.async_client import AsyncClient | ||
from pyinjective.core.network import Network | ||
|
||
|
||
async def main() -> None: | ||
network = Network.testnet() | ||
client = AsyncClient(network) | ||
|
||
client_id = "07-tendermint-0" | ||
revision_number = 0 | ||
revision_height = 7379538 | ||
|
||
state = await client.fetch_ibc_consensus_state( | ||
client_id=client_id, revision_number=revision_number, revision_height=revision_height | ||
) | ||
print(state) | ||
|
||
|
||
if __name__ == "__main__": | ||
symbol_db = symbol_database.Default() | ||
asyncio.get_event_loop().run_until_complete(main()) |
23 changes: 23 additions & 0 deletions
23
examples/chain_client/ibc/client/query/4_ConsensusStates.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import asyncio | ||
|
||
from google.protobuf import symbol_database | ||
|
||
from pyinjective.async_client import AsyncClient | ||
from pyinjective.client.model.pagination import PaginationOption | ||
from pyinjective.core.network import Network | ||
|
||
|
||
async def main() -> None: | ||
network = Network.testnet() | ||
client = AsyncClient(network) | ||
|
||
client_id = "07-tendermint-0" | ||
pagination = PaginationOption(skip=2, limit=4) | ||
|
||
states = await client.fetch_ibc_consensus_states(client_id=client_id, pagination=pagination) | ||
print(states) | ||
|
||
|
||
if __name__ == "__main__": | ||
symbol_db = symbol_database.Default() | ||
asyncio.get_event_loop().run_until_complete(main()) |
23 changes: 23 additions & 0 deletions
23
examples/chain_client/ibc/client/query/5_ConsensusStateHeights.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import asyncio | ||
|
||
from google.protobuf import symbol_database | ||
|
||
from pyinjective.async_client import AsyncClient | ||
from pyinjective.client.model.pagination import PaginationOption | ||
from pyinjective.core.network import Network | ||
|
||
|
||
async def main() -> None: | ||
network = Network.testnet() | ||
client = AsyncClient(network) | ||
|
||
client_id = "07-tendermint-0" | ||
pagination = PaginationOption(skip=2, limit=4) | ||
|
||
states = await client.fetch_ibc_consensus_state_heights(client_id=client_id, pagination=pagination) | ||
print(states) | ||
|
||
|
||
if __name__ == "__main__": | ||
symbol_db = symbol_database.Default() | ||
asyncio.get_event_loop().run_until_complete(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import asyncio | ||
|
||
from google.protobuf import symbol_database | ||
|
||
from pyinjective.async_client import AsyncClient | ||
from pyinjective.core.network import Network | ||
|
||
|
||
async def main() -> None: | ||
network = Network.testnet() | ||
client = AsyncClient(network) | ||
|
||
client_id = "07-tendermint-0" | ||
|
||
state = await client.fetch_ibc_client_status(client_id=client_id) | ||
print(state) | ||
|
||
|
||
if __name__ == "__main__": | ||
symbol_db = symbol_database.Default() | ||
asyncio.get_event_loop().run_until_complete(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import asyncio | ||
|
||
from google.protobuf import symbol_database | ||
|
||
from pyinjective.async_client import AsyncClient | ||
from pyinjective.core.network import Network | ||
|
||
|
||
async def main() -> None: | ||
network = Network.testnet() | ||
client = AsyncClient(network) | ||
|
||
params = await client.fetch_ibc_client_params() | ||
print(params) | ||
|
||
|
||
if __name__ == "__main__": | ||
symbol_db = symbol_database.Default() | ||
asyncio.get_event_loop().run_until_complete(main()) |
19 changes: 19 additions & 0 deletions
19
examples/chain_client/ibc/client/query/8_UpgradedClientState.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import asyncio | ||
|
||
from google.protobuf import symbol_database | ||
|
||
from pyinjective.async_client import AsyncClient | ||
from pyinjective.core.network import Network | ||
|
||
|
||
async def main() -> None: | ||
network = Network.testnet() | ||
client = AsyncClient(network) | ||
|
||
state = await client.fetch_ibc_upgraded_client_state() | ||
print(state) | ||
|
||
|
||
if __name__ == "__main__": | ||
symbol_db = symbol_database.Default() | ||
asyncio.get_event_loop().run_until_complete(main()) |
19 changes: 19 additions & 0 deletions
19
examples/chain_client/ibc/client/query/9_UpgradedConsensusState.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import asyncio | ||
|
||
from google.protobuf import symbol_database | ||
|
||
from pyinjective.async_client import AsyncClient | ||
from pyinjective.core.network import Network | ||
|
||
|
||
async def main() -> None: | ||
network = Network.testnet() | ||
client = AsyncClient(network) | ||
|
||
state = await client.fetch_ibc_upgraded_consensus_state() | ||
print(state) | ||
|
||
|
||
if __name__ == "__main__": | ||
symbol_db = symbol_database.Default() | ||
asyncio.get_event_loop().run_until_complete(main()) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
from typing import Any, Callable, Dict, Optional | ||
|
||
from grpc import Channel | ||
|
||
from pyinjective.client.model.pagination import PaginationOption | ||
from pyinjective.core.network import CookieAssistant | ||
from pyinjective.proto.ibc.core.client.v1 import query_pb2 as ibc_client_query, query_pb2_grpc as ibc_client_query_grpc | ||
from pyinjective.utils.grpc_api_request_assistant import GrpcApiRequestAssistant | ||
|
||
|
||
class IBCClientGrpcApi: | ||
def __init__(self, channel: Channel, cookie_assistant: CookieAssistant): | ||
self._stub = ibc_client_query_grpc.QueryStub(channel) | ||
self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant) | ||
|
||
async def fetch_client_state(self, client_id: str) -> Dict[str, Any]: | ||
request = ibc_client_query.QueryClientStateRequest(client_id=client_id) | ||
response = await self._execute_call(call=self._stub.ClientState, request=request) | ||
|
||
return response | ||
|
||
async def fetch_client_states(self, pagination: Optional[PaginationOption] = None) -> Dict[str, Any]: | ||
if pagination is None: | ||
pagination = PaginationOption() | ||
request = ibc_client_query.QueryClientStatesRequest(pagination=pagination.create_pagination_request()) | ||
response = await self._execute_call(call=self._stub.ClientStates, request=request) | ||
|
||
return response | ||
|
||
async def fetch_consensus_state( | ||
self, | ||
client_id: str, | ||
revision_number: int, | ||
revision_height: int, | ||
latest_height: Optional[bool] = None, | ||
) -> Dict[str, Any]: | ||
request = ibc_client_query.QueryConsensusStateRequest( | ||
client_id=client_id, | ||
revision_number=revision_number, | ||
revision_height=revision_height, | ||
latest_height=latest_height, | ||
) | ||
response = await self._execute_call(call=self._stub.ConsensusState, request=request) | ||
|
||
return response | ||
|
||
async def fetch_consensus_states( | ||
self, client_id: str, pagination: Optional[PaginationOption] = None | ||
) -> Dict[str, Any]: | ||
if pagination is None: | ||
pagination = PaginationOption() | ||
request = ibc_client_query.QueryConsensusStatesRequest( | ||
client_id=client_id, pagination=pagination.create_pagination_request() | ||
) | ||
response = await self._execute_call(call=self._stub.ConsensusStates, request=request) | ||
|
||
return response | ||
|
||
async def fetch_consensus_state_heights( | ||
self, client_id: str, pagination: Optional[PaginationOption] = None | ||
) -> Dict[str, Any]: | ||
if pagination is None: | ||
pagination = PaginationOption() | ||
request = ibc_client_query.QueryConsensusStateHeightsRequest( | ||
client_id=client_id, pagination=pagination.create_pagination_request() | ||
) | ||
response = await self._execute_call(call=self._stub.ConsensusStateHeights, request=request) | ||
|
||
return response | ||
|
||
async def fetch_client_status(self, client_id: str) -> Dict[str, Any]: | ||
request = ibc_client_query.QueryClientStatusRequest(client_id=client_id) | ||
response = await self._execute_call(call=self._stub.ClientStatus, request=request) | ||
|
||
return response | ||
|
||
async def fetch_client_params(self) -> Dict[str, Any]: | ||
request = ibc_client_query.QueryClientParamsRequest() | ||
response = await self._execute_call(call=self._stub.ClientParams, request=request) | ||
|
||
return response | ||
|
||
async def fetch_upgraded_client_state(self) -> Dict[str, Any]: | ||
request = ibc_client_query.QueryUpgradedClientStateRequest() | ||
response = await self._execute_call(call=self._stub.UpgradedClientState, request=request) | ||
|
||
return response | ||
|
||
async def fetch_upgraded_consensus_state(self) -> Dict[str, Any]: | ||
request = ibc_client_query.QueryUpgradedConsensusStateRequest() | ||
response = await self._execute_call(call=self._stub.UpgradedConsensusState, request=request) | ||
|
||
return response | ||
|
||
async def _execute_call(self, call: Callable, request) -> Dict[str, Any]: | ||
return await self._assistant.execute_call(call=call, request=request) |
Empty file.
Empty file.
Oops, something went wrong.