1 '''This module contains classes used by pool core to interact with the rest of the pool.
2 Default implementation do almost nothing, you probably want to override these classes
3 and customize references to interface instances in your launcher.
4 (see launcher_demo.tac for an example).
10 log = stratum.logger.get_logger('interfaces')
12 class WorkerManagerInterface(object):
13 def authorize(self, worker_name, worker_password):
16 class ShareManagerInterface(object):
17 def on_submit_share(self, worker_name, block_header, block_hash, shares, timestamp, is_valid):
18 log.info("%s %s %s" % ('Valid' if is_valid else 'INVALID', worker_name, block_hash))
20 def on_submit_block(self, worker_name, block_header, block_hash, timestamp, is_accepted):
21 log.info("Block %s %s" % (block_hash, 'ACCEPTED' if is_accepted else 'REJECTED'))
23 class TimestamperInterface(object):
24 '''This is the only source for current time in the application.
25 Override this for generating unix timestamp in different way.'''
29 class PredictableTimestamperInterface(TimestamperInterface):
30 '''Predictable timestamper may be useful for unit testing.'''
31 start_time = 1345678900 # Some day in year 2012
36 return self.start_time + self.delta
38 class Interfaces(object):
42 template_registry = None
45 def set_worker_manager(cls, manager):
46 cls.worker_manager = manager
49 def set_share_manager(cls, manager):
50 cls.share_manager = manager
53 def set_timestamper(cls, manager):
54 cls.timestamper = manager
57 def set_template_registry(cls, registry):
58 cls.template_registry = registry