From e25658d72459a7fef10e48c9dc48c86e85ca6941 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Wed, 22 May 2024 15:26:26 +0000 Subject: [PATCH] fix plot.py fixes https://github.com/spesmilo/electrum/issues/9058 --- electrum/plot.py | 7 ++++--- electrum/util.py | 1 + electrum/wallet.py | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/electrum/plot.py b/electrum/plot.py index 42bdee0c9..3e3604d29 100644 --- a/electrum/plot.py +++ b/electrum/plot.py @@ -1,6 +1,7 @@ # note: This module takes 1-2 seconds to import. It should be imported *on-demand*. import datetime +from decimal import Decimal from collections import defaultdict import matplotlib @@ -20,15 +21,15 @@ class NothingToPlotException(Exception): def plot_history(history): if len(history) == 0: raise NothingToPlotException() - hist_in = defaultdict(int) - hist_out = defaultdict(int) + hist_in = defaultdict(Decimal) + hist_out = defaultdict(Decimal) for item in history: is_lightning = item.get("lightning", False) if not is_lightning and not item['confirmations']: continue if item['timestamp'] is None: continue - value = item['value'].value/COIN + value = Decimal(item['value'].value)/COIN date = item['date'] datenum = int(md.date2num(datetime.date(date.year, date.month, 1))) if value > 0: diff --git a/electrum/util.py b/electrum/util.py index f2c6f5743..c4422deb5 100644 --- a/electrum/util.py +++ b/electrum/util.py @@ -238,6 +238,7 @@ class Satoshis(object): def __new__(cls, value): self = super(Satoshis, cls).__new__(cls) # note: 'value' sometimes has msat precision + assert isinstance(value, (int, Decimal)), f"unexpected type for {value=!r}" self.value = value return self diff --git a/electrum/wallet.py b/electrum/wallet.py index 101d431d5..9c4cc9482 100644 --- a/electrum/wallet.py +++ b/electrum/wallet.py @@ -1389,6 +1389,7 @@ class Abstract_Wallet(ABC, Logger, EventListener): 'value': Satoshis(0), 'children': [], 'timestamp': 0, + 'date': timestamp_to_datetime(0), 'fee_sat': 0, } transactions[key] = parent @@ -1403,6 +1404,7 @@ class Abstract_Wallet(ABC, Logger, EventListener): parent['lightning'] = False parent['txid'] = tx_item['txid'] parent['timestamp'] = tx_item['timestamp'] + parent['date'] = timestamp_to_datetime(tx_item['timestamp']) parent['height'] = tx_item['height'] parent['confirmations'] = tx_item['confirmations'] parent['children'].append(tx_item)