Skip to content

Commit 1aea872

Browse files
committed
feat: add chain query in sync client and provide an example
1 parent 54fb719 commit 1aea872

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
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.client import Client
20+
from pyinjective.constant import Network
21+
22+
async def main() -> None:
23+
network = Network.testnet()
24+
client = Client(network, insecure=True)
25+
granter = "inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku"
26+
grantee = "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"
27+
msg_type_url = "/injective.exchange.v1beta1.MsgCreateDerivativeLimitOrder"
28+
authorizations = 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/client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ def get_chain_id(self) -> str:
167167
latest_block = self.get_latest_block()
168168
return latest_block.block.header.chain_id
169169

170+
def get_grants(self, granter: str, grantee: str, **kwargs):
171+
return self.stubAuthz.Grants(
172+
authz_query.QueryGrantsRequest(
173+
granter=granter, grantee=grantee, msg_type_url=kwargs.get("msg_type_url")))
174+
170175
# Injective Exchange client methods
171176

172177
# Auction RPC

0 commit comments

Comments
 (0)