Renamed: modules -> backends
authorgenjix <fake@lol.u>
Fri, 6 Apr 2012 18:43:15 +0000 (19:43 +0100)
committergenjix <fake@lol.u>
Fri, 6 Apr 2012 18:44:31 +0000 (19:44 +0100)
backends/__init__.py [moved from modules/__init__.py with 100% similarity]
backends/abe/__init__.py [moved from modules/abe/__init__.py with 100% similarity]
backends/irc/__init__.py [moved from modules/irc/__init__.py with 100% similarity]
backends/libbitcoin/__init__.py [moved from modules/libbitcoin/__init__.py with 88% similarity]
backends/libbitcoin/composed.py [moved from modules/libbitcoin/composed.py with 100% similarity]
server.py

similarity index 100%
rename from modules/__init__.py
rename to backends/__init__.py
similarity index 88%
rename from modules/libbitcoin/__init__.py
rename to backends/libbitcoin/__init__.py
index 97440ce..e28132a 100644 (file)
@@ -113,7 +113,8 @@ class NumblocksSubscribe:
     def reorganize(self, ec, fork_point, arrivals, replaced):
         latest = fork_point + len(arrivals)
         self.latest.set(latest)
-        self.processor.push_response({"method":"numblocks.subscribe", "result": latest})
+        response = {"method": "numblocks.subscribe", "result": latest}
+        self.processor.push_response(response)
         self.backend.blockchain.subscribe_reorganize(self.reorganize)
 
 
@@ -129,7 +130,9 @@ class AddressGetHistory:
             bitcoin.bind(self.respond, request, bitcoin._1))
 
     def respond(self, request, result):
-        self.processor.push_response({"id": request["id"], "method":request["method"], "params":request["params"], "result": result})
+        response = {"id": request["id"], "method": request["method"],
+                    "params": request["params"], "result": result}
+        self.processor.push_response(response)
 
 
 class BlockchainProcessor(Processor):
@@ -144,19 +147,17 @@ class BlockchainProcessor(Processor):
         self.backend.stop()
 
     def process(self, request):
-
         print "New request (lib)", request
         if request["method"] == "numblocks.subscribe":
             self.numblocks_subscribe.subscribe(session, request)
         elif request["method"] == "address.get_history":
             self.address_get_history.get(request)
         elif request["method"] == "server.banner":
-            self.push_response({"id": request["id"], "method": request["method"], "params":request["params"],
+            self.push_response({"id": request["id"],
+                "method": request["method"], "params": request["params"],
                 "result": "libbitcoin using python-bitcoin bindings"})
         elif request["method"] == "transaction.broadcast":
             self.broadcast_transaction(request)
-        # Execute and when ready, you call
-        # self.push_response(response)
 
     def broadcast_transaction(self, request):
         raw_tx = bitcoin.data_chunk(str(request["params"]))
@@ -164,18 +165,19 @@ class BlockchainProcessor(Processor):
         try:
             tx = exporter.load_transaction(raw_tx)
         except RuntimeError:
-            response = {"id": request["id"], "method": request["method"], "params":request["params"], "result": None,
-                "error": {"message": 
-                    "Exception while parsing the transaction data.",
-                    "code": -4}}
+            response = {"id": request["id"], "method": request["method"],
+                        "params": request["params"], "result": None,
+                        "error": {"message": 
+                            "Exception while parsing the transaction data.",
+                            "code": -4}}
         else:
             self.backend.protocol.broadcast_transaction(tx)
             tx_hash = str(bitcoin.hash_transaction(tx))
-            response = {"id": request["id"], "method": request["method"], "params":request["params"], "result": tx_hash}
+            response = {"id": request["id"], "method": request["method"],
+                        "params": request["params"], "result": tx_hash}
         self.push_response(response)
 
     def run(self):
-        # this class is a thread. it does nothing in this example.
         print "Warning: pre-alpha prototype. Full of bugs."
         while not self.shared.stopped():
             time.sleep(1)
index f0b2b41..1697150 100755 (executable)
--- a/server.py
+++ b/server.py
@@ -29,7 +29,7 @@ def create_config():
     config = ConfigParser.ConfigParser()
     # set some defaults, which will be overwritten by the config file
     config.add_section('server')
-    config.set('server','banner', 'Welcome to Electrum!')
+    config.set('server', 'banner', 'Welcome to Electrum!')
     config.set('server', 'host', 'localhost')
     config.set('server', 'native_port', '50000')
     config.set('server', 'stratum_tcp_port', '50001')
@@ -80,14 +80,14 @@ if __name__ == '__main__':
     from transports.stratum_tcp import TcpServer
     from transports.native import NativeServer
 
-    from modules.irc import ServerProcessor
+    from backends.irc import ServerProcessor
     backend_name = config.get('server', 'backend')
     if backend_name == "libbitcoin":
         # NativeServer cannot be used with libbitcoin
         native_port = None
         config.set('server', 'native_port', '')
     try:
-        backend = __import__("modules." + backend_name,
+        backend = __import__("backends." + backend_name,
                              fromlist=["BlockchainProcessor"])
     except ImportError:
         sys.stderr.write('Unknown backend specified\n')