electrum

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

commit b5e0363f858a2fbf9c804c30fe6530741beb5d84
parent f710d872c73497006803b625d1d98d566895b1c3
Author: Neil Booth <kyuupichan@gmail.com>
Date:   Fri, 11 Sep 2015 14:02:01 +0900

Only save wallet if modified

Diffstat:
Mlib/wallet.py | 18+++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/lib/wallet.py b/lib/wallet.py @@ -51,6 +51,7 @@ class WalletStorage(PrintError): self.data = {} self.path = path self.file_exists = False + self.modified = False self.print_error("wallet path", self.path) if self.path: self.read(self.path) @@ -94,7 +95,7 @@ class WalletStorage(PrintError): v = default else: v = copy.deepcopy(v) - return v + return v def put(self, key, value, save = True): try: @@ -105,16 +106,22 @@ class WalletStorage(PrintError): return with self.lock: if value is not None: - self.data[key] = copy.deepcopy(value) + if self.data.get(key) != value: + self.modified = True + self.data[key] = copy.deepcopy(value) elif key in self.data: + self.modified = True self.data.pop(key) - if save: - self.write() + if save: + self.write() def write(self): assert not threading.currentThread().isDaemon() + if not self.modified: + return + with self.lock: + s = json.dumps(self.data, indent=4, sort_keys=True) temp_path = "%s.tmp.%s" % (self.path, os.getpid()) - s = json.dumps(self.data, indent=4, sort_keys=True) with open(temp_path, "w") as f: f.write(s) f.flush() @@ -128,6 +135,7 @@ class WalletStorage(PrintError): if 'ANDROID_DATA' not in os.environ: import stat os.chmod(self.path,stat.S_IREAD | stat.S_IWRITE) + self.print_error("saved")