From 7306df34459714b4b2e21cbf066d582c03b6ffd6 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Mon, 6 Nov 2023 22:52:05 +0100 Subject: [PATCH] handle correctly the case with no active channels --- lnbits/nodes/base.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lnbits/nodes/base.py b/lnbits/nodes/base.py index b35136d6e..b64d95f01 100644 --- a/lnbits/nodes/base.py +++ b/lnbits/nodes/base.py @@ -68,13 +68,22 @@ class ChannelStats(BaseModel): if channel.state == ChannelState.ACTIVE ] - return cls( - counts=counts, - avg_size=int(sum(active_channel_sizes) / len(active_channel_sizes)), - biggest_size=max(active_channel_sizes), - smallest_size=min(active_channel_sizes), - total_capacity=sum(active_channel_sizes), - ) + if len(active_channel_sizes) > 0: + return cls( + counts=counts, + avg_size=int(sum(active_channel_sizes) / len(active_channel_sizes)), + biggest_size=max(active_channel_sizes), + smallest_size=min(active_channel_sizes), + total_capacity=sum(active_channel_sizes), + ) + else: + return cls( + counts=counts, + avg_size=0, + biggest_size=0, + smallest_size=0, + total_capacity=0, + ) class NodeFees(BaseModel):