remove dangling whitespace
[stratum-mining.git] / lib / extranonce_counter.py
1 import struct
2
3 class ExtranonceCounter(object):
4     '''Implementation of a counter producing
5        unique extranonce across all pool instances.
6        This is just dumb "quick&dirty" solution,
7        but it can be changed at any time without breaking anything.'''
8
9     def __init__(self, instance_id):
10         if instance_id < 0 or instance_id > 31:
11             raise Exception("Current ExtranonceCounter implementation needs an instance_id in <0, 31>.")
12
13         # Last 5 most-significant bits represents instance_id
14         # The rest is just an iterator of jobs.
15         self.counter = instance_id << 27
16         self.size = struct.calcsize('>L')
17
18     def get_size(self):
19         '''Return expected size of generated extranonce in bytes'''
20         return self.size
21
22     def get_new_bin(self):
23         self.counter += 1
24         return struct.pack('>L', self.counter)
25