ttie confirmation icons to payment verifier - electrum - Electrum Bitcoin wallet (HTM) git clone https://git.parazyd.org/electrum (DIR) Log (DIR) Files (DIR) Refs (DIR) Submodules --- (DIR) commit 2a06a5b493dbfb275c25746f708a980c222f7d8e (DIR) parent 46eabd1dab6bcaa3dfca5729116df58a201fda11 (HTM) Author: ThomasV <thomasv@gitorious> Date: Fri, 26 Oct 2012 00:40:19 +0200 ttie confirmation icons to payment verifier Diffstat: M electrum | 5 ++++- M lib/gui.py | 18 ++++++------------ M lib/gui_lite.py | 2 -- M lib/gui_qt.py | 14 ++++---------- M lib/simple_config.py | 8 ++++++-- M lib/verifier.py | 23 +++++++++++++---------- M lib/wallet.py | 6 ------ 7 files changed, 33 insertions(+), 43 deletions(-) --- (DIR) diff --git a/electrum b/electrum t@@ -191,7 +191,10 @@ if __name__ == '__main__': interface.start() WalletSynchronizer(wallet, config).start() - WalletVerifier(interface, config, wallet.get_tx_hashes).start() + + verifier = WalletVerifier(interface, config, wallet.get_tx_hashes) + verifier.start() + wallet.verifier = verifier try: found = config.wallet_file_exists (DIR) diff --git a/lib/gui.py b/lib/gui.py t@@ -325,7 +325,7 @@ def run_network_dialog( wallet, parent ): interface = wallet.interface if parent: if interface.is_connected: - status = "Connected to %s:%d\n%d blocks"%(interface.host, interface.port, wallet.blocks) + status = "Connected to %s:%d\n%d blocks"%(interface.host, interface.port, wallet.verifier.height) else: status = "Not connected" else: t@@ -1164,25 +1164,19 @@ class ElectrumWindow: if self.funds_error: text = "Not enough funds" elif interface and interface.is_connected: - self.network_button.set_tooltip_text("Connected to %s:%d.\n%d blocks"%(interface.host, interface.port, self.wallet.blocks)) - if self.wallet.blocks == -1: - self.status_image.set_from_stock(gtk.STOCK_NO, gtk.ICON_SIZE_MENU) - text = "Connecting..." - elif self.wallet.blocks == 0: - self.status_image.set_from_stock(gtk.STOCK_NO, gtk.ICON_SIZE_MENU) - text = "Server not ready" - elif not self.wallet.up_to_date: + self.network_button.set_tooltip_text("Connected to %s:%d.\n%d blocks"%(interface.host, interface.port, self.wallet.verifier.height)) + if not self.wallet.up_to_date: self.status_image.set_from_stock(gtk.STOCK_REFRESH, gtk.ICON_SIZE_MENU) text = "Synchronizing..." else: self.status_image.set_from_stock(gtk.STOCK_YES, gtk.ICON_SIZE_MENU) - self.network_button.set_tooltip_text("Connected to %s:%d.\n%d blocks"%(interface.host, interface.port, self.wallet.blocks)) + self.network_button.set_tooltip_text("Connected to %s:%d.\n%d blocks"%(interface.host, interface.port, self.wallet.verifier.height)) c, u = self.wallet.get_balance() text = "Balance: %s "%( format_satoshis(c,False,self.wallet.num_zeros) ) if u: text += "[%s unconfirmed]"%( format_satoshis(u,True,self.wallet.num_zeros).strip() ) else: self.status_image.set_from_stock(gtk.STOCK_NO, gtk.ICON_SIZE_MENU) - self.network_button.set_tooltip_text("Trying to contact %s.\n%d blocks"%(interface.server, self.wallet.blocks)) + self.network_button.set_tooltip_text("Not connected.") text = "Not connected" self.status_bar.pop(self.context_id) t@@ -1231,7 +1225,7 @@ class ElectrumWindow: for tx in self.wallet.get_tx_history(): tx_hash = tx['tx_hash'] if tx['height']: - conf = self.wallet.blocks - tx['height'] + 1 + conf = self.wallet.verifier.get_confirmations(tx_hash) time_str = datetime.datetime.fromtimestamp( tx['timestamp']).isoformat(' ')[:-3] conf_icon = gtk.STOCK_APPLY else: (DIR) diff --git a/lib/gui_lite.py b/lib/gui_lite.py t@@ -821,8 +821,6 @@ class MiniDriver(QObject): self.initializing() elif not self.wallet.interface.is_connected: self.connecting() - elif not self.wallet.blocks == -1: - self.connecting() elif not self.wallet.up_to_date: self.synchronizing() else: (DIR) diff --git a/lib/gui_qt.py b/lib/gui_qt.py t@@ -277,13 +277,7 @@ class ElectrumWindow(QMainWindow): def update_wallet(self): if self.wallet.interface and self.wallet.interface.is_connected: - if self.wallet.blocks == -1: - text = _( "Connecting..." ) - icon = QIcon(":icons/status_disconnected.png") - elif self.wallet.blocks == 0: - text = _( "Server not ready" ) - icon = QIcon(":icons/status_disconnected.png") - elif not self.wallet.up_to_date: + if not self.wallet.up_to_date: text = _( "Synchronizing..." ) icon = QIcon(":icons/status_waiting.png") else: t@@ -339,7 +333,7 @@ class ElectrumWindow(QMainWindow): tx = self.wallet.tx_history.get(tx_hash) if tx['height']: - conf = self.wallet.blocks - tx['height'] + 1 + conf = self.wallet.verifier.get_confirmations(tx_hash) time_str = datetime.datetime.fromtimestamp( tx['timestamp']).isoformat(' ')[:-3] else: conf = 0 t@@ -441,7 +435,7 @@ class ElectrumWindow(QMainWindow): for tx in self.wallet.get_tx_history(): tx_hash = tx['tx_hash'] if tx['height']: - conf = self.wallet.blocks - tx['height'] + 1 + conf = self.wallet.verifier.get_confirmations(tx_hash) time_str = datetime.datetime.fromtimestamp( tx['timestamp']).isoformat(' ')[:-3] if conf < 6: icon = QIcon(":icons/clock%d.png"%conf) t@@ -1367,7 +1361,7 @@ class ElectrumWindow(QMainWindow): interface = wallet.interface if parent: if interface.is_connected: - status = _("Connected to")+" %s\n%d blocks"%(interface.host, wallet.blocks) + status = _("Connected to")+" %s\n%d blocks"%(interface.host, wallet.verifier.height) else: status = _("Not connected") else: (DIR) diff --git a/lib/simple_config.py b/lib/simple_config.py t@@ -104,8 +104,12 @@ class SimpleConfig: # try to fix the type if default is not None and type(out) != type(default): import ast - out = ast.literal_eval(out) - + try: + out = ast.literal_eval(out) + except: + print "type error, using default value" + out = default + return out (DIR) diff --git a/lib/verifier.py b/lib/verifier.py t@@ -33,17 +33,17 @@ class WalletVerifier(threading.Thread): self.interface = interface self.get_transactions = get_transactions self.interface.register_channel('verifier') - self.verified_tx = config.get('verified_tx',[]) + self.verified_tx = config.get('verified_tx',{}) self.merkle_roots = config.get('merkle_roots',{}) # hashed by me self.targets = config.get('targets',{}) # compute targets self.lock = threading.Lock() self.pending_headers = [] # headers that have not been verified self.height = 0 self.local_height = 0 - self.set_local_numblocks() + self.set_local_height() - - + def get_confirmations(self, tx): + return (self.local_height - self.verified_tx[tx] + 1) if tx in self.verified_tx else None def run(self): requested_merkle = [] t@@ -138,7 +138,7 @@ class WalletVerifier(threading.Thread): header = self.read_header(tx_height) if header: assert header.get('merkle_root') == self.merkle_roots[tx_hash] - self.verified_tx.append(tx_hash) + self.verified_tx[tx_hash] = tx_height print "verified", tx_hash self.config.set_key('verified_tx', self.verified_tx, True) t@@ -257,7 +257,7 @@ class WalletVerifier(threading.Thread): f.seek(index*2016*80) h = f.write(chunk) f.close() - self.set_local_numblocks() + self.set_local_height() def save_header(self, header): data = self.header_to_string(header).decode('hex') t@@ -268,13 +268,16 @@ class WalletVerifier(threading.Thread): f.seek(height*80) h = f.write(data) f.close() - self.set_local_numblocks() + self.set_local_height() + - def set_local_numblocks(self): + def set_local_height(self): name = self.path() if os.path.exists(name): - self.local_height = os.path.getsize(name)/80 - 1 - # print "local height", self.local_height, os.path.getsize(name)/80. + h = os.path.getsize(name)/80 - 1 + if self.local_height != h: + self.local_height = h + self.interface.trigger_callback('updated') def read_header(self, block_height): (DIR) diff --git a/lib/wallet.py b/lib/wallet.py t@@ -78,7 +78,6 @@ class Wallet: self.receipt = None # next receipt self.tx_history = {} self.was_updated = True - self.blocks = -1 self.banner = '' # there is a difference between wallet.up_to_date and interface.is_up_to_date() t@@ -868,7 +867,6 @@ class WalletSynchronizer(threading.Thread): self.interface.send([('server.banner',[])],'synchronizer') # subscriptions - self.interface.send([('blockchain.numblocks.subscribe',[])], 'synchronizer') self.interface.send([('server.peers.subscribe',[])],'synchronizer') self.subscribe_to_addresses(self.wallet.all_addresses()) t@@ -903,10 +901,6 @@ class WalletSynchronizer(threading.Thread): self.wallet.tx_result = result self.wallet.tx_event.set() - elif method == 'blockchain.numblocks.subscribe': - self.wallet.blocks = result - self.wallet.was_updated = True - elif method == 'server.version': pass