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:
@@ -845,9 +845,9 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
|
|||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
self.wallet.export_history_to_file(
|
self.wallet.export_history_to_file(
|
||||||
self.main_window.fx if self.hm.should_show_fiat() else None,
|
fx=self.main_window.fx if self.hm.should_show_fiat() else None,
|
||||||
filename,
|
file_path=filename,
|
||||||
csv_button.isChecked(),
|
is_csv=csv_button.isChecked(),
|
||||||
)
|
)
|
||||||
except (IOError, os.error) as reason:
|
except (IOError, os.error) as reason:
|
||||||
export_error_label = _("Electrum was unable to produce a transaction export.")
|
export_error_label = _("Electrum was unable to produce a transaction export.")
|
||||||
|
|||||||
@@ -3614,9 +3614,14 @@ class Abstract_Wallet(ABC, Logger, EventListener):
|
|||||||
util.trigger_callback('wallet_updated', self)
|
util.trigger_callback('wallet_updated', self)
|
||||||
self.adb.set_future_tx(tx.txid(), wanted_height=wanted_height)
|
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)
|
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]]:
|
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
|
# 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
|
return fees_sat, fees_fiat
|
||||||
|
|
||||||
|
lines = []
|
||||||
if is_csv:
|
if is_csv:
|
||||||
# sort by timestamp so the generated csv is more understandable on first sight
|
# 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():
|
for item in txns.values():
|
||||||
# tx groups will are shown as single element
|
# tx groups will are shown as single element
|
||||||
fees_sat, fees_fiat = get_all_fees_paid_by_item(item)
|
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['bc_value'],
|
||||||
item['ln_value'],
|
item['ln_value'],
|
||||||
item.get('fiat_value', ''),
|
item.get('fiat_value', ''),
|
||||||
fees_sat,
|
util.format_satoshis(fees_sat),
|
||||||
str(fees_fiat or ''),
|
str(fees_fiat or ''),
|
||||||
item['date']
|
item['date']
|
||||||
]
|
]
|
||||||
@@ -3676,7 +3682,7 @@ class Abstract_Wallet(ABC, Logger, EventListener):
|
|||||||
"amount_chain_bc",
|
"amount_chain_bc",
|
||||||
"amount_lightning_bc",
|
"amount_lightning_bc",
|
||||||
"fiat_value",
|
"fiat_value",
|
||||||
"network_fee_satoshi",
|
"network_fee_bc",
|
||||||
"fiat_fee",
|
"fiat_fee",
|
||||||
"timestamp"])
|
"timestamp"])
|
||||||
for line in lines:
|
for line in lines:
|
||||||
|
|||||||
Reference in New Issue
Block a user