X-Git-Url: https://git.novaco.in/?p=stratum-mining.git;a=blobdiff_plain;f=mining%2Finterfaces.py;fp=mining%2Finterfaces.py;h=40f1d2f1a953c0a4ebb3eb1b855c6b0abd823799;hp=1fef21a941bcaa6810fe14c14db946a3cc206e2f;hb=23ebc8506325ec4b8a60ce3c49cab96ae87c006b;hpb=8a7474eb0eefdbc68e9b57371a68c25f33427f0d diff --git a/mining/interfaces.py b/mining/interfaces.py index 1fef21a..40f1d2f 100644 --- a/mining/interfaces.py +++ b/mining/interfaces.py @@ -2,7 +2,7 @@ Default implementation do almost nothing, you probably want to override these classes and customize references to interface instances in your launcher. (see launcher_demo.tac for an example). -''' +''' import time from twisted.internet import reactor, defer @@ -15,22 +15,22 @@ class WorkerManagerInterface(object): # Fire deferred when manager is ready self.on_load = defer.Deferred() self.on_load.callback(True) - + def authorize(self, worker_name, worker_password): return True class ShareLimiterInterface(object): '''Implement difficulty adjustments here''' - + def submit(self, connection_ref, current_difficulty, timestamp): '''connection - weak reference to Protocol instance current_difficulty - difficulty of the connection timestamp - submission time of current share - + - raise SubmitException for stop processing this request - call mining.set_difficulty on connection to adjust the difficulty''' pass - + class ShareManagerInterface(object): def __init__(self): # Fire deferred when manager is ready @@ -40,13 +40,13 @@ class ShareManagerInterface(object): def on_network_block(self, prevhash): '''Prints when there's new block coming from the network (possibly new round)''' pass - + def on_submit_share(self, worker_name, block_header, block_hash, shares, timestamp, is_valid): log.info("%s %s %s" % (block_hash, 'valid' if is_valid else 'INVALID', worker_name)) - + def on_submit_block(self, is_accepted, worker_name, block_header, block_hash, timestamp): log.info("Block %s %s" % (block_hash, 'ACCEPTED' if is_accepted else 'REJECTED')) - + class TimestamperInterface(object): '''This is the only source for current time in the application. Override this for generating unix timestamp in different way.''' @@ -57,34 +57,34 @@ class PredictableTimestamperInterface(TimestamperInterface): '''Predictable timestamper may be useful for unit testing.''' start_time = 1345678900 # Some day in year 2012 delta = 0 - + def time(self): self.delta += 1 return self.start_time + self.delta - + class Interfaces(object): worker_manager = None share_manager = None share_limiter = None timestamper = None template_registry = None - + @classmethod def set_worker_manager(cls, manager): - cls.worker_manager = manager - - @classmethod + cls.worker_manager = manager + + @classmethod def set_share_manager(cls, manager): cls.share_manager = manager - @classmethod + @classmethod def set_share_limiter(cls, limiter): cls.share_limiter = limiter - + @classmethod def set_timestamper(cls, manager): cls.timestamper = manager - + @classmethod def set_template_registry(cls, registry): - cls.template_registry = registry \ No newline at end of file + cls.template_registry = registry