-
Notifications
You must be signed in to change notification settings - Fork 33
Feat/add missing explorer endpoints #369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fa5e91b
1719ef5
9d1489f
42c994e
9dece94
2803a59
2cd9389
436f8f6
4abdf75
e2e76d9
5c5867a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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()) |
| 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()) |
| 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()) |
| 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()) | ||
| 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()) |
| 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()) |
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||
|
|
||
|
|
||
| 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 = "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()) |
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
Suggested change
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| except Exception as e: | ||||||||||||||||||||||
| print(f"Error: {e}") | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if __name__ == "__main__": | ||||||||||||||||||||||
| asyncio.get_event_loop().run_until_complete(main()) | ||||||||||||||||||||||
| 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()) |
There was a problem hiding this comment.
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+:
📝 Committable suggestion