From: genjix Date: Wed, 21 Mar 2012 23:23:05 +0000 (+0000) Subject: Notify on new blocks. X-Git-Url: https://git.novaco.in/?p=electrum-server.git;a=commitdiff_plain;h=e00dbd9c1ab427f8c73bbe0f2a5791d8e30ce97e Notify on new blocks. --- diff --git a/server-genjix.py b/server-genjix.py index 58dd38c..be44dba 100644 --- a/server-genjix.py +++ b/server-genjix.py @@ -100,20 +100,32 @@ class NumblocksSubscribe: self.backend.blockchain.subscribe_reorganize(self.reorganize) self.backend.blockchain.fetch_last_depth(self.set_last_depth) self.latest = GhostValue() + self.subscribed = [] def subscribe(self, session, request): last = self.latest.get() session.push_response({"id": request["id"], "result": last}) + with self.lock: + self.subscribed.append((session, request)) def set_last_depth(self, ec, last_depth): if ec: print "Error retrieving last depth", ec else: - with self.lock: - self.latest.set(last_depth) + self.latest.set(last_depth) def reorganize(self, ec, fork_point, arrivals, replaced): - pass + latest = fork_point + len(arrivals) + self.latest.set(latest) + subscribed = self.spring_clean() + for session, request in subscribed: + session.push_response({"id": request["id"], "result": latest}) + + def spring_clean(self): + with self.lock: + self.subscribed = [sub for sub in self.subscribed + if not sub[0].stopped()] + return self.subscribed[:] class LibbitcoinProcessor(stratum.Processor):