Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
Comment on lines +27 to +28
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Update to modern async execution pattern.

The current async execution pattern is deprecated. Use the modern pattern introduced in Python 3.7+:

 if __name__ == "__main__":
-    asyncio.get_event_loop().run_until_complete(main())
+    asyncio.run(main())
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
if __name__ == "__main__":
asyncio.run(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)
Comment on lines +15 to +17
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling and improve logging.

Add try-except block and improve logging for better error handling and debugging.

-    wasm_contract = await client.fetch_wasm_contract_by_address(address=address)
-    print("Wasm contract:")
-    print(wasm_contract)
+    try:
+        wasm_contract = await client.fetch_wasm_contract_by_address(address=address)
+        print("Wasm contract:")
+        print(wasm_contract)
+    except Exception as e:
+        logging.error(f"Failed to fetch WASM contract: {e}")
+        raise

Committable suggestion skipped: line range outside the PR's diff.



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)
Comment on lines +16 to +20
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix variable name mismatch.

The variable name doesn't match its purpose (validators vs relayers).

-        validators = await client.fetch_relayers()
+        relayers = await client.fetch_relayers()
 
         # Print relayers
         print("Relayers:")
-        print(validators)
+        print(relayers)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
validators = await client.fetch_relayers()
# Print relayers
print("Relayers:")
print(validators)
relayers = await client.fetch_relayers()
# Print relayers
print("Relayers:")
print(relayers)


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
Loading