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

@@ -440,46 +440,16 @@ class Commands:
return tx.as_dict()
@command('w')
def history(self):
def history(self, year=None, show_addresses=False, show_fiat=False):
"""Wallet history. Returns the transaction history of your wallet."""
balance = 0
out = []
for item in self.wallet.get_history():
tx_hash, height, conf, timestamp, value, balance = item
if timestamp:
date = datetime.datetime.fromtimestamp(timestamp).isoformat(' ')[:-3]
else:
date = "----"
label = self.wallet.get_label(tx_hash)
tx = self.wallet.transactions.get(tx_hash)
tx.deserialize()
input_addresses = []
output_addresses = []
for x in tx.inputs():
if x['type'] == 'coinbase': continue
addr = x.get('address')
if addr == None: continue
if addr == "(pubkey)":
prevout_hash = x.get('prevout_hash')
prevout_n = x.get('prevout_n')
_addr = self.wallet.find_pay_to_pubkey_address(prevout_hash, prevout_n)
if _addr:
addr = _addr
input_addresses.append(addr)
for addr, v in tx.get_outputs():
output_addresses.append(addr)
out.append({
'txid': tx_hash,
'timestamp': timestamp,
'date': date,
'input_addresses': input_addresses,
'output_addresses': output_addresses,
'label': label,
'value': str(Decimal(value)/COIN) if value is not None else None,
'height': height,
'confirmations': conf
})
return out
kwargs = {'show_addresses': show_addresses}
if year:
import time
start_date = datetime.datetime(year, 1, 1)
end_date = datetime.datetime(year+1, 1, 1)
kwargs['from_timestamp'] = time.mktime(start_date.timetuple())
kwargs['to_timestamp'] = time.mktime(end_date.timetuple())
return self.wallet.export_history(**kwargs)
@command('w')
def setlabel(self, key, label):
@@ -736,6 +706,9 @@ command_options = {
'pending': (None, "Show only pending requests."),
'expired': (None, "Show only expired requests."),
'paid': (None, "Show only paid requests."),
'show_addresses': (None, "Show input and output addresses"),
'show_fiat': (None, "Show fiat value of transactions"),
'year': (None, "Show history for a given year"),
}
@@ -746,6 +719,7 @@ arg_types = {
'num': int,
'nbits': int,
'imax': int,
'year': int,
'entropy': int,
'tx': tx_from_str,
'pubkeys': json_loads,