fix: rounding errors on eclair total balance (#3196)

This commit is contained in:
dni ⚡
2025-06-24 16:09:53 +02:00
committed by GitHub
parent 18496f0dd9
commit 6d2f39d390
2 changed files with 5 additions and 4 deletions

View File

@@ -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:

View File

@@ -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