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

Mint: Use Pydantic validated BaseModel for Lightning API responses #620

Open
callebtc opened this issue Sep 18, 2024 · 0 comments
Open

Mint: Use Pydantic validated BaseModel for Lightning API responses #620

callebtc opened this issue Sep 18, 2024 · 0 comments
Labels
code health Code health help wanted Extra attention is needed mint About the Nutshell mint

Comments

@callebtc
Copy link
Collaborator

Currently, this is our pattern throughout the lightning backends:

        try:
            r = await self.client.get(url=f"{self.endpoint}/api/v1/wallet", timeout=15)
            r.raise_for_status()
        except Exception as exc:
            return StatusResponse(
                error_message=f"Failed to connect to {self.endpoint} due to: {exc}",
                balance=0,
            )

        try:
            data: dict = r.json()
        except Exception:
            return StatusResponse(
                error_message=(
                    f"Received invalid response from {self.endpoint}: {r.text}"
                ),
                balance=0,
            )

We should make use of pydantic and predefine all expected response models from the Lightning backends so we can automatically validate the response. This would get rid of a lot of boilerplate and error checking in the code and make things a lot more robust and less prone to human errors.

@callebtc callebtc added help wanted Extra attention is needed mint About the Nutshell mint code health Code health labels Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code health Code health help wanted Extra attention is needed mint About the Nutshell mint
Projects
None yet
Development

No branches or pull requests

1 participant