1
0

Factorize history export code used in GUI and command line.

Add options to export history limits and exchange rate.
Closes: #1752, #2604,
Replaces: #2715, 3724
This commit is contained in:
ThomasV
2018-02-09 15:28:28 +01:00
parent 670194b920
commit 3f954a8b3d
3 changed files with 68 additions and 62 deletions

View File

@@ -2494,32 +2494,13 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
plt.show()
def do_export_history(self, wallet, fileName, is_csv):
history = wallet.get_history()
history = wallet.export_history(fx=self.fx)
lines = []
for item in history:
tx_hash, height, confirmations, timestamp, value, balance = item
if height>0:
if timestamp is not None:
time_string = format_time(timestamp)
else:
time_string = _("unverified")
else:
time_string = _("unconfirmed")
if value is not None:
value_string = format_satoshis(value, True)
else:
value_string = '--'
if tx_hash:
label = wallet.get_label(tx_hash)
else:
label = ""
if is_csv:
lines.append([tx_hash, label, confirmations, value_string, time_string])
lines.append([item['txid'], item.get('label', ''), item['confirmations'], item['value'], item['date']])
else:
lines.append({'txid':tx_hash, 'date':"%16s"%time_string, 'label':label, 'value':value_string})
lines.append(item)
with open(fileName, "w+") as f:
if is_csv:
@@ -2529,7 +2510,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
transaction.writerow(line)
else:
import json
f.write(json.dumps(lines, indent = 4))
f.write(json.dumps(lines, indent=4))
def sweep_key_dialog(self):
d = WindowModalDialog(self, title=_('Sweep private keys'))