Merge pull request #9938 from f321x/fix_history_export
fix: update do_export_history to use wallet.get_full_history
This commit is contained in:
@@ -845,29 +845,52 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
|
|||||||
self.main_window.show_message(_("Your wallet history has been successfully exported."))
|
self.main_window.show_message(_("Your wallet history has been successfully exported."))
|
||||||
|
|
||||||
def do_export_history(self, file_name, is_csv):
|
def do_export_history(self, file_name, is_csv):
|
||||||
hist = self.wallet.get_detailed_history(fx=self.main_window.fx)
|
txns = self.wallet.get_full_history(fx=self.main_window.fx)
|
||||||
txns = hist['transactions']
|
|
||||||
lines = []
|
lines = []
|
||||||
|
|
||||||
|
def get_all_fees_paid_sat(h_item: dict) -> int:
|
||||||
|
# gets all fees paid in an item (or group), as the outer group doesn't contain the
|
||||||
|
# transaction fees paid by the children
|
||||||
|
fees_sat = 0
|
||||||
|
for child in h_item.get('children', []):
|
||||||
|
fees_sat += child['fee_sat'] or 0 if 'fee_sat' in child \
|
||||||
|
else (child.get('fee_msat', 0) or 0) // 1000
|
||||||
|
|
||||||
|
fees_sat += h_item['fee_sat'] or 0 if 'fee_sat' in h_item \
|
||||||
|
else (h_item.get('fee_msat', 0) or 0) // 1000
|
||||||
|
return fees_sat
|
||||||
|
|
||||||
if is_csv:
|
if is_csv:
|
||||||
for item in txns:
|
# sort by timestamp so the generated csv is more understandable on first sight
|
||||||
lines.append([item['txid'],
|
txns = dict(sorted(txns.items(), key=lambda h_item: h_item[1]['timestamp'] or 0))
|
||||||
item.get('label', ''),
|
for item in txns.values():
|
||||||
item['confirmations'],
|
# tx groups will are shown as single element
|
||||||
item['bc_value'],
|
line = [
|
||||||
item.get('fiat_value', ''),
|
item.get('txid', ''),
|
||||||
item.get('fee', ''),
|
item.get('payment_hash', ''),
|
||||||
item.get('fiat_fee', ''),
|
item.get('label', ''),
|
||||||
item['date']])
|
item.get('confirmations', ''),
|
||||||
|
item['bc_value'],
|
||||||
|
item['ln_value'],
|
||||||
|
item.get('fiat_value', ''),
|
||||||
|
get_all_fees_paid_sat(item),
|
||||||
|
item.get('fiat_fee', ''),
|
||||||
|
item['date']
|
||||||
|
]
|
||||||
|
lines.append(line)
|
||||||
|
|
||||||
with open(file_name, "w+", encoding='utf-8') as f:
|
with open(file_name, "w+", encoding='utf-8') as f:
|
||||||
if is_csv:
|
if is_csv:
|
||||||
import csv
|
import csv
|
||||||
transaction = csv.writer(f, lineterminator='\n')
|
transaction = csv.writer(f, lineterminator='\n')
|
||||||
transaction.writerow(["transaction_hash",
|
transaction.writerow(["oc_transaction_hash",
|
||||||
|
"ln_payment_hash",
|
||||||
"label",
|
"label",
|
||||||
"confirmations",
|
"confirmations",
|
||||||
"value",
|
"amount_chain_bc",
|
||||||
|
"amount_lightning_bc",
|
||||||
"fiat_value",
|
"fiat_value",
|
||||||
"fee",
|
"network_fee_satoshi",
|
||||||
"fiat_fee",
|
"fiat_fee",
|
||||||
"timestamp"])
|
"timestamp"])
|
||||||
for line in lines:
|
for line in lines:
|
||||||
|
|||||||
Reference in New Issue
Block a user