1
0

history export: make fees bitcoin, add hook, rm local tx

Change fees from sats to bitcoin so the fee value is consistent with the
other values.
Fixes #10445

Also adds a plugin hook so plugins can create fancy history exports.

And stops adding unconfirmed/local transactions to the history as they
are unordered and make the export non-deterministic. Also transactions
that haven't happened yet don't seem useful for accounting.
This commit is contained in:
f321x
2026-01-27 18:14:07 +01:00
parent 68144588dd
commit e1dac558dd
2 changed files with 14 additions and 8 deletions

View File

@@ -845,9 +845,9 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
return
try:
self.wallet.export_history_to_file(
self.main_window.fx if self.hm.should_show_fiat() else None,
filename,
csv_button.isChecked(),
fx=self.main_window.fx if self.hm.should_show_fiat() else None,
file_path=filename,
is_csv=csv_button.isChecked(),
)
except (IOError, os.error) as reason:
export_error_label = _("Electrum was unable to produce a transaction export.")

View File

@@ -3614,9 +3614,14 @@ class Abstract_Wallet(ABC, Logger, EventListener):
util.trigger_callback('wallet_updated', self)
self.adb.set_future_tx(tx.txid(), wanted_height=wanted_height)
def export_history_to_file(self, fx: Optional['FxThread'], file_path: str, is_csv: bool):
def export_history_to_file(self, *, fx: Optional['FxThread'], file_path: str, is_csv: bool):
"""Create a file containing the wallet history in either json or csv format, e.g. for bookkeeping."""
if run_hook('export_history_to_file', self, fx, file_path, is_csv):
return # allow for plugins to create history fancy export
txns = self.get_full_history(fx=fx)
lines = []
# remove unconfirmed/local tx as their ordering is not deterministic, and they don't seem
# useful for a wallet export (can't do accounting on a tx that hasn't happened yet)
txns = {k: v for k, v in txns.items() if v['timestamp'] not in (None, 0)}
def get_all_fees_paid_by_item(h_item: dict) -> Tuple[int, Optional[Fiat]]:
# gets all fees paid in an item (or group), as the outer group doesn't contain the
@@ -3642,9 +3647,10 @@ class Abstract_Wallet(ABC, Logger, EventListener):
return fees_sat, fees_fiat
lines = []
if is_csv:
# sort by timestamp so the generated csv is more understandable on first sight
txns = dict(sorted(txns.items(), key=lambda h_item: h_item[1]['timestamp'] or 0))
txns = dict(sorted(txns.items(), key=lambda h_item: h_item[1]['timestamp']))
for item in txns.values():
# tx groups will are shown as single element
fees_sat, fees_fiat = get_all_fees_paid_by_item(item)
@@ -3659,7 +3665,7 @@ class Abstract_Wallet(ABC, Logger, EventListener):
item['bc_value'],
item['ln_value'],
item.get('fiat_value', ''),
fees_sat,
util.format_satoshis(fees_sat),
str(fees_fiat or ''),
item['date']
]
@@ -3676,7 +3682,7 @@ class Abstract_Wallet(ABC, Logger, EventListener):
"amount_chain_bc",
"amount_lightning_bc",
"fiat_value",
"network_fee_satoshi",
"network_fee_bc",
"fiat_fee",
"timestamp"])
for line in lines: