From efccde2e8e720c2c773e10b7ea7f930df5cc0ef4 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Sun, 4 Nov 2012 15:38:34 +0100 Subject: [PATCH] fix: timestamps in transactions --- lib/deserialize.py | 1 - lib/gui.py | 6 ++---- lib/gui_qt.py | 10 ++++------ lib/wallet.py | 40 ++++++++++++++++++++++------------------ 4 files changed, 28 insertions(+), 29 deletions(-) diff --git a/lib/deserialize.py b/lib/deserialize.py index bb4fa37aa..7d6c0bafd 100644 --- a/lib/deserialize.py +++ b/lib/deserialize.py @@ -215,7 +215,6 @@ def parse_Transaction(vds): for i in xrange(n_vout): d['outputs'].append(parse_TxOut(vds, i)) d['lockTime'] = vds.read_uint32() - print d return d diff --git a/lib/gui.py b/lib/gui.py index ba844e459..e6f58c4af 100644 --- a/lib/gui.py +++ b/lib/gui.py @@ -1226,12 +1226,11 @@ class ElectrumWindow: balance = 0 for tx in self.wallet.get_tx_history(): tx_hash = tx['tx_hash'] - if tx['height']: - conf = self.wallet.verifier.get_confirmations(tx_hash) + conf = self.wallet.verifier.get_confirmations(tx_hash) + if conf: time_str = datetime.datetime.fromtimestamp( tx['timestamp']).isoformat(' ')[:-3] conf_icon = gtk.STOCK_APPLY else: - conf = 0 time_str = 'pending' conf_icon = gtk.STOCK_EXECUTE v = self.wallet.get_tx_value(tx_hash) @@ -1243,7 +1242,6 @@ class ElectrumWindow: inputs = map(lambda x: x.get('address'), tx['inputs']) outputs = map(lambda x: x.get('address'), tx['outputs']) - # tx = self.wallet.tx_history.get(tx_hash) details = "Transaction Details:\n\n" \ + "Transaction ID:\n" + tx_hash + "\n\n" \ + "Status: %d confirmations\n\n"%conf \ diff --git a/lib/gui_qt.py b/lib/gui_qt.py index 3fb1c7d5b..c4d96133f 100644 --- a/lib/gui_qt.py +++ b/lib/gui_qt.py @@ -332,11 +332,10 @@ class ElectrumWindow(QMainWindow): def tx_details(self, tx_hash): tx = self.wallet.transactions.get(tx_hash) - if tx['height']: - conf = self.wallet.verifier.get_confirmations(tx_hash) + conf = self.wallet.verifier.get_confirmations(tx_hash) + if conf: time_str = datetime.datetime.fromtimestamp( tx['timestamp']).isoformat(' ')[:-3] else: - conf = 0 time_str = 'pending' inputs = map(lambda x: x.get('address'), tx['inputs']) @@ -436,8 +435,8 @@ class ElectrumWindow(QMainWindow): balance = 0 for tx in self.wallet.get_tx_history(): tx_hash = tx['tx_hash'] - if tx['height']: - conf = self.wallet.verifier.get_confirmations(tx_hash) + conf = self.wallet.verifier.get_confirmations(tx_hash) + if conf: time_str = datetime.datetime.fromtimestamp( tx['timestamp']).isoformat(' ')[:-3] if conf == 0: icon = QIcon(":icons/unconfirmed.png") @@ -446,7 +445,6 @@ class ElectrumWindow(QMainWindow): else: icon = QIcon(":icons/confirmed.png") else: - conf = 0 time_str = 'pending' icon = QIcon(":icons/unconfirmed.png") v = self.wallet.get_tx_value(tx_hash) diff --git a/lib/wallet.py b/lib/wallet.py index 4f062292f..459dc6667 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -871,6 +871,16 @@ class Wallet: self.verifier.add(tx_hash) + def set_tx_timestamp(self, tx_hash, tx_height): + if tx_height>0: + header = self.verifier.read_header(tx_height) + timestamp = header.get('timestamp') + else: + timestamp = 1e12 + + with self.lock: + self.transactions[tx_hash]['timestamp'] = timestamp + @@ -951,22 +961,23 @@ class WalletSynchronizer(threading.Thread): addr = params[0] hist = [] # in the new protocol, we will receive a list of (tx_hash, height) - for tx in result: hist.append( (tx['tx_hash'], tx['height']) ) + for item in result: hist.append( (item['tx_hash'], item['height']) ) # store it self.wallet.receive_history_callback(addr, hist) # request transactions that we don't have for tx_hash, tx_height in hist: - if self.wallet.transactions.get(tx_hash) is None and tx_hash not in requested_tx: - self.interface.send([ ('blockchain.transaction.get',[tx_hash, tx_height]) ], 'synchronizer') - requested_tx.append(tx_hash) + if self.wallet.transactions.get(tx_hash) is None: + if tx_hash not in requested_tx: + self.interface.send([ ('blockchain.transaction.get',[tx_hash, tx_height]) ], 'synchronizer') + requested_tx.append(tx_hash) + else: + self.wallet.set_tx_timestamp(tx_hash, tx_height) elif method == 'blockchain.transaction.get': tx_hash = params[0] tx_height = params[1] - header = self.wallet.verifier.read_header(tx_height) - timestamp = header.get('timestamp') - tx = result - self.receive_tx(tx_hash, tx_height, timestamp, tx) + self.receive_tx(tx_hash, tx_height, result) + self.wallet.set_tx_timestamp(tx_hash, tx_height) requested_tx.remove(tx_hash) self.was_updated = True @@ -987,20 +998,13 @@ class WalletSynchronizer(threading.Thread): self.was_updated = False - def receive_tx(self, tx_hash, tx_height, timestamp, raw_tx): + def receive_tx(self, tx_hash, tx_height, raw_tx): assert tx_hash == hash_encode(Hash(raw_tx.decode('hex'))) - - import deserialize, BCDataStream - - # deserialize - vds = BCDataStream.BCDataStream() + import deserialize + vds = deserialize.BCDataStream() vds.write(raw_tx.decode('hex')) d = deserialize.parse_Transaction(vds) - d['height'] = tx_height d['tx_hash'] = tx_hash - d['timestamp'] = timestamp - d['default_label'] = tx_hash - print d self.wallet.receive_tx_callback(tx_hash, d)