Skip to content

Commit 9bac59b

Browse files
Merge pull request #116 from InjectiveLabs/f/add_explorer_calls
Add more methods in ExplorerRPC
2 parents fa722e0 + 0c23d42 commit 9bac59b

File tree

8 files changed

+230
-0
lines changed

8 files changed

+230
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ Note that the [sync client](https://github.com/InjectiveLabs/sdk-python/blob/mas
8080
### Changelogs
8181
**0.5.6.8**
8282
* Add skip & limit params to Exchange API methods
83+
* Add more methods in ExplorerRPC
8384
* Re-gen ini files
8485

8586
**0.5.6.6**
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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=False)
25+
address = "inj1cml96vmptgw99syqrrz8az79xer2pcgp0a885r"
26+
type = "injective.exchange.v1beta1.MsgCreateDerivativeLimitOrder"
27+
account = await client.get_account_txs(address=address, type=type)
28+
print(account)
29+
30+
if __name__ == '__main__':
31+
logging.basicConfig(level=logging.INFO)
32+
asyncio.get_event_loop().run_until_complete(main())
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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=False)
25+
limit = 2
26+
block = await client.get_blocks(limit=limit)
27+
print(block)
28+
29+
if __name__ == '__main__':
30+
logging.basicConfig(level=logging.INFO)
31+
asyncio.get_event_loop().run_until_complete(main())
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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=False)
25+
block_height = "5825046"
26+
block = await client.get_block(block_height=block_height)
27+
print(block)
28+
29+
if __name__ == '__main__':
30+
logging.basicConfig(level=logging.INFO)
31+
asyncio.get_event_loop().run_until_complete(main())
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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=False)
25+
txs = await client.get_txs()
26+
print(txs)
27+
28+
if __name__ == '__main__':
29+
logging.basicConfig(level=logging.INFO)
30+
asyncio.get_event_loop().run_until_complete(main())
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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=False)
25+
stream_txs = await client.stream_txs(
26+
)
27+
async for tx in stream_txs:
28+
print(tx)
29+
30+
if __name__ == '__main__':
31+
logging.basicConfig(level=logging.INFO)
32+
asyncio.get_event_loop().run_until_complete(main())
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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=False)
25+
stream_blocks = await client.stream_blocks(
26+
)
27+
async for block in stream_blocks:
28+
print(block)
29+
30+
if __name__ == '__main__':
31+
logging.basicConfig(level=logging.INFO)
32+
asyncio.get_event_loop().run_until_complete(main())

pyinjective/async_client.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,47 @@ async def get_tx_by_hash(self, tx_hash: str):
346346
req = explorer_rpc_pb.GetTxByTxHashRequest(hash=tx_hash)
347347
return await self.stubExplorer.GetTxByTxHash(req)
348348

349+
async def get_account_txs(self, address: str, **kwargs):
350+
req = explorer_rpc_pb.GetAccountTxsRequest(
351+
address=address,
352+
before=kwargs.get("before"),
353+
after=kwargs.get("after"),
354+
limit=kwargs.get("limit"),
355+
skip=kwargs.get("skip"),
356+
type=kwargs.get("type"),
357+
module=kwargs.get("module"))
358+
return await self.stubExplorer.GetAccountTxs(req)
359+
360+
async def get_blocks(self, **kwargs):
361+
req = explorer_rpc_pb.GetBlocksRequest(
362+
before=kwargs.get("before"),
363+
after=kwargs.get("after"),
364+
limit=kwargs.get("limit")
365+
)
366+
return await self.stubExplorer.GetBlocks(req)
367+
368+
async def get_block(self, block_height: str):
369+
req = explorer_rpc_pb.GetBlockRequest(id=block_height)
370+
return await self.stubExplorer.GetBlock(req)
371+
372+
async def get_txs(self, **kwargs):
373+
req = explorer_rpc_pb.GetTxsRequest(
374+
before=kwargs.get("before"),
375+
after=kwargs.get("after"),
376+
limit=kwargs.get("limit"),
377+
skip=kwargs.get("skip"),
378+
type=kwargs.get("type"),
379+
module=kwargs.get("module"))
380+
return await self.stubExplorer.GetTxs(req)
381+
382+
async def stream_txs(self):
383+
req = explorer_rpc_pb.StreamTxsRequest()
384+
return self.stubExplorer.StreamTxs(req)
385+
386+
async def stream_blocks(self):
387+
req = explorer_rpc_pb.StreamBlocksRequest()
388+
return self.stubExplorer.StreamBlocks(req)
389+
349390
# AccountsRPC
350391

351392
async def stream_subaccount_balance(self, subaccount_id: str):

0 commit comments

Comments
 (0)