electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit ec141ebb67dd3c36e5675799c89ded7794e50f0e
parent 2b0d92e767396d12d7b69d2fe85477d8c38fb945
Author: ThomasV <thomasv@gitorious>
Date:   Sun, 29 Sep 2013 10:52:47 +0200

fix labels plugin

Diffstat:
Mgui/qt/main_window.py | 2+-
Mplugins/labels.py | 12++++++------
Mplugins/pointofsale.py | 20++++++++++++--------
3 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py @@ -288,7 +288,7 @@ class ElectrumWindow(QMainWindow): self.update_buttons_on_seed() self.update_console() - run_hook('load_wallet') + run_hook('load_wallet', wallet) def select_wallet_file(self): diff --git a/plugins/labels.py b/plugins/labels.py @@ -48,9 +48,9 @@ class Plugin(BasePlugin): def init(self): self.target_host = 'labelectrum.herokuapp.com' self.window = self.gui.main_window - self.wallet = self.window.wallet - self.labels = self.wallet.labels - self.transactions = self.wallet.transactions + + def load_wallet(self, wallet): + self.wallet = wallet mpk = self.wallet.master_public_keys["m/0'/"][1] self.encode_password = hashlib.sha1(mpk).digest().encode('hex')[:32] self.wallet_id = hashlib.sha256(mpk).digest().encode('hex') @@ -170,7 +170,7 @@ class Plugin(BasePlugin): def do_full_push(self): try: bundle = {"labels": {}} - for key, value in self.labels.iteritems(): + for key, value in self.wallet.labels.iteritems(): encoded = self.encode(key) bundle["labels"][encoded] = self.encode(value) @@ -214,8 +214,8 @@ class Plugin(BasePlugin): for label in response: decoded_key = self.decode(label["external_id"]) decoded_label = self.decode(label["text"]) - if force or not self.labels.get(decoded_key): - self.labels[decoded_key] = decoded_label + if force or not self.wallet.labels.get(decoded_key): + self.wallet.labels[decoded_key] = decoded_label return True except socket.gaierror as e: print_error('Error connecting to service: %s ' % e) diff --git a/plugins/pointofsale.py b/plugins/pointofsale.py @@ -102,6 +102,7 @@ class Plugin(BasePlugin): def init(self): self.window = self.gui.main_window + self.wallet = self.window.wallet self.qr_window = None self.merchant_name = self.config.get('merchant_name', 'Invoice') @@ -111,8 +112,9 @@ class Plugin(BasePlugin): self.requested_amounts = {} self.toggle_QR_window(True) - def load_wallet(self): - self.requested_amounts = self.window.wallet.storage.get('requested_amounts',{}) + def load_wallet(self, wallet): + self.wallet = wallet + self.requested_amounts = self.wallet.storage.get('requested_amounts',{}) def close(self): self.window.receive_list.setHeaderLabels([ _('Address'), _('Label'), _('Balance'), _('Tx')]) @@ -138,7 +140,7 @@ class Plugin(BasePlugin): item = self.window.receive_list.currentItem() if item: address = str(item.text(1)) - label = self.window.wallet.labels.get(address) + label = self.wallet.labels.get(address) amount, currency = self.requested_amounts.get(address, (None, None)) self.qr_window.set_content( address, label, amount, currency ) @@ -166,9 +168,11 @@ class Plugin(BasePlugin): def current_item_changed(self, a): + if not self.wallet: + return if a is not None and self.qr_window and self.qr_window.isVisible(): address = str(a.text(0)) - label = self.window.wallet.labels.get(address) + label = self.wallet.labels.get(address) try: amount, currency = self.requested_amounts.get(address, (None, None)) except: @@ -183,7 +187,7 @@ class Plugin(BasePlugin): address = str( item.text(0) ) text = str( item.text(column) ) try: - seq = self.window.wallet.get_address_index(address) + seq = self.wallet.get_address_index(address) index = seq[1][1] except: print "cannot get index" @@ -201,12 +205,12 @@ class Plugin(BasePlugin): currency = currency.upper() self.requested_amounts[address] = (amount, currency) - self.window.wallet.storage.put('requested_amounts', self.requested_amounts, True) + self.wallet.storage.put('requested_amounts', self.requested_amounts, True) - label = self.window.wallet.labels.get(address) + label = self.wallet.labels.get(address) if label is None: label = self.merchant_name + ' - %04d'%(index+1) - self.window.wallet.labels[address] = label + self.wallet.labels[address] = label if self.qr_window: self.qr_window.set_content( address, label, amount, currency )