From f710d872c73497006803b625d1d98d566895b1c3 Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Thu, 10 Sep 2015 22:27:50 +0900 Subject: [PATCH] When using labels plugin write wallet once Poor hook coupling would cause the wallet to be written twice unnecessarily when using the labels plugin and changing a label --- lib/wallet.py | 4 +--- plugins/labels.py | 11 ++++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/wallet.py b/lib/wallet.py index ca051b98..7b3e4a45 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -40,8 +40,6 @@ from mnemonic import Mnemonic import paymentrequest - - # internal ID for imported account IMPORTED_ACCOUNT = '/x' @@ -365,9 +363,9 @@ class Abstract_Wallet(PrintError): changed = True if changed: + run_hook('set_label', self, name, text) self.storage.put('labels', self.labels, True) - run_hook('set_label', self, name, text, changed) return changed def addresses(self, include_change = True): diff --git a/plugins/labels.py b/plugins/labels.py index 5a110aa6..f9598f20 100644 --- a/plugins/labels.py +++ b/plugins/labels.py @@ -76,16 +76,16 @@ class Plugin(BasePlugin): self.set_nonce(wallet, nonce) return nonce - def set_nonce(self, wallet, nonce): + def set_nonce(self, wallet, nonce, force_write=True): self.print_error("set", wallet.basename(), "nonce to", nonce) - wallet.storage.put("wallet_nonce", nonce, True) + wallet.storage.put("wallet_nonce", nonce, force_write) def requires_settings(self): return True @hook - def set_label(self, wallet, item, label, changed): - if not changed or not wallet in self.wallets: + def set_label(self, wallet, item, label): + if not wallet in self.wallets: return nonce = self.get_nonce(wallet) wallet_id = self.wallets[wallet][2] @@ -97,7 +97,8 @@ class Plugin(BasePlugin): args=["POST", "/label", False, bundle]) t.setDaemon(True) t.start() - self.set_nonce(wallet, nonce + 1) + # Caller will write the wallet + self.set_nonce(wallet, nonce + 1, force_write=False) def settings_widget(self, window): return EnterButton(_('Settings'),