commit f710d872c73497006803b625d1d98d566895b1c3
parent a735fbabe0b5b77e8b783ee6ed8da457ff6fbd00
Author: Neil Booth <kyuupichan@gmail.com>
Date: Thu, 10 Sep 2015 22:27:50 +0900
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
Diffstat:
2 files changed, 7 insertions(+), 8 deletions(-)
diff --git 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
@@ -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'),