From 1d6493c70b4bd5f4bb9ab5426681ada1e0094566 Mon Sep 17 00:00:00 2001 From: Krisna Pranav <68631244+krishpranav@users.noreply.github.com> Date: Wed, 25 Dec 2024 15:56:51 +0530 Subject: [PATCH] sdk: utils --- sdk/utils.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sdk/utils.py b/sdk/utils.py index 65dbb93..dde0111 100644 --- a/sdk/utils.py +++ b/sdk/utils.py @@ -28,3 +28,14 @@ def convert_amount_type(amount: str | Decimal) -> Decimal: def satoshis(amount: str | Decimal) -> int: return int(convert_amount_type(amount) * CONVERT_RATE) + +def bitcoins(amount: int) -> Decimal: + return Decimal(amount) / Decimal(CONVERT_RATE) + +class CustomJSONEncoder(json.JSONEncoder): + def default(self, obj: Any) -> Any: + if isinstance(obj, Decimal): + return str(obj) + + return super().default(obj) +