Skip to content
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

feat: hathor-core health request #43

Merged
merged 2 commits into from
Feb 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions hathorlib/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import json
import re
from typing import Any, Dict, List, NamedTuple, Optional, cast
from urllib.parse import urljoin
Expand Down Expand Up @@ -105,6 +106,18 @@ async def version(self) -> HathorVersion:
else:
raise RuntimeError(f'Cannot parse version {version}')

async def health(self) -> Dict[str, Any]:
"""Return the health information of the backend."""
assert self._session is not None

async with self._session.get(self._get_url('health')) as resp:
data = await resp.text()
try:
parsed_json: Dict[str, Any] = json.loads(data)
except json.JSONDecodeError:
raise RuntimeError('Cannot parse health response: {}'.format(data))
return parsed_json

async def get_block_template(self, address: Optional[str] = None) -> BlockTemplate:
"""Return a block template."""
assert self._session is not None
Expand Down