From ce6b7a05edc62e75483e485e2f50758f7d298d50 Mon Sep 17 00:00:00 2001 From: Mostafa Date: Sun, 4 May 2025 18:49:23 +0800 Subject: [PATCH] feat: use Pactus Python packages for RPC connections --- examples/example_get_consensus_info.py | 21 ------------------- ...py => example_grpc_get_blockchain_info.py} | 6 +++--- ..._info.py => example_grpc_get_node_info.py} | 2 +- .../example_jsonrpc_get_blockchain_info.py | 16 ++++++++++++++ examples/example_jsonrpc_get_node_info.py | 16 ++++++++++++++ pyproject.toml | 3 +++ setup.py | 3 ++- 7 files changed, 41 insertions(+), 26 deletions(-) delete mode 100644 examples/example_get_consensus_info.py rename examples/{example_get_blockchain_info.py => example_grpc_get_blockchain_info.py} (70%) rename examples/{example_get_node_info.py => example_grpc_get_node_info.py} (89%) create mode 100644 examples/example_jsonrpc_get_blockchain_info.py create mode 100644 examples/example_jsonrpc_get_node_info.py create mode 100644 pyproject.toml diff --git a/examples/example_get_consensus_info.py b/examples/example_get_consensus_info.py deleted file mode 100644 index 9d5ccd6..0000000 --- a/examples/example_get_consensus_info.py +++ /dev/null @@ -1,21 +0,0 @@ -from pactus_grpc.blockchain_pb2_grpc import BlockchainStub -from pactus_grpc.blockchain_pb2 import GetConsensusInfoRequest -import grpc - - -def main() -> None: - # Creating a gRPC channel - channel = grpc.insecure_channel("bootstrap1.pactus.org:50051") - - # Creating a stub from channel - stub = BlockchainStub(channel) - - # Initialize a request and call get consensus info method - req = GetConsensusInfoRequest() - res = stub.GetConsensusInfo(req) - - print(f"Consensus info:\n{res}") - - -if __name__ == "__main__": - main() diff --git a/examples/example_get_blockchain_info.py b/examples/example_grpc_get_blockchain_info.py similarity index 70% rename from examples/example_get_blockchain_info.py rename to examples/example_grpc_get_blockchain_info.py index 8f15940..0b59832 100644 --- a/examples/example_get_blockchain_info.py +++ b/examples/example_grpc_get_blockchain_info.py @@ -5,16 +5,16 @@ def main() -> None: # Creating a gRPC channel - channel = grpc.insecure_channel("testnet1.pactus.org:50052") + channel = grpc.insecure_channel("bootstrap1.pactus.org:50051") # Creating a stub from channel stub = BlockchainStub(channel) # Initialize a request and call get blockchain info method req = GetBlockchainInfoRequest() - blockchain_info = stub.GetBlockchainInfo(req) + res = stub.GetBlockchainInfo(req) - print(f"Blockchain info:\n{blockchain_info}") + print(f"Blockchain info:\n{res}") if __name__ == "__main__": diff --git a/examples/example_get_node_info.py b/examples/example_grpc_get_node_info.py similarity index 89% rename from examples/example_get_node_info.py rename to examples/example_grpc_get_node_info.py index 7d22d31..f709e25 100644 --- a/examples/example_get_node_info.py +++ b/examples/example_grpc_get_node_info.py @@ -14,7 +14,7 @@ def main() -> None: req = GetNodeInfoRequest() res = stub.GetNodeInfo(req) - print(f"Node info Response:\n{res.reachability}") + print(f"Node info:\n{res}") if __name__ == "__main__": diff --git a/examples/example_jsonrpc_get_blockchain_info.py b/examples/example_jsonrpc_get_blockchain_info.py new file mode 100644 index 0000000..c5680c4 --- /dev/null +++ b/examples/example_jsonrpc_get_blockchain_info.py @@ -0,0 +1,16 @@ +from pactus_jsonrpc.client import PactusOpenRPCClient +import pactus_jsonrpc.client +import asyncio + + +async def main() -> None: + pactus_jsonrpc.client.CLIENT_URL = "https://testnet1.pactus.org/jsonrpc" + client = PactusOpenRPCClient([]) + + res = await client.pactus.blockchain.get_blockchain_info() + + print(f"Blockchain info:\n{res}") + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/examples/example_jsonrpc_get_node_info.py b/examples/example_jsonrpc_get_node_info.py new file mode 100644 index 0000000..0da46bf --- /dev/null +++ b/examples/example_jsonrpc_get_node_info.py @@ -0,0 +1,16 @@ +from pactus_jsonrpc.client import PactusOpenRPCClient +import pactus_jsonrpc.client +import asyncio + + +async def main() -> None: + pactus_jsonrpc.client.CLIENT_URL = "https://testnet1.pactus.org/jsonrpc" + client = PactusOpenRPCClient([]) + + res = await client.pactus.network.get_node_info() + + print(f"Node info:\n{res}") + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..eb62c16 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools >= 42.0.0"] +build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py index 60e4b25..30404f2 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,8 @@ packages=find_packages(), license="MIT", install_requires=[ - "pactus_grpc", + "pactus-grpc>=1.7.4", + "pactus-jsonrpc>=1.7.4", "ripemd-hash", "grpcio", "grpcio-tools",