From 1a20aac16da9439305a3e73d7e33205022a7c3c5 Mon Sep 17 00:00:00 2001 From: Martino Salvetti Date: Sun, 8 Jan 2017 15:55:20 +0100 Subject: [PATCH 1/3] Add timestamps of the unspent values --- joinmarket/blockchaininterface.py | 27 +++++++++++++++++++++++++++ wallet-tool.py | 30 ++++++++++++++++++++++++++---- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/joinmarket/blockchaininterface.py b/joinmarket/blockchaininterface.py index d2291dc3..0390936c 100644 --- a/joinmarket/blockchaininterface.py +++ b/joinmarket/blockchaininterface.py @@ -135,6 +135,10 @@ def estimate_fee_per_kb(self, N): required for inclusion in the next N blocks. ''' + @abc.abstractmethod + def get_lasts_txs_info(self, wallet): + """returns information about the addresses""" + def get_fee(self, N): '''Get the fee the user wishes to use. This can either be a manually set fee if the 'block' target is higher than 144 or an estimation by the @@ -432,6 +436,9 @@ def estimate_fee_per_kb(self, N): return fee_per_kb + def get_lasts_txs_info(self, wallet): + """Not implemented""" + raise NotImplementedError def bitcoincore_timeout_callback(uc_called, txout_set, txnotify_fun_list, timeoutfun): @@ -912,6 +919,26 @@ def estimate_fee_per_kb(self, N): estimate = Decimal(1e8) * Decimal(self.rpc('estimatefee', [N+1])) return estimate + def get_lasts_txs_info(self, wallet): + """ + returns timestamps for the last tx of every not empty address. + """ + + info = {} + for utxo, addrvalue in wallet.unspent.iteritems(): + # txid:nvalue, {'address', 'value'} + txid = utxo.split(':')[0] + addr = addrvalue['address'] + + tx = self.rpc('gettransaction', [txid]) + if 'time' in tx: + info[addr] = dict(time=tx['time'], used=True) + + agd = self.rpc('listaddressgroupings', []) + for used in agd: + info[used[0][0]] = info.get(used[0][0], dict(used=True)) + + return info # class for regtest chain access # running on local daemon. Only diff --git a/wallet-tool.py b/wallet-tool.py index a136f4a6..de46d367 100644 --- a/wallet-tool.py +++ b/wallet-tool.py @@ -5,6 +5,7 @@ import json import os import sys +import time import sqlite3 from optparse import OptionParser @@ -151,6 +152,13 @@ if method == 'display' or method == 'displayall' or method == 'summary': + try: + addrs_info = jm_single().bc_interface.get_lasts_txs_info(wallet) + used_addrs = set(addrs_info.keys()) + except NotImplementedError: + addrs_info = {} + used_addrs = [] + def cus_print(s): if method != 'summary': print(s) @@ -174,17 +182,31 @@ def cus_print(s): if addr == addrvalue['address']: balance += addrvalue['value'] balance_depth += balance - used = ('used' if k < wallet.index[m][forchange] else ' new') + + if k < wallet.index[m][forchange]: + if used_addrs and addr not in used_addrs: + used = 'exposed' + else: + used = 'used' + else: + used = ' new' + + if addr in used_addrs and 'time' in addrs_info[addr]: + t = time.localtime(addrs_info[addr]['time']) + ts = time.strftime(' %d %b %y %H:%M', t) + else: + ts = '' + if options.showprivkey: - privkey = btc.wif_compressed_privkey( + privkey = ' ' + btc.wif_compressed_privkey( wallet.get_key(m, forchange, k), get_p2pk_vbyte()) else: privkey = '' if (method == 'displayall' or balance > 0 or (used == ' new' and forchange == 0)): - cus_print(' m/0/%d/%d/%03d %-35s%s %.8f btc %s' % + cus_print(' m/0/%d/%d/%03d %-35s%s %.8f btc%s%s' % (m, forchange, k, addr, used, balance / 1e8, - privkey)) + privkey, ts)) if m in wallet.imported_privkeys: cus_print(' import addresses') for privkey in wallet.imported_privkeys[m]: From dffcea175e17bd6a5231398e77603a7eecf38304 Mon Sep 17 00:00:00 2001 From: Martino Salvetti Date: Sun, 8 Jan 2017 17:40:17 +0100 Subject: [PATCH 2/3] Add DummyBlockchainInterface.get_lasts_txs_info --- test/test_broadcast_method.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/test_broadcast_method.py b/test/test_broadcast_method.py index 10832913..6bf2e0b1 100644 --- a/test/test_broadcast_method.py +++ b/test/test_broadcast_method.py @@ -57,6 +57,9 @@ def pushtx(self, txhex): self_pushtx_count[0] += 1 return True + def get_lasts_txs_info(self, wallet): + return {} + def dummy_commitment_creator(wallet, utxos, amount): return "fake_commitment", "fake_reveal" From b5f5d17dabf7ba08474e13cff2e911b795b55b21 Mon Sep 17 00:00:00 2001 From: Martino Salvetti Date: Sat, 19 Aug 2017 14:19:04 +0200 Subject: [PATCH 3/3] Change date format --- wallet-tool.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wallet-tool.py b/wallet-tool.py index de46d367..bc186844 100644 --- a/wallet-tool.py +++ b/wallet-tool.py @@ -193,7 +193,7 @@ def cus_print(s): if addr in used_addrs and 'time' in addrs_info[addr]: t = time.localtime(addrs_info[addr]['time']) - ts = time.strftime(' %d %b %y %H:%M', t) + ts = time.strftime(' %d-%b-%y %H:%M', t) else: ts = ''