qt console: accept kwargs for commands.py methods
e.g. make_seed(nbits=264, segwit=True) also allow setting "password" as a kwarg
This commit is contained in:
@@ -107,21 +107,20 @@ class Commands:
|
|||||||
self.network = network
|
self.network = network
|
||||||
self._callback = callback
|
self._callback = callback
|
||||||
|
|
||||||
def _run(self, method, args, password_getter):
|
def _run(self, method, args, password_getter, **kwargs):
|
||||||
# this wrapper is called from the python console
|
"""This wrapper is called from the Qt python console."""
|
||||||
cmd = known_commands[method]
|
cmd = known_commands[method]
|
||||||
if cmd.requires_password and self.wallet.has_password():
|
password = kwargs.get('password', None)
|
||||||
|
if (cmd.requires_password and self.wallet.has_password()
|
||||||
|
and password is None):
|
||||||
password = password_getter()
|
password = password_getter()
|
||||||
if password is None:
|
if password is None:
|
||||||
return
|
return
|
||||||
else:
|
|
||||||
password = None
|
|
||||||
|
|
||||||
f = getattr(self, method)
|
f = getattr(self, method)
|
||||||
if cmd.requires_password:
|
if cmd.requires_password:
|
||||||
result = f(*args, **{'password':password})
|
kwargs['password'] = password
|
||||||
else:
|
result = f(*args, **kwargs)
|
||||||
result = f(*args)
|
|
||||||
|
|
||||||
if self._callback:
|
if self._callback:
|
||||||
self._callback()
|
self._callback()
|
||||||
|
|||||||
@@ -2087,7 +2087,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
|||||||
c = commands.Commands(self.config, self.wallet, self.network, lambda: self.console.set_json(True))
|
c = commands.Commands(self.config, self.wallet, self.network, lambda: self.console.set_json(True))
|
||||||
methods = {}
|
methods = {}
|
||||||
def mkfunc(f, method):
|
def mkfunc(f, method):
|
||||||
return lambda *args: f(method, args, self.password_dialog)
|
return lambda *args, **kwargs: f(method, args, self.password_dialog, **kwargs)
|
||||||
for m in dir(c):
|
for m in dir(c):
|
||||||
if m[0]=='_' or m in ['network','wallet','config']: continue
|
if m[0]=='_' or m in ['network','wallet','config']: continue
|
||||||
methods[m] = mkfunc(c._run, m)
|
methods[m] = mkfunc(c._run, m)
|
||||||
|
|||||||
Reference in New Issue
Block a user