Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wallet: since we have jsonpatch, save labels immediately upon setting. #8736

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions electrum/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ def _set_label(self, key: str, value: Optional[str]) -> None:
else:
self._labels[key] = value

def set_label(self, name: str, text: str = None) -> bool:
def set_label(self, name: str, text: str = None, *, write_to_disk=True) -> bool:
if not name:
return False
changed = False
Expand All @@ -663,12 +663,17 @@ def set_label(self, name: str, text: str = None) -> bool:
changed = True
if changed:
run_hook('set_label', self, name, text)
if write_to_disk:
self.save_db()
return changed

def import_labels(self, path):
data = read_json_file(path)
changed = False
for key, value in data.items():
self.set_label(key, value)
changed |= self.set_label(key, value, write_to_disk=False)
if changed:
self.save_db()

def export_labels(self, path):
write_json_file(path, self.get_all_labels())
Expand Down Expand Up @@ -3332,8 +3337,8 @@ def delete_address(self, address: str) -> None:
self.db.remove_addr_history(address)
for tx_hash in transactions_to_remove:
self.adb._remove_transaction(tx_hash)
self.set_label(address, None)
if req:= self.get_request_by_addr(address):
self.set_label(address, None, write_to_disk=False)
if req := self.get_request_by_addr(address):
self.delete_request(req.get_id())
self.set_frozen_state_of_addresses([address], False, write_to_disk=False)
pubkey = self.get_public_key(address)
Expand Down