Merge pull request #9656 from SomberNight/202503_configvar_plugins
plugin ConfigVars: define vars less dynamically
This commit is contained in:
@@ -300,11 +300,7 @@ class Plugins(DaemonThread):
|
|||||||
else:
|
else:
|
||||||
zipfile = zipimport.zipimporter(metadata['path'])
|
zipfile = zipimport.zipimporter(metadata['path'])
|
||||||
init_spec = zipfile.find_spec(name)
|
init_spec = zipfile.find_spec(name)
|
||||||
module = self.exec_module_from_spec(init_spec, base_name)
|
self.exec_module_from_spec(init_spec, base_name)
|
||||||
# import config vars
|
|
||||||
if hasattr(module, 'config_vars'):
|
|
||||||
for cv in module.config_vars:
|
|
||||||
setattr(SimpleConfig, cv.key().upper(), cv)
|
|
||||||
if name == "trustedcoin":
|
if name == "trustedcoin":
|
||||||
# removes trustedcoin after loading to not show it in the list of plugins
|
# removes trustedcoin after loading to not show it in the list of plugins
|
||||||
del self.internal_plugin_metadata[name]
|
del self.internal_plugin_metadata[name]
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
from electrum.simple_config import ConfigVar
|
from electrum.simple_config import ConfigVar, SimpleConfig
|
||||||
config_vars = [
|
|
||||||
ConfigVar('payserver_port', default=8080, type_=int),
|
SimpleConfig.PAYSERVER_PORT = ConfigVar('payserver_port', default=8080, type_=int, plugin=__name__)
|
||||||
ConfigVar('payserver_root', default='/r', type_=str),
|
SimpleConfig.PAYSERVER_ROOT = ConfigVar('payserver_root', default='/r', type_=str, plugin=__name__)
|
||||||
ConfigVar('payserver_allow_create_invoice', default=False, type_=bool),
|
SimpleConfig.PAYSERVER_ALLOW_CREATE_INVOICE = ConfigVar('payserver_allow_create_invoice', default=False, type_=bool, plugin=__name__)
|
||||||
]
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
from electrum.simple_config import ConfigVar
|
from electrum.simple_config import ConfigVar, SimpleConfig
|
||||||
config_vars = [
|
|
||||||
ConfigVar('swapserver_port', default=None, type_=int),
|
SimpleConfig.SWAPSERVER_PORT = ConfigVar('swapserver_port', default=None, type_=int, plugin=__name__)
|
||||||
ConfigVar('swapserver_fee_millionths', default=5000, type_=int),
|
SimpleConfig.SWAPSERVER_FEE_MILLIONTHS = ConfigVar('swapserver_fee_millionths', default=5000, type_=int, plugin=__name__)
|
||||||
ConfigVar('swapserver_ann_pow_nonce', default=0, type_=int),
|
SimpleConfig.SWAPSERVER_ANN_POW_NONCE = ConfigVar('swapserver_ann_pow_nonce', default=0, type_=int, plugin=__name__)
|
||||||
]
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
from electrum.simple_config import ConfigVar
|
from electrum.simple_config import ConfigVar, SimpleConfig
|
||||||
config_vars = [
|
|
||||||
ConfigVar('watchtower_server_port', default=None, type_=int),
|
SimpleConfig.WATCHTOWER_SERVER_PORT = ConfigVar('watchtower_server_port', default=None, type_=int, plugin=__name__)
|
||||||
ConfigVar('watchtower_server_user', default=None, type_=str),
|
SimpleConfig.WATCHTOWER_SERVER_USER = ConfigVar('watchtower_server_user', default=None, type_=str, plugin=__name__)
|
||||||
ConfigVar('watchtower_server_password', default=None, type_=str),
|
SimpleConfig.WATCHTOWER_SERVER_PASSWORD = ConfigVar('watchtower_server_password', default=None, type_=str, plugin=__name__)
|
||||||
]
|
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ class ConfigVar(property):
|
|||||||
convert_getter: Callable[[Any], Any] = None,
|
convert_getter: Callable[[Any], Any] = None,
|
||||||
short_desc: Callable[[], str] = None,
|
short_desc: Callable[[], str] = None,
|
||||||
long_desc: Callable[[], str] = None,
|
long_desc: Callable[[], str] = None,
|
||||||
|
plugin: Optional[str] = None,
|
||||||
):
|
):
|
||||||
self._key = key
|
self._key = key
|
||||||
self._default = default
|
self._default = default
|
||||||
@@ -56,6 +57,13 @@ class ConfigVar(property):
|
|||||||
assert long_desc is None or callable(long_desc)
|
assert long_desc is None or callable(long_desc)
|
||||||
self._short_desc = short_desc
|
self._short_desc = short_desc
|
||||||
self._long_desc = long_desc
|
self._long_desc = long_desc
|
||||||
|
if plugin: # enforce "key" starts with name of plugin
|
||||||
|
pkg_prefix = "electrum.plugins." # for internal plugins
|
||||||
|
if plugin.startswith(pkg_prefix):
|
||||||
|
plugin = plugin[len(pkg_prefix):]
|
||||||
|
assert "." not in plugin, plugin
|
||||||
|
key_prefix = plugin + "_"
|
||||||
|
assert key.startswith(key_prefix), f"ConfigVar {key=} must be prefixed with the plugin name ({key_prefix})"
|
||||||
property.__init__(self, self._get_config_value, self._set_config_value)
|
property.__init__(self, self._get_config_value, self._set_config_value)
|
||||||
assert key not in _config_var_from_key, f"duplicate config key str: {key!r}"
|
assert key not in _config_var_from_key, f"duplicate config key str: {key!r}"
|
||||||
_config_var_from_key[key] = self
|
_config_var_from_key[key] = self
|
||||||
|
|||||||
Reference in New Issue
Block a user