-
Notifications
You must be signed in to change notification settings - Fork 34
feat/ibc_client_module_queries #321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is the same, only using a non private name. Or is it a different module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, in the end it is the same. I just feel it is better to use the general class