-
Notifications
You must be signed in to change notification settings - Fork 30
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
feat/ibc_connection_module_queries #322
Changes from 1 commit
1c592e0
e185d46
961884a
58f62c2
0631678
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
|
||
connection_id = "connection-0" | ||
|
||
connection = await client.fetch_ibc_connection(connection_id=connection_id) | ||
print(connection) | ||
|
||
|
||
if __name__ == "__main__": | ||
symbol_db = symbol_database.Default() | ||
asyncio.get_event_loop().run_until_complete(main()) |
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) | ||
|
||
connections = await client.fetch_ibc_connections(pagination=pagination) | ||
print(connections) | ||
|
||
|
||
if __name__ == "__main__": | ||
symbol_db = symbol_database.Default() | ||
asyncio.get_event_loop().run_until_complete(main()) |
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" | ||
|
||
connections = await client.fetch_ibc_client_connections(client_id=client_id) | ||
print(connections) | ||
|
||
|
||
if __name__ == "__main__": | ||
symbol_db = symbol_database.Default() | ||
asyncio.get_event_loop().run_until_complete(main()) |
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) | ||
|
||
connection_id = "connection-0" | ||
|
||
state = await client.fetch_ibc_connection_client_state(connection_id=connection_id) | ||
print(state) | ||
|
||
|
||
if __name__ == "__main__": | ||
symbol_db = symbol_database.Default() | ||
asyncio.get_event_loop().run_until_complete(main()) |
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) | ||
|
||
connection_id = "connection-0" | ||
revision_number = 0 | ||
revision_height = 7379538 | ||
|
||
state = await client.fetch_ibc_connection_consensus_state( | ||
connection_id=connection_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()) |
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) | ||
|
||
connection_id = "connection-0" | ||
revision_number = 0 | ||
revision_height = 7379538 | ||
|
||
state = await client.fetch_ibc_connection_consensus_state( | ||
connection_id=connection_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()) | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
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.connection.v1 import ( | ||
query_pb2 as ibc_connection_query, | ||
query_pb2_grpc as ibc_connection_query_grpc, | ||
) | ||
from pyinjective.utils.grpc_api_request_assistant import GrpcApiRequestAssistant | ||
|
||
|
||
class IBCConnectionGrpcApi: | ||
def __init__(self, channel: Channel, cookie_assistant: CookieAssistant): | ||
self._stub = ibc_connection_query_grpc.QueryStub(channel) | ||
self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant) | ||
|
||
async def fetch_connection(self, connection_id: str) -> Dict[str, Any]: | ||
request = ibc_connection_query.QueryConnectionRequest(connection_id=connection_id) | ||
response = await self._execute_call(call=self._stub.Connection, request=request) | ||
|
||
return response | ||
|
||
async def fetch_connections(self, pagination: Optional[PaginationOption] = None) -> Dict[str, Any]: | ||
if pagination is None: | ||
pagination = PaginationOption() | ||
request = ibc_connection_query.QueryConnectionsRequest(pagination=pagination.create_pagination_request()) | ||
response = await self._execute_call(call=self._stub.Connections, request=request) | ||
|
||
return response | ||
|
||
async def fetch_client_connections(self, client_id: str) -> Dict[str, Any]: | ||
request = ibc_connection_query.QueryClientConnectionsRequest(client_id=client_id) | ||
response = await self._execute_call(call=self._stub.ClientConnections, request=request) | ||
|
||
return response | ||
|
||
async def fetch_connection_client_state(self, connection_id: str) -> Dict[str, Any]: | ||
request = ibc_connection_query.QueryConnectionClientStateRequest(connection_id=connection_id) | ||
response = await self._execute_call(call=self._stub.ConnectionClientState, request=request) | ||
|
||
return response | ||
|
||
async def fetch_connection_consensus_state( | ||
self, | ||
connection_id: str, | ||
revision_number: int, | ||
revision_height: int, | ||
) -> Dict[str, Any]: | ||
request = ibc_connection_query.QueryConnectionConsensusStateRequest( | ||
connection_id=connection_id, | ||
revision_number=revision_number, | ||
revision_height=revision_height, | ||
) | ||
response = await self._execute_call(call=self._stub.ConnectionConsensusState, request=request) | ||
|
||
return response | ||
|
||
async def fetch_connection_params(self) -> Dict[str, Any]: | ||
request = ibc_connection_query.QueryConnectionParamsRequest() | ||
response = await self._execute_call(call=self._stub.ConnectionParams, 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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from collections import deque | ||
|
||
from pyinjective.proto.ibc.core.connection.v1 import ( | ||
query_pb2 as ibc_connection_query, | ||
query_pb2_grpc as ibc_connection_query_grpc, | ||
) | ||
|
||
|
||
class ConfigurableIBCConnectionQueryServicer(ibc_connection_query_grpc.QueryServicer): | ||
def __init__(self): | ||
super().__init__() | ||
self.connection_responses = deque() | ||
self.connections_responses = deque() | ||
self.client_connections_responses = deque() | ||
self.connection_client_state_responses = deque() | ||
self.connection_consensus_state_responses = deque() | ||
self.connection_params_responses = deque() | ||
|
||
async def Connection(self, request: ibc_connection_query.QueryConnectionRequest, context=None, metadata=None): | ||
return self.connection_responses.pop() | ||
|
||
async def Connections(self, request: ibc_connection_query.QueryConnectionsRequest, context=None, metadata=None): | ||
return self.connections_responses.pop() | ||
|
||
async def ClientConnections( | ||
self, request: ibc_connection_query.QueryClientConnectionsRequest, context=None, metadata=None | ||
): | ||
return self.client_connections_responses.pop() | ||
|
||
async def ConnectionClientState( | ||
self, request: ibc_connection_query.QueryConnectionClientStateRequest, context=None, metadata=None | ||
): | ||
return self.connection_client_state_responses.pop() | ||
|
||
async def ConnectionConsensusState( | ||
self, request: ibc_connection_query.QueryConnectionConsensusStateRequest, context=None, metadata=None | ||
): | ||
return self.connection_consensus_state_responses.pop() | ||
|
||
async def ConnectionParams( | ||
self, request: ibc_connection_query.QueryConnectionParamsRequest, context=None, metadata=None | ||
): | ||
return self.connection_params_responses.pop() | ||
Comment on lines
+1
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure robust handling of empty deques in servicer methods. The methods in |
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.
Check for potential file duplication or incorrect content.
This script appears identical to
5_ConnectionConsensusState.py
. Please verify if this is intentional or if there has been a mistake in file naming or content duplication.