|
|
@ -89,7 +89,7 @@ def get_server(config): |
|
|
|
|
|
|
|
class Daemon(DaemonThread): |
|
|
|
|
|
|
|
def __init__(self, config, fd, is_android): |
|
|
|
def __init__(self, config, fd, is_gui): |
|
|
|
DaemonThread.__init__(self) |
|
|
|
self.config = config |
|
|
|
if config.get('offline'): |
|
|
@ -103,14 +103,10 @@ class Daemon(DaemonThread): |
|
|
|
|
|
|
|
self.gui = None |
|
|
|
self.wallets = {} |
|
|
|
if not is_android: |
|
|
|
# Setup JSONRPC server |
|
|
|
self.cmd_runner = Commands(self.config, None, self.network) |
|
|
|
self.init_server(config, fd) |
|
|
|
else: |
|
|
|
self.server = None |
|
|
|
# Setup JSONRPC server |
|
|
|
self.init_server(config, fd, is_gui) |
|
|
|
|
|
|
|
def init_server(self, config, fd): |
|
|
|
def init_server(self, config, fd, is_gui): |
|
|
|
host = config.get('rpchost', '127.0.0.1') |
|
|
|
port = config.get('rpcport', 0) |
|
|
|
try: |
|
|
@ -122,14 +118,17 @@ class Daemon(DaemonThread): |
|
|
|
return |
|
|
|
os.write(fd, bytes(repr((server.socket.getsockname(), time.time())), 'utf8')) |
|
|
|
os.close(fd) |
|
|
|
self.server = server |
|
|
|
server.timeout = 0.1 |
|
|
|
for cmdname in known_commands: |
|
|
|
server.register_function(getattr(self.cmd_runner, cmdname), cmdname) |
|
|
|
server.register_function(self.run_cmdline, 'run_cmdline') |
|
|
|
server.register_function(self.ping, 'ping') |
|
|
|
server.register_function(self.run_daemon, 'daemon') |
|
|
|
server.register_function(self.run_gui, 'gui') |
|
|
|
self.server = server |
|
|
|
if is_gui: |
|
|
|
server.register_function(self.run_gui, 'gui') |
|
|
|
else: |
|
|
|
server.register_function(self.run_daemon, 'daemon') |
|
|
|
self.cmd_runner = Commands(self.config, None, self.network) |
|
|
|
for cmdname in known_commands: |
|
|
|
server.register_function(getattr(self.cmd_runner, cmdname), cmdname) |
|
|
|
server.register_function(self.run_cmdline, 'run_cmdline') |
|
|
|
|
|
|
|
def ping(self): |
|
|
|
return True |
|
|
@ -178,12 +177,13 @@ class Daemon(DaemonThread): |
|
|
|
def run_gui(self, config_options): |
|
|
|
config = SimpleConfig(config_options) |
|
|
|
if self.gui: |
|
|
|
if hasattr(self.gui, 'new_window'): |
|
|
|
path = config.get_wallet_path() |
|
|
|
self.gui.new_window(path, config.get('url')) |
|
|
|
response = "ok" |
|
|
|
else: |
|
|
|
response = "error: current GUI does not support multiple windows" |
|
|
|
#if hasattr(self.gui, 'new_window'): |
|
|
|
# path = config.get_wallet_path() |
|
|
|
# self.gui.new_window(path, config.get('url')) |
|
|
|
# response = "ok" |
|
|
|
#else: |
|
|
|
# response = "error: current GUI does not support multiple windows" |
|
|
|
response = "error: Electrum GUI already running" |
|
|
|
else: |
|
|
|
response = "Error: Electrum is running in daemon mode. Please stop the daemon first." |
|
|
|
return response |
|
|
|