1
0

daemon: pass cmdname to register_method

This allows plugins to use already existing names without Electrum complaining about collisions
This commit is contained in:
ThomasV
2025-11-04 12:08:16 +01:00
parent e02cfbfb60
commit 9c4c7f01ac
2 changed files with 9 additions and 9 deletions

View File

@@ -214,9 +214,9 @@ class AuthenticatedServer(Logger):
self.auth_lock = asyncio.Lock() self.auth_lock = asyncio.Lock()
self._methods = {} # type: Dict[str, Callable] self._methods = {} # type: Dict[str, Callable]
def register_method(self, f): def register_method(self, name: str, f):
assert f.__name__ not in self._methods, f"name collision for {f.__name__}" assert name not in self._methods, f"name collision for {name}"
self._methods[f.__name__] = f self._methods[name] = f
async def authenticate(self, headers): async def authenticate(self, headers):
if self.rpc_password == '': if self.rpc_password == '':
@@ -299,12 +299,12 @@ class CommandsServer(AuthenticatedServer):
self.port = self.config.RPC_PORT self.port = self.config.RPC_PORT
self.app = web.Application() self.app = web.Application()
self.app.router.add_post("/", self.handle) self.app.router.add_post("/", self.handle)
self.register_method(self.ping) self.register_method('ping', self.ping)
self.register_method(self.gui) self.register_method('gui', self.gui)
self.cmd_runner = Commands(config=self.config, network=self.daemon.network, daemon=self.daemon) self.cmd_runner = Commands(config=self.config, network=self.daemon.network, daemon=self.daemon)
for cmdname in known_commands: for cmdname in known_commands:
self.register_method(getattr(self.cmd_runner, cmdname)) self.register_method(cmdname, getattr(self.cmd_runner, cmdname))
self.register_method(self.run_cmdline) self.register_method('run_cmdline', self.run_cmdline)
def _socket_config_str(self) -> str: def _socket_config_str(self) -> str:
if self.socktype == 'unix': if self.socktype == 'unix':

View File

@@ -28,8 +28,8 @@ class WatchTowerServer(AuthenticatedServer):
self.lnwatcher = watchtower self.lnwatcher = watchtower
self.app = web.Application() self.app = web.Application()
self.app.router.add_post("/", self.handle) self.app.router.add_post("/", self.handle)
self.register_method(self.get_ctn) self.register_method('get_ctn', self.get_ctn)
self.register_method(self.add_sweep_tx) self.register_method('add_sweep_tx', self.add_sweep_tx)
async def run(self): async def run(self):
self.runner = web.AppRunner(self.app) self.runner = web.AppRunner(self.app)