-
Notifications
You must be signed in to change notification settings - Fork 28
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 #313 from InjectiveLabs/feat/tendermint_module_que…
…ries Feat/tendermint module queries
- Loading branch information
Showing
22 changed files
with
995 additions
and
45 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
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
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
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,16 @@ | ||
import asyncio | ||
|
||
from pyinjective.async_client import AsyncClient | ||
from pyinjective.core.network import Network | ||
|
||
|
||
async def main() -> None: | ||
network = Network.testnet() | ||
client = AsyncClient(network) | ||
|
||
node_info = await client.fetch_node_info() | ||
print(node_info) | ||
|
||
|
||
if __name__ == "__main__": | ||
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,16 @@ | ||
import asyncio | ||
|
||
from pyinjective.async_client import AsyncClient | ||
from pyinjective.core.network import Network | ||
|
||
|
||
async def main() -> None: | ||
network = Network.testnet() | ||
client = AsyncClient(network) | ||
|
||
syncing = await client.fetch_syncing() | ||
print(syncing) | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.get_event_loop().run_until_complete(main()) |
16 changes: 16 additions & 0 deletions
16
examples/chain_client/tendermint/query/3_GetLatestBlock.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,16 @@ | ||
import asyncio | ||
|
||
from pyinjective.async_client import AsyncClient | ||
from pyinjective.core.network import Network | ||
|
||
|
||
async def main() -> None: | ||
network = Network.testnet() | ||
client = AsyncClient(network) | ||
|
||
latest_block = await client.fetch_latest_block() | ||
print(latest_block) | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.get_event_loop().run_until_complete(main()) |
16 changes: 16 additions & 0 deletions
16
examples/chain_client/tendermint/query/4_GetBlockByHeight.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,16 @@ | ||
import asyncio | ||
|
||
from pyinjective.async_client import AsyncClient | ||
from pyinjective.core.network import Network | ||
|
||
|
||
async def main() -> None: | ||
network = Network.testnet() | ||
client = AsyncClient(network) | ||
|
||
block = await client.fetch_block_by_height(height=15793860) | ||
print(block) | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.get_event_loop().run_until_complete(main()) |
19 changes: 19 additions & 0 deletions
19
examples/chain_client/tendermint/query/5_GetLatestValidatorSet.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) | ||
|
||
validator_set = await client.fetch_latest_validator_set() | ||
print(validator_set) | ||
|
||
|
||
if __name__ == "__main__": | ||
symbol_db = symbol_database.Default() | ||
asyncio.get_event_loop().run_until_complete(main()) |
22 changes: 22 additions & 0 deletions
22
examples/chain_client/tendermint/query/6_GetValidatorSetByHeight.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,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) | ||
|
||
validator_set = await client.fetch_validator_set_by_height(height=23040174, pagination=pagination) | ||
print(validator_set) | ||
|
||
|
||
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
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,69 @@ | ||
from typing import Any, Callable, Dict, Optional | ||
|
||
from grpc.aio import Channel | ||
|
||
from pyinjective.client.model.pagination import PaginationOption | ||
from pyinjective.proto.cosmos.base.tendermint.v1beta1 import ( | ||
query_pb2 as tendermint_query, | ||
query_pb2_grpc as tendermint_query_grpc, | ||
) | ||
from pyinjective.utils.grpc_api_request_assistant import GrpcApiRequestAssistant | ||
|
||
|
||
class TendermintGrpcApi: | ||
def __init__(self, channel: Channel, metadata_provider: Callable): | ||
self._stub = tendermint_query_grpc.ServiceStub(channel) | ||
self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider) | ||
|
||
async def fetch_node_info(self) -> Dict[str, Any]: | ||
request = tendermint_query.GetNodeInfoRequest() | ||
response = await self._execute_call(call=self._stub.GetNodeInfo, request=request) | ||
|
||
return response | ||
|
||
async def fetch_syncing(self) -> Dict[str, Any]: | ||
request = tendermint_query.GetSyncingRequest() | ||
response = await self._execute_call(call=self._stub.GetSyncing, request=request) | ||
|
||
return response | ||
|
||
async def fetch_latest_block(self) -> Dict[str, Any]: | ||
request = tendermint_query.GetLatestBlockRequest() | ||
response = await self._execute_call(call=self._stub.GetLatestBlock, request=request) | ||
|
||
return response | ||
|
||
async def fetch_block_by_height(self, height: int) -> Dict[str, Any]: | ||
request = tendermint_query.GetBlockByHeightRequest(height=height) | ||
response = await self._execute_call(call=self._stub.GetBlockByHeight, request=request) | ||
|
||
return response | ||
|
||
async def fetch_latest_validator_set(self) -> Dict[str, Any]: | ||
request = tendermint_query.GetLatestValidatorSetRequest() | ||
response = await self._execute_call(call=self._stub.GetLatestValidatorSet, request=request) | ||
|
||
return response | ||
|
||
async def fetch_validator_set_by_height( | ||
self, height: int, pagination: Optional[PaginationOption] = None | ||
) -> Dict[str, Any]: | ||
if pagination is None: | ||
pagination = PaginationOption() | ||
request = tendermint_query.GetValidatorSetByHeightRequest( | ||
height=height, pagination=pagination.create_pagination_request() | ||
) | ||
response = await self._execute_call(call=self._stub.GetValidatorSetByHeight, request=request) | ||
|
||
return response | ||
|
||
async def abci_query( | ||
self, path: str, data: Optional[bytes] = None, height: Optional[int] = None, prove: bool = False | ||
) -> Dict[str, Any]: | ||
request = tendermint_query.ABCIQueryRequest(path=path, data=data, height=height, prove=prove) | ||
response = await self._execute_call(call=self._stub.ABCIQuery, 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) |
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
Oops, something went wrong.