tadd timeout to daemon, update getaddressbalance - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit a5629539e416c8347a3f7e8e8b49ba3a8a80e011 DIR parent 37f2320a8330b75edd1a15278be910b193233c97 HTML Author: ThomasV <thomasv@gitorious> Date: Sun, 2 Mar 2014 10:31:34 +0100 add timeout to daemon, update getaddressbalance Diffstat: M electrum | 11 ++++++++++- M lib/commands.py | 11 +++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) --- DIR diff --git a/electrum b/electrum t@@ -160,6 +160,7 @@ def start_server(): print_msg("Network daemon connected to " + network.interface.connection_msg) from SimpleXMLRPCServer import SimpleXMLRPCServer server = SimpleXMLRPCServer(('localhost',8000), allow_none=True, logRequests=False) + server.network = network server.register_function(lambda: 'pong', 'ping') server.register_function(network.synchronous_get, 'synchronous_get') server.register_function(network.get_servers, 'get_servers') t@@ -181,9 +182,17 @@ def start_daemon(): if (pid2 == 0): # Second child server = start_server() server.running = True + timeout = 60 + t0 = time.time() + server.socket.settimeout(timeout) while server.running: server.handle_request() - print_msg("Daemon stopped") + t = time.time() + if t - t0 > 0.9*timeout: + break + if not server.network.is_connected(): + break + t0 = t sys.exit(0) time.sleep(2) DIR diff --git a/lib/commands.py b/lib/commands.py t@@ -79,8 +79,8 @@ register_command('help', 0, 1, False, False, False, 'Prints this register_command('history', 0, 0, True, True, False, 'Returns the transaction history of your wallet') register_command('importprivkey', 1, 1, False, True, True, 'Import a private key', 'importprivkey <privatekey>') register_command('listaddresses', 2, 2, False, True, False, 'Returns your list of addresses.', '', listaddr_options) -register_command('listunspent', 0, 0, True, False, False, 'Returns the list of unspent inputs in your wallet.') -register_command('getaddressunspent', 1, 1, True, False, False, 'Returns the list of unspent inputs in your wallet.') +register_command('listunspent', 0, 0, True, True, False, 'Returns the list of unspent inputs in your wallet.') +register_command('getaddressunspent', 1, 1, True, False, False, 'Returns the list of unspent inputs for an address.') register_command('mktx', 5, 5, False, True, True, 'Create a signed transaction', 'mktx <recipient> <amount> [label]', payto_options) register_command('mksendmanytx', 4, 4, False, True, True, 'Create a signed transaction', mksendmany_syntax, payto_options) register_command('payto', 5, 5, True, True, True, 'Create and broadcast a transaction.', payto_syntax, payto_options) t@@ -227,8 +227,11 @@ class Commands: return out def getaddressbalance(self, addr): - b = self.network.synchronous_get([ ('blockchain.address.get_balance',[addr]) ])[0] - return str(Decimal(b)/100000000) + out = self.network.synchronous_get([ ('blockchain.address.get_balance',[addr]) ])[0] + out["confirmed"] = str(Decimal(out["confirmed"])/100000000) + out["unconfirmed"] = str(Decimal(out["unconfirmed"])/100000000) + return out + def getproof(self, addr): p = self.network.synchronous_get([ ('blockchain.address.get_proof',[addr]) ])[0]