move callbacks to the network class
[electrum-nvc.git] / electrum
index 0e684c6..91141ee 100755 (executable)
--- a/electrum
+++ b/electrum
@@ -107,7 +107,6 @@ if __name__ == '__main__':
         util.check_windows_wallet_migration()
 
     config = SimpleConfig(config_options)
-    storage = WalletStorage(config)
 
     if len(args)==0:
         url = None
@@ -129,19 +128,13 @@ if __name__ == '__main__':
             #sys.exit("Error: Unknown GUI: " + gui_name )
         
         # network interface
-        interface = Interface(config, True)
-        interface.start(wait = False)
-        interface.send([('server.peers.subscribe',[])])
-
-        blockchain = BlockchainVerifier(interface, config)
-        blockchain.start()
+        network = Network(config)
+        network.start()
 
-        gui = gui.ElectrumGui(config, interface, blockchain)
+        gui = gui.ElectrumGui(config, network)
         gui.main(url)
         
-        interface.stop()
-        blockchain.stop()
-
+        network.stop()
         # we use daemon threads, their termination is enforced.
         # this sleep command gives them time to terminate cleanly. 
         time.sleep(0.1)
@@ -149,6 +142,7 @@ if __name__ == '__main__':
 
 
     # instanciate wallet for command-line
+    storage = WalletStorage(config)
     wallet = Wallet(storage)
 
     if cmd not in known_commands:
@@ -323,15 +317,13 @@ if __name__ == '__main__':
 
     # open session
     if cmd not in offline_commands and not options.offline:
-        interface = Interface(config)
-        interface.register_callback('connected', lambda: sys.stderr.write("Connected to " + interface.connection_msg + "\n"))
-
-        if not interface.start(wait=True):
+        network = Network(config)
+        network.register_callback('connected', lambda: sys.stderr.write("Connected to " + network.interface.connection_msg + "\n"))
+        if not network.start(wait=True):
             print_msg("Not connected, aborting.")
             sys.exit(1)
-        blockchain = BlockchainVerifier(interface, config)
-        blockchain.start()
-        wallet.start_threads(interface, blockchain)
+
+        wallet.start_threads(network)
         wallet.update()
 
 
@@ -347,9 +339,9 @@ if __name__ == '__main__':
             if raw_input("Are you sure you want to continue? (y/n) ") in ['y','Y','yes']:
                 wallet.config.path = ns
                 wallet.seed = ''
-                wallet.config.set_key('seed', '', True)
+                wallet.storage.put('seed', '', True)
                 wallet.use_encryption = False
-                wallet.config.set_key('use_encryption', wallet.use_encryption, True)
+                wallet.storage.put('use_encryption', wallet.use_encryption, True)
                 for k in wallet.imported_keys.keys(): wallet.imported_keys[k] = ''
                 wallet.config.set_key('imported_keys',wallet.imported_keys, True)
                 print_msg("Done.")
@@ -358,12 +350,12 @@ if __name__ == '__main__':
 
     elif cmd == 'getconfig':
         key = args[1]
-        print_msg(wallet.config.get(key))
+        print_msg(config.get(key))
 
     elif cmd == 'setconfig':
         key, value = args[1:3]
         if key not in ['seed', 'seed_version', 'master_public_key', 'use_encryption']:
-            wallet.config.set_key(key, value, True)
+            config.set_key(key, value, True)
             print_msg(True)
         else:
             print_msg(False)
@@ -392,7 +384,6 @@ if __name__ == '__main__':
 
     if cmd not in offline_commands and not options.offline:
         wallet.stop_threads()
-        interface.stop()
-        blockchain.stop()
+        network.stop()
         time.sleep(0.1)
         sys.exit(0)