Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

[WIP] Add timestamp of the last transaction to addresses in ./wallet-tool.py display #698

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions joinmarket/blockchaininterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions test/test_broadcast_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
30 changes: 26 additions & 4 deletions wallet-tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import json
import os
import sys
import time
import sqlite3
from optparse import OptionParser

Expand Down Expand Up @@ -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)
Expand All @@ -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]:
Expand Down