v0.5.11: Electrum 4.8.0 compatibility (register_dict -> register_name shim)

This commit is contained in:
2026-07-13 21:53:51 +00:00
parent 6456f9fa16
commit 745489f616

View File

@@ -36,11 +36,26 @@ _logger = get_logger(__name__)
# --------------------------------------------------------------------------- # # --------------------------------------------------------------------------- #
# Wallet-DB registration # Wallet-DB registration
# --------------------------------------------------------------------------- # # --------------------------------------------------------------------------- #
# Electrum needs to know how to (de)serialise the custom dictionaries the # Electrum needs to know how to (de)serialise the custom dictionaries the plugin
# plugin stores inside the wallet file. ``register_dict`` associates a key # stores inside the wallet file: a key name is associated with a conversion
# name with a conversion callable applied to each value when the wallet is # callable applied to each value when the wallet is loaded. ``will`` values run
# loaded. ``will`` values run through ``get_will`` so the stored transaction # through ``get_will`` so the stored transaction hex is turned back into a
# hex is turned back into a ``Transaction`` object. # ``Transaction`` object.
#
# COMPATIBILITY NOTE (Electrum 4.8.0):
# Electrum 4.8.0 REMOVED ``json_db.register_dict`` and moved the registration API
# to the new ``electrum.stored_dict`` module, switching from flat key names to
# '/'-separated paths with a wildcard for the dict entries, and swapping the last
# two arguments:
#
# Electrum <= 4.7.2 : json_db.register_dict(NAME, method, _type)
# Electrum >= 4.8.0 : stored_dict.register_name('/NAME/*', _type, method)
#
# The conversion semantics are identical in both versions (``_type is dict`` ->
# ``method(**value)``, ``_type is tuple`` -> ``method(*value)``, otherwise
# ``method(value)``); only the registration API changed. We therefore detect
# which API is available and adapt, so the plugin keeps working on BOTH 4.7.2 and
# 4.8.0 instead of breaking for users who have not upgraded yet.
def get_will(x): def get_will(x):
"""Deserialise a stored will entry, rebuilding its ``tx`` object.""" """Deserialise a stored will entry, rebuilding its ``tx`` object."""
try: try:
@@ -50,9 +65,24 @@ def get_will(x):
return x return x
json_db.register_dict("heirs", tuple, None) try:
json_db.register_dict("will", dict, None) # Electrum >= 4.8.0
json_db.register_dict("will_settings", lambda x: x, None) from electrum.stored_dict import register_name as _electrum_register_name
def _register_will_dict(name, method, _type=None):
"""Register a plugin dict in the wallet DB (Electrum >= 4.8.0 API)."""
_electrum_register_name(f"/{name}/*", _type, method)
except ImportError:
# Electrum <= 4.7.2
def _register_will_dict(name, method, _type=None):
"""Register a plugin dict in the wallet DB (Electrum <= 4.7.2 API)."""
json_db.register_dict(name, method, _type)
_register_will_dict("heirs", tuple)
_register_will_dict("will", dict)
_register_will_dict("will_settings", lambda x: x)
class BalConfig: class BalConfig:
@@ -91,7 +121,7 @@ class BalPlugin(BasePlugin):
""" """
_version = None _version = None
__version__ = "0.5.10" # AUTOMATICALLY GENERATED DO NOT EDIT __version__ = "0.5.11" # AUTOMATICALLY GENERATED DO NOT EDIT
# Command used to open an .ics calendar file, per operating system. # Command used to open an .ics calendar file, per operating system.
default_app = { default_app = {