Browse Source

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
283
Neil Booth 9 years ago
parent
commit
f710d872c7
  1. 4
      lib/wallet.py
  2. 11
      plugins/labels.py

4
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):

11
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'),

Loading…
Cancel
Save