Skip to content

Commit

Permalink
Merge pull request #369 from InjectiveLabs/feat/add_missing_explorer_…
Browse files Browse the repository at this point in the history
…endpoints

Feat/add missing explorer endpoints
  • Loading branch information
aarmoa authored Jan 23, 2025
2 parents 302f09b + 5c5867a commit f7ba353
Show file tree
Hide file tree
Showing 21 changed files with 951 additions and 4,687 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
python: ["3.9", "3.10", "3.11"]
os: [ubuntu-latest, macos-13, windows-latest]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
env:
OS: ${{ matrix.os }}
Expand All @@ -22,8 +22,13 @@ jobs:
with:
python-version: ${{ matrix.python }}

- name: Set ARCHFLAGS for macOS
if: runner.os == 'macOS'
run: echo "ARCHFLAGS=-arch arm64" >> $GITHUB_ENV

- name: Install poetry
run: python -m pip install poetry

- name: Cache the virtualenv
id: cache-venv
uses: actions/cache@v4
Expand All @@ -37,7 +42,7 @@ jobs:

- name: Run tests and Generate coverage
run: |
poetry run pytest --cov --cov-report=xml
poetry run pytest --cov --cov-report=xml -v --full-trace
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
Expand Down
47 changes: 47 additions & 0 deletions examples/exchange_client/explorer_rpc/11_GetContractsTxsV2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import asyncio
import time

from pyinjective.async_client import AsyncClient
from pyinjective.client.model.pagination import PaginationOption
from pyinjective.core.network import Network


async def main() -> None:
# Select network: local, testnet, mainnet, or custom
network = Network.testnet()

# Initialize client
client = AsyncClient(network)

try:
# Example parameters for fetching contract transactions
address = "inj1ady3s7whq30l4fx8sj3x6muv5mx4dfdlcpv8n7" # Replace with actual contract address

# Optional pagination and filtering parameters
pagination = PaginationOption(
limit=10,
start_time=int((time.time() - 100) * 1000),
end_time=int(time.time() * 1000),
)

# Fetch contract transactions V2
response = await client.fetch_contract_txs_v2(address=address, height=60_000_000, pagination=pagination)

# Print the results
print("Contract Transactions V2:")
print("Total Transactions:", len(response["data"]))

for tx in response["data"]:
print("\nTransaction Details:")
print("ID:", tx["id"])
print("Block Number:", tx["blockNumber"])
print("Timestamp:", tx["blockTimestamp"])
print("Hash:", tx["hash"])
print("Tx Number:", tx["txNumber"])

except Exception as e:
print(f"Error occurred: {e}")


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
27 changes: 27 additions & 0 deletions examples/exchange_client/explorer_rpc/12_GetValidators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import asyncio

from pyinjective.async_client import AsyncClient
from pyinjective.core.network import Network


async def main():
# Select network: choose between testnet, mainnet, or local
network = Network.testnet()

# Initialize AsyncClient
client = AsyncClient(network)

try:
# Fetch validators
validators = await client.fetch_validators()

# Print validators
print("Validators:")
print(validators)

except Exception as e:
print(f"Error: {e}")


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
28 changes: 28 additions & 0 deletions examples/exchange_client/explorer_rpc/13_GetValidator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import asyncio

from pyinjective.async_client import AsyncClient
from pyinjective.core.network import Network


async def main():
# Select network: choose between testnet, mainnet, or local
network = Network.testnet()

# Initialize AsyncClient
client = AsyncClient(network)
address = "injvaloper1kk523rsm9pey740cx4plalp40009ncs0wrchfe"

try:
# Fetch validator
validator = await client.fetch_validator(address=address)

# Print validators
print("Validator:")
print(validator)

except Exception as e:
print(f"Error: {e}")


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
28 changes: 28 additions & 0 deletions examples/exchange_client/explorer_rpc/14_GetValidatorUptime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import asyncio

from pyinjective.async_client import AsyncClient
from pyinjective.core.network import Network


async def main():
# Select network: choose between testnet, mainnet, or local
network = Network.testnet()

# Initialize AsyncClient
client = AsyncClient(network)
address = "injvaloper1kk523rsm9pey740cx4plalp40009ncs0wrchfe"

try:
# Fetch validator uptime
uptime = await client.fetch_validator_uptime(address=address)

# Print uptime
print("Validator uptime:")
print(uptime)

except Exception as e:
print(f"Error: {e}")


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
29 changes: 29 additions & 0 deletions examples/exchange_client/explorer_rpc/15_GetWasmCodes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import asyncio
import logging

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 = Network.testnet()
network: Network = Network.testnet()
client: AsyncClient = AsyncClient(network)

pagination = PaginationOption(
limit=10,
from_number=1000,
to_number=2000,
)

wasm_codes = await client.fetch_wasm_codes(
pagination=pagination,
)
print("Wasm codes:")
print(wasm_codes)


if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
asyncio.get_event_loop().run_until_complete(main())
24 changes: 24 additions & 0 deletions examples/exchange_client/explorer_rpc/16_GetWasmCodeById.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import asyncio
import logging

from pyinjective.async_client import AsyncClient
from pyinjective.core.network import Network


async def main() -> None:
# network: Network = Network.testnet()
network: Network = Network.testnet()
client: AsyncClient = AsyncClient(network)

code_id = 2008

wasm_code = await client.fetch_wasm_code_by_id(
code_id=code_id,
)
print("Wasm code:")
print(wasm_code)


if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
asyncio.get_event_loop().run_until_complete(main())
30 changes: 30 additions & 0 deletions examples/exchange_client/explorer_rpc/17_GetWasmContracts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import asyncio
import logging

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 = Network.testnet()
network: Network = Network.testnet()
client: AsyncClient = AsyncClient(network)

pagination = PaginationOption(
limit=10,
from_number=1000,
to_number=2000,
)

wasm_contracts = await client.fetch_wasm_contracts(
assets_only=True,
pagination=pagination,
)
print("Wasm contracts:")
print(wasm_contracts)


if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
asyncio.get_event_loop().run_until_complete(main())
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import asyncio
import logging

from pyinjective.async_client import AsyncClient
from pyinjective.core.network import Network


async def main() -> None:
# network: Network = Network.testnet()
network: Network = Network.testnet()
client: AsyncClient = AsyncClient(network)

address = "inj1yhz4e7df95908jhs9erl87vdzjkdsc24q7afjf"

wasm_contract = await client.fetch_wasm_contract_by_address(address=address)
print("Wasm contract:")
print(wasm_contract)


if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
asyncio.get_event_loop().run_until_complete(main())
22 changes: 22 additions & 0 deletions examples/exchange_client/explorer_rpc/19_GetCw20Balance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import asyncio
import logging

from pyinjective.async_client import AsyncClient
from pyinjective.core.network import Network


async def main() -> None:
# network: Network = Network.testnet()
network: Network = Network.testnet()
client: AsyncClient = AsyncClient(network)

address = "inj1phd706jqzd9wznkk5hgsfkrc8jqxv0kmlj0kex"

balance = await client.fetch_cw20_balance(address=address)
print("Cw20 balance:")
print(balance)


if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
asyncio.get_event_loop().run_until_complete(main())
27 changes: 27 additions & 0 deletions examples/exchange_client/explorer_rpc/20_Relayers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import asyncio

from pyinjective.async_client import AsyncClient
from pyinjective.core.network import Network


async def main():
# Select network: choose between testnet, mainnet, or local
network = Network.testnet()

# Initialize AsyncClient
client = AsyncClient(network)

try:
# Fetch relayers
validators = await client.fetch_relayers()

# Print relayers
print("Relayers:")
print(validators)

except Exception as e:
print(f"Error: {e}")


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
25 changes: 25 additions & 0 deletions examples/exchange_client/explorer_rpc/21_GetBankTransfers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import asyncio
import json
import logging

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 = Network.testnet()
network: Network = Network.testnet()
client: AsyncClient = AsyncClient(network)

pagination = PaginationOption(limit=5)
senders = ["inj17xpfvakm2amg962yls6f84z3kell8c5l6s5ye9"]

bank_transfers = await client.fetch_bank_transfers(senders=senders, pagination=pagination)
print("Bank transfers:")
print(json.dumps(bank_transfers, indent=2))


if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
asyncio.get_event_loop().run_until_complete(main())
Loading

0 comments on commit f7ba353

Please sign in to comment.