Skip to content

Commit fe63c93

Browse files
committed
add chain query in async client and provide an example
1 parent 1aea872 commit fe63c93

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2021 Injective Labs
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""Injective Exchange API client for Python. Example only."""
15+
16+
import asyncio
17+
import logging
18+
19+
from pyinjective.async_client import AsyncClient
20+
from pyinjective.constant import Network
21+
22+
async def main() -> None:
23+
network = Network.testnet()
24+
client = AsyncClient(network, insecure=True)
25+
granter = "inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku"
26+
grantee = "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"
27+
msg_type_url = "/injective.exchange.v1beta1.MsgCreateDerivativeLimitOrder"
28+
authorizations = await client.get_grants(granter=granter, grantee=grantee, msg_type_url=msg_type_url)
29+
print(authorizations)
30+
31+
if __name__ == '__main__':
32+
logging.basicConfig(level=logging.INFO)
33+
asyncio.get_event_loop().run_until_complete(main())

pyinjective/async_client.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import time
2-
32
import grpc
4-
53
from typing import List, Optional, Tuple, Union
64

7-
from .exceptions import NotFoundError
5+
from .exceptions import NotFoundError, EmptyMsgError
86

97
from .proto.cosmos.base.abci.v1beta1 import abci_pb2 as abci_type
108

@@ -17,11 +15,15 @@
1715
query_pb2 as auth_query,
1816
auth_pb2 as auth_type,
1917
)
18+
from .proto.cosmos.authz.v1beta1 import (
19+
query_pb2_grpc as authz_query_grpc,
20+
query_pb2 as authz_query,
21+
authz_pb2 as authz_type,
22+
)
2023
from .proto.cosmos.tx.v1beta1 import (
2124
service_pb2_grpc as tx_service_grpc,
2225
service_pb2 as tx_service,
2326
)
24-
2527
from .proto.exchange import (
2628
injective_accounts_rpc_pb2 as exchange_accounts_rpc_pb,
2729
injective_accounts_rpc_pb2_grpc as exchange_accounts_rpc_grpc,
@@ -140,6 +142,11 @@ async def get_chain_id(self) -> str:
140142
latest_block = await self.get_latest_block()
141143
return latest_block.block.header.chain_id
142144

145+
async def get_grants(self, granter: str, grantee: str, **kwargs):
146+
return await self.stubAuthz.Grants(
147+
authz_query.QueryGrantsRequest(
148+
granter=granter, grantee=grantee, msg_type_url=kwargs.get("msg_type_url")))
149+
143150
# Injective Exchange client methods
144151

145152
# Auction RPC

0 commit comments

Comments
 (0)