be stricter with response typing.
authorgenjix <fake@lol.u>
Mon, 23 Apr 2012 03:09:11 +0000 (04:09 +0100)
committergenjix <fake@lol.u>
Mon, 23 Apr 2012 03:09:11 +0000 (04:09 +0100)
backends/libbitcoin/__init__.py
processor.py

index 0687092..5d9a4d8 100644 (file)
@@ -254,7 +254,6 @@ class NumblocksSubscribe:
     def subscribe(self, request):
         latest = self.latest.get()
         response = {"id": request["id"],
-                    "method": "blockchain.numblocks.subscribe",
                     "result": latest,
                     "error": None}
         self.processor.push_response(response)
index e41e303..4005408 100644 (file)
@@ -189,7 +189,8 @@ class Session:
             self.subscriptions.append(subdesc)
 
     # subdesc = A subscription description
-    def build_subdesc(self, method, params):
+    @staticmethod
+    def build_subdesc(method, params):
         if method == "blockchain.numblocks.subscribe":
             return method,
         elif method == "blockchain.address.get_history":
@@ -222,18 +223,19 @@ class ResponseDispatcher(threading.Thread):
         #print "pop response", response
         internal_id = response.get('id')
         method = response.get('method')
-        params = response.get('params', [])
+        params = response.get('params')
 
         # A notification
-        if internal_id is None and method is None:
-            self.notification(response)
-        elif internal_id is not None:
+        if internal_id is None and method is not None and params is not None:
+            self.notification(method, params, response)
+        # A response
+        elif internal_id is not None and method is None and params is None:
             self.send_response(internal_id, response)
         else:
             print "no method", response
 
-    def notification(self, response):
-        subdesc = self.build_subdesc(method, params)
+    def notification(self, method, params, response):
+        subdesc = Session.build_subdesc(method, params)
         for session in self.processor.sessions:
             if session.stopped():
                 continue