From 6d2f39d390c53144bb1a6a813abb8f4852baae78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Tue, 24 Jun 2025 16:09:53 +0200 Subject: [PATCH] fix: rounding errors on eclair total balance (#3196) --- lnbits/wallets/eclair.py | 8 +++++--- tests/regtest/test_real_invoice.py | 1 - 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lnbits/wallets/eclair.py b/lnbits/wallets/eclair.py index daec315fa..c46f75c37 100644 --- a/lnbits/wallets/eclair.py +++ b/lnbits/wallets/eclair.py @@ -3,7 +3,9 @@ import base64 import hashlib import json import urllib.parse -from typing import Any, AsyncGenerator, Optional +from collections.abc import AsyncGenerator +from decimal import Decimal +from typing import Any, Optional import httpx from loguru import logger @@ -70,8 +72,8 @@ class EclairWallet(Wallet): if r.is_error or "total" not in data: return StatusResponse(f"Server error: '{r.text}'", 0) - - return StatusResponse(None, int(data.get("total") * 100_000_000_000)) + total = round(Decimal(data.get("total")), 8) * 100_000_000_000 + return StatusResponse(balance_msat=int(total), error_message=None) except json.JSONDecodeError: return StatusResponse("Server error: 'invalid json response'", 0) except Exception as exc: diff --git a/tests/regtest/test_real_invoice.py b/tests/regtest/test_real_invoice.py index 22707aca2..99319abbe 100644 --- a/tests/regtest/test_real_invoice.py +++ b/tests/regtest/test_real_invoice.py @@ -66,7 +66,6 @@ async def test_pay_real_invoice( await asyncio.sleep(1) balance = await get_node_balance_sats() - # TODO: maybe take fee into consideration? assert prev_balance - balance == 100