require user to start daemon explicitly
This commit is contained in:
14
electrum
14
electrum
@@ -110,7 +110,6 @@ def arg_parser():
|
|||||||
parser.add_option("-g", "--gui", dest="gui", help="User interface: qt, lite, gtk, text or stdio")
|
parser.add_option("-g", "--gui", dest="gui", help="User interface: qt, lite, gtk, text or stdio")
|
||||||
parser.add_option("-w", "--wallet", dest="wallet_path", help="wallet path")
|
parser.add_option("-w", "--wallet", dest="wallet_path", help="wallet path")
|
||||||
parser.add_option("-o", "--offline", action="store_true", dest="offline", default=False, help="remain offline")
|
parser.add_option("-o", "--offline", action="store_true", dest="offline", default=False, help="remain offline")
|
||||||
parser.add_option("-d", "--daemon", action="store_true", dest="daemon", default=False, help="use daemon")
|
|
||||||
parser.add_option("-C", "--concealed", action="store_true", dest="concealed", default=False, help="don't echo seed to console when restoring")
|
parser.add_option("-C", "--concealed", action="store_true", dest="concealed", default=False, help="don't echo seed to console when restoring")
|
||||||
parser.add_option("-a", "--all", action="store_true", dest="show_all", default=False, help="show all addresses")
|
parser.add_option("-a", "--all", action="store_true", dest="show_all", default=False, help="show all addresses")
|
||||||
parser.add_option("-l", "--labels", action="store_true", dest="show_labels", default=False, help="show the labels of listed addresses")
|
parser.add_option("-l", "--labels", action="store_true", dest="show_labels", default=False, help="show the labels of listed addresses")
|
||||||
@@ -148,7 +147,10 @@ def run_command(cmd, password=None, args=None):
|
|||||||
if args is None:
|
if args is None:
|
||||||
args = [] # Do not use mutables as default values!
|
args = [] # Do not use mutables as default values!
|
||||||
if cmd.requires_network and not options.offline:
|
if cmd.requires_network and not options.offline:
|
||||||
s = get_daemon(config, True)
|
s = get_daemon(config, False)
|
||||||
|
if not s:
|
||||||
|
print_msg("Network daemon is not running. Try 'electrum daemon start'")
|
||||||
|
sys.exit(1)
|
||||||
network = NetworkProxy(s, config)
|
network = NetworkProxy(s, config)
|
||||||
network.start()
|
network.start()
|
||||||
while network.is_connecting():
|
while network.is_connecting():
|
||||||
@@ -238,7 +240,9 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
# network interface
|
# network interface
|
||||||
if not options.offline:
|
if not options.offline:
|
||||||
s = get_daemon(config, start_daemon=options.daemon)
|
s = get_daemon(config, False)
|
||||||
|
if s:
|
||||||
|
print_msg("Connected to daemon")
|
||||||
network = NetworkProxy(s, config)
|
network = NetworkProxy(s, config)
|
||||||
network.start()
|
network.start()
|
||||||
else:
|
else:
|
||||||
@@ -335,8 +339,8 @@ if __name__ == '__main__':
|
|||||||
wallet.create_main_account(password)
|
wallet.create_main_account(password)
|
||||||
|
|
||||||
if not options.offline:
|
if not options.offline:
|
||||||
s = get_daemon(config, True)
|
s = get_daemon(config, False)
|
||||||
network = NetworkProxy(s,config)
|
network = NetworkProxy(s, config)
|
||||||
network.start()
|
network.start()
|
||||||
wallet.start_threads(network)
|
wallet.start_threads(network)
|
||||||
print_msg("Recovering wallet...")
|
print_msg("Recovering wallet...")
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ def do_start_daemon(config):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_daemon(config, start_daemon=True):
|
def get_daemon(config, start_daemon):
|
||||||
import socket
|
import socket
|
||||||
daemon_socket = os.path.join(config.path, DAEMON_SOCKET)
|
daemon_socket = os.path.join(config.path, DAEMON_SOCKET)
|
||||||
daemon_started = False
|
daemon_started = False
|
||||||
@@ -49,8 +49,6 @@ def get_daemon(config, start_daemon=True):
|
|||||||
try:
|
try:
|
||||||
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||||
s.connect(daemon_socket)
|
s.connect(daemon_socket)
|
||||||
if not daemon_started:
|
|
||||||
print_stderr("Connected to daemon")
|
|
||||||
return s
|
return s
|
||||||
except socket.error:
|
except socket.error:
|
||||||
if not start_daemon:
|
if not start_daemon:
|
||||||
@@ -180,7 +178,7 @@ def daemon_loop(server):
|
|||||||
daemon_socket = os.path.join(server.config.path, DAEMON_SOCKET)
|
daemon_socket = os.path.join(server.config.path, DAEMON_SOCKET)
|
||||||
if os.path.exists(daemon_socket):
|
if os.path.exists(daemon_socket):
|
||||||
os.remove(daemon_socket)
|
os.remove(daemon_socket)
|
||||||
daemon_timeout = server.config.get('daemon_timeout', 5*60)
|
daemon_timeout = server.config.get('daemon_timeout', None)
|
||||||
s.bind(daemon_socket)
|
s.bind(daemon_socket)
|
||||||
s.listen(5)
|
s.listen(5)
|
||||||
s.settimeout(1)
|
s.settimeout(1)
|
||||||
@@ -189,6 +187,8 @@ def daemon_loop(server):
|
|||||||
try:
|
try:
|
||||||
connection, address = s.accept()
|
connection, address = s.accept()
|
||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
|
if daemon_timeout is None:
|
||||||
|
continue
|
||||||
if not server.clients:
|
if not server.clients:
|
||||||
if time.time() - t > daemon_timeout:
|
if time.time() - t > daemon_timeout:
|
||||||
print_error("Daemon timeout")
|
print_error("Daemon timeout")
|
||||||
|
|||||||
Reference in New Issue
Block a user