forked from exonum/exonum-python-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.py
59 lines (51 loc) · 2.15 KB
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""Example of a Basic API Interaction via Exonum Python Light Client."""
from exonum_client import ExonumClient
def run() -> None:
"""Example of a simple API interaction."""
client = ExonumClient(hostname="127.0.0.1", public_api_port=8080, private_api_port=8081)
# Get the available services:
print("Available services:")
available_services_response = client.public_api.available_services()
if available_services_response.status_code == 200:
available_services = available_services_response.json()
print(" Artifacts:")
for artifact in available_services["artifacts"]:
print(f" - {artifact['name']}:{artifact['version']} (runtime ID {artifact['runtime_id']})")
print(" Instances:")
for state in available_services["services"]:
instance = state["spec"]
print(f" - ID {instance['id']} => {instance['name']} (artifact {instance['artifact']['name']})")
else:
print("Available services request failed")
print("")
# Get the health info:
print("Health info:")
health_info_response = client.public_api.health_info()
if health_info_response.status_code == 200:
health_info = health_info_response.json()
print(f"Consensus status: {health_info['consensus_status']}")
print(f"Connected peers: {health_info['connected_peers']}")
else:
print("Health info request failed.")
print("")
# Get the Exonum stats:
print("Exonum stats:")
stats_response = client.public_api.stats()
if stats_response.status_code == 200:
stats = stats_response.json()
print(f"Tx pool size: {stats['tx_pool_size']}")
print(f"Tx count: {stats['tx_count']}")
print(f"Tx cache size: {stats['tx_cache_size']}")
else:
print("Stats request failed.")
print("")
# Get the user agent:
print("Exonum user agent:")
user_agent_response = client.public_api.user_agent()
if user_agent_response.status_code == 200:
user_agent = user_agent_response.json()
print(f"User agent: {user_agent}")
else:
print("User agent request failed.")
if __name__ == "__main__":
run()