当前位置: 首页>>代码示例>>Python>>正文


Python ExtranonceCounter.get_new_bin方法代码示例

本文整理汇总了Python中extranonce_counter.ExtranonceCounter.get_new_bin方法的典型用法代码示例。如果您正苦于以下问题:Python ExtranonceCounter.get_new_bin方法的具体用法?Python ExtranonceCounter.get_new_bin怎么用?Python ExtranonceCounter.get_new_bin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在extranonce_counter.ExtranonceCounter的用法示例。


在下文中一共展示了ExtranonceCounter.get_new_bin方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TemplateRegistry

# 需要导入模块: from extranonce_counter import ExtranonceCounter [as 别名]
# 或者: from extranonce_counter.ExtranonceCounter import get_new_bin [as 别名]
class TemplateRegistry(object):
    '''Implements the main logic of the pool. Keep track
    on valid block templates, provide internal interface for stratum
    service and implements block validation and submits.'''
    
    def __init__(self, block_template_class, coinbaser, bitcoin_rpc, instance_id,
                 on_template_callback, on_block_callback):
        self.prevhashes = {}
        self.jobs = weakref.WeakValueDictionary()
        
        self.extranonce_counter = ExtranonceCounter(instance_id)
        self.extranonce2_size = block_template_class.coinbase_transaction_class.extranonce_size \
                - self.extranonce_counter.get_size()
        log.debug("Got to Template Registry")
        self.coinbaser = coinbaser
        self.block_template_class = block_template_class
        self.bitcoin_rpc = bitcoin_rpc
        self.on_block_callback = on_block_callback
        self.on_template_callback = on_template_callback
        
        self.last_block = None
        self.update_in_progress = False
        self.last_update = None
        
        # Create first block template on startup
        self.update_block()
        
    def get_new_extranonce1(self):
        '''Generates unique extranonce1 (e.g. for newly
        subscribed connection.'''
        log.debug("Getting Unique Extronance")
        return self.extranonce_counter.get_new_bin()
    
    def get_last_broadcast_args(self):
        '''Returns arguments for mining.notify
        from last known template.'''
        log.debug("Getting Laat Template")
        return self.last_block.broadcast_args
        
    def add_template(self, block,block_height):
        '''Adds new template to the registry.
        It also clean up templates which should
        not be used anymore.'''
        
        prevhash = block.prevhash_hex

        if prevhash in self.prevhashes.keys():
            new_block = False
        else:
            new_block = True
            self.prevhashes[prevhash] = []
               
        # Blocks sorted by prevhash, so it's easy to drop
        # them on blockchain update
        self.prevhashes[prevhash].append(block)
        
        # Weak reference for fast lookup using job_id
        self.jobs[block.job_id] = block
        
        # Use this template for every new request
        self.last_block = block
        
        # Drop templates of obsolete blocks
        for ph in self.prevhashes.keys():
            if ph != prevhash:
                del self.prevhashes[ph]
                
        log.info("New template for %s" % prevhash)

        if new_block:
            # Tell the system about new block
            # It is mostly important for share manager
            self.on_block_callback(prevhash, block_height)

        # Everything is ready, let's broadcast jobs!
        self.on_template_callback(new_block)
        

        #from twisted.internet import reactor
        #reactor.callLater(10, self.on_block_callback, new_block) 
              
    def update_block(self):
        '''Registry calls the getblocktemplate() RPC
        and build new block template.'''
        
        if self.update_in_progress:
            # Block has been already detected
            return
        
        self.update_in_progress = True
        self.last_update = Interfaces.timestamper.time()
        
        d = self.bitcoin_rpc.getblocktemplate()
        d.addCallback(self._update_block)
        d.addErrback(self._update_block_failed)
        
    def _update_block_failed(self, failure):
        log.error(str(failure))
        self.update_in_progress = False
        
#.........这里部分代码省略.........
开发者ID:Neozonz,项目名称:blockie,代码行数:103,代码来源:template_registry.py

示例2: TemplateRegistry

# 需要导入模块: from extranonce_counter import ExtranonceCounter [as 别名]
# 或者: from extranonce_counter.ExtranonceCounter import get_new_bin [as 别名]
class TemplateRegistry(object):
    '''Implements the main logic of the pool. Keep track
    on valid block templates, provide internal interface for stratum
    service and implements block validation and submits.'''

    def __init__(self, block_template_class, coinbaser, bitcoin_rpc, instance_id,
                 on_template_callback, on_block_callback):
        self.prevhashes = {}
        self.jobs = weakref.WeakValueDictionary()

        self.extranonce_counter = ExtranonceCounter(instance_id)
        self.extranonce2_size = block_template_class.coinbase_transaction_class.extranonce_size \
                - self.extranonce_counter.get_size()

        self.coinbaser = coinbaser
        self.block_template_class = block_template_class
        self.bitcoin_rpc = bitcoin_rpc
        self.on_block_callback = on_block_callback
        self.on_template_callback = on_template_callback

        self.last_block = None
        self.update_in_progress = False
        self.last_update = None

        # Create first block template on startup
        self.update_block()

    def get_new_extranonce1(self):
        '''Generates unique extranonce1 (e.g. for newly
        subscribed connection.'''
        return self.extranonce_counter.get_new_bin()

    def get_last_broadcast_args(self):
        '''Returns arguments for mining.notify
        from last known template.'''
        return self.last_block.broadcast_args

    def add_template(self, block):
        '''Adds new template to the registry.
        It also clean up templates which should
        not be used anymore.'''

        prevhash = block.prevhash_hex

        if prevhash in self.prevhashes.keys():
            new_block = False
        else:
            new_block = True
            self.prevhashes[prevhash] = []

        # Blocks sorted by prevhash, so it's easy to drop
        # them on blockchain update
        self.prevhashes[prevhash].append(block)

        # Weak reference for fast lookup using job_id
        self.jobs[block.job_id] = block

        # Use this template for every new request
        self.last_block = block

        # Drop templates of obsolete blocks
        for ph in self.prevhashes.keys():
            if ph != prevhash:
                del self.prevhashes[ph]

        log.info("New template for %s" % prevhash)

        if new_block:
            # Tell the system about new block
            # It is mostly important for share manager
            self.on_block_callback(prevhash)

        # Everything is ready, let's broadcast jobs!
        self.on_template_callback(new_block)


        #from twisted.internet import reactor
        #reactor.callLater(10, self.on_block_callback, new_block)

    def update_block(self):
        '''Registry calls the getblocktemplate() RPC
        and build new block template.'''

        if self.update_in_progress:
            # Block has been already detected
            return

        self.update_in_progress = True
        self.last_update = Interfaces.timestamper.time()

        d = self.bitcoin_rpc.getblocktemplate()
        d.addCallback(self._update_block)
        d.addErrback(self._update_block_failed)

    def _update_block_failed(self, failure):
        log.error(str(failure))
        self.update_in_progress = False

    def _update_block(self, data):
        start = Interfaces.timestamper.time()
#.........这里部分代码省略.........
开发者ID:jtoomim,项目名称:stratum-mining,代码行数:103,代码来源:template_registry.py

示例3: TemplateRegistry

# 需要导入模块: from extranonce_counter import ExtranonceCounter [as 别名]
# 或者: from extranonce_counter.ExtranonceCounter import get_new_bin [as 别名]
class TemplateRegistry(object):
    '''Implements the main logic of the pool. Keep track
    on valid block templates, provide internal interface for stratum
    service and implements block validation and submits.'''

    def __init__(self, block_template_class, coinbaser, bitcoin_rpc, instance_id,
                 on_template_callback, on_block_callback):
        self.current_prevhash = ''
        self.jobs = weakref.WeakValueDictionary()
        self.minimal_job_id = 0

        self.extranonce_counter = ExtranonceCounter(instance_id)
        self.extranonce2_size = block_template_class.coinbase_transaction_class.extranonce_size \
                - self.extranonce_counter.get_size()

        self.coinbaser = coinbaser
        self.block_template_class = block_template_class
        self.bitcoin_rpc = bitcoin_rpc
        self.on_block_callback = on_block_callback
        self.on_template_callback = on_template_callback

        self._last_template = None
        self.update_in_progress = False
        self.last_update = None

        # Create first block template on startup
        self.update_block()


    def get_block_min_job_id(self):
        return self.minimal_job_id


    def get_new_extranonce1(self):
        '''Generates unique extranonce1 (e.g. for newly
        subscribed connection.'''
        return self.extranonce_counter.get_new_bin()


    def get_last_template_broadcast_args(self):
        '''Returns arguments for mining.notify
        from last known template.'''
        return self._last_template.broadcast_args


    def get_last_template(self):
        ''' Returns the last known template. '''
        return self._last_template


    def _add_template(self, template):
        '''Adds new template to the registry.
        It also clean up templates which should
        not be used anymore.'''

        prevhash = template.prevhash_hex

        # Did we just detect a new block?
        new_block = (prevhash != self.current_prevhash)
        if new_block:
            # Update the current prevhash and throw away all previous jobs (templates)
            self.current_prevhash = prevhash
            self.jobs = {template.job_id: template}

            # Remember the first job's id for the new block. All next templates must have
            # higher job_id in order to be valid.
            self.minimal_job_id = template.job_id

            # Tell the system about new template
            # It is mostly important for share manager
            self.on_block_callback(prevhash)
        else:
            # Check if the new job (template) has valid job_id (related to the first job for the block)
            if template.job_id < self.minimal_job_id:
                log.error("New template has invalid job_id (%s) - minimal %s" % \
                          (template.job_id, self.minimal_job_id))
                return
            # Remember the job for the current block (prevhash)
            self.jobs[template.job_id] = template

        # Use this template for every new request
        self._last_template = template

        log.info("New template %x (cnt %d) for %s" % \
                 (template.job_id, len(self.jobs), prevhash))

        # Everything is ready, let's broadcast jobs!
        self.on_template_callback(new_block)


    def update_blank_block(self, prevhash):
        '''Pick current block, replaces it's prevhash and broadcast
        it as a new template to client. This is work-around for slow
        processing of blocks in bitcoind.'''

        start = posix_time()

        template = self.block_template_class(Interfaces.timestamper, self.coinbaser, JobIdGenerator.get_new_id())
        template.fill_from_another(self._last_template, prevhash)
        self._add_template(template)
#.........这里部分代码省略.........
开发者ID:frrp,项目名称:bitcoin-mining-pool,代码行数:103,代码来源:template_registry.py

示例4: TemplateRegistry

# 需要导入模块: from extranonce_counter import ExtranonceCounter [as 别名]
# 或者: from extranonce_counter.ExtranonceCounter import get_new_bin [as 别名]
class TemplateRegistry(object):
	'''Implements the main logic of the pool. Keep track
	on valid block templates, provide internal interface for stratum
	service and implements block validation and submits.'''

	def __init__(self, template_generator, bitcoin_rpc, instance_id, on_template_callback, on_block_callback):
		log.debug("Got to Template Registry")

		self.prevhashes = {}
		self.jobs = weakref.WeakValueDictionary()

		self.template_generator = template_generator

		self.extranonce_counter = ExtranonceCounter(instance_id)
		self.extranonce2_size = template_generator.get_extranonce_size() - self.extranonce_counter.get_size()

		self.bitcoin_rpc = bitcoin_rpc
		self.on_block_callback = on_block_callback
		self.on_template_callback = on_template_callback

		self.last_template = None
		self.update_in_progress = False
		self.GBT_RPC_ATTEMPT = None
		self.last_block_update_start_time = None

		# Create first block template on startup
		self.update_block()

	def get_new_extranonce1(self):
		'''Generates unique extranonce1 (e.g. for newly
		subscribed connection.'''
		log.debug("Getting Unique Extronance")
		return self.extranonce_counter.get_new_bin()

	def get_last_broadcast_args(self):
		'''Returns arguments for mining.notify
		from last known template.'''
		log.debug("Getting arguments needed for mining.notify")
		return self.last_template.broadcast_args

	def add_template(self, template, block_height):
		'''Adds new template to the registry.
		It also clean up templates which should
		not be used anymore.'''

		prevhash = template.prevhash_hex

		if prevhash in self.prevhashes.keys():
			new_block = False
		else:
			new_block = True
			self.prevhashes[prevhash] = []

		# Blocks sorted by prevhash, so it's easy to drop
		# them on blockchain update
		self.prevhashes[prevhash].append(template)

		# Weak reference for fast lookup using job_id
		self.jobs[template.job_id] = template

		# Use this template for every new request
		self.last_template = template

		# Drop templates of obsolete blocks
		for ph in self.prevhashes.keys():
			if ph != prevhash:
				del self.prevhashes[ph]

		log.info("New template for %s" % prevhash)

		if new_block:
			# Tell the system about new block
			# It is mostly important for share manager
			self.on_block_callback(prevhash, block_height)

		# Everything is ready, let's broadcast jobs!
		self.on_template_callback(new_block)

		#from twisted.internet import reactor
		#reactor.callLater(10, self.on_block_callback, new_block) 

	def update_block(self, force = False):
		'''Registry calls the getblocktemplate() RPC
		and build new block template.'''
		log.info("A block update has been requested.")

		if self.update_in_progress and force and not self.GBT_RPC_ATTEMPT is None:
			# Cancel current block update request (if any)
			log.warning("Forcing block update.")
			self.GBT_RPC_ATTEMPT.cancel()
			self.update_in_progress = False

		if self.update_in_progress:
			# Block has been already detected
			log.warning("Block update already in progress.  Started at: %s" % str(self.last_block_update_start_time))
			# It's possible for this process to get 'hung', lets see how long
			running_time = max(Interfaces.timestamper.time() - self.last_block_update_start_time , 0)
			log.info("Block update running for %i seconds" % running_time)
			# If it's been more than 30 seconds, then cancel it
			# But we don't run in this instance.
#.........这里部分代码省略.........
开发者ID:tuaris,项目名称:TidePool,代码行数:103,代码来源:template_registry.py

示例5: TemplateRegistry

# 需要导入模块: from extranonce_counter import ExtranonceCounter [as 别名]
# 或者: from extranonce_counter.ExtranonceCounter import get_new_bin [as 别名]
class TemplateRegistry(object):
    '''Implements the main logic of the pool. Keep track
    on valid block templates, provide internal interface for stratum
    service and implements block validation and submits.'''
    
    def __init__(self, block_template_class, bitcoin_rpc, instance_id,
                 on_template_callback, on_block_callback):
        self.prevhashes = {}
        self.jobs = weakref.WeakValueDictionary()
        
        self.extranonce_counter = ExtranonceCounter(instance_id)
        self.extranonce2_size = block_template_class.coinbase_transaction_class.extranonce_size \
                - self.extranonce_counter.get_size()
                 
        self.coinbasers_value = []

        for address, percent in settings.BITCOIN_ADDRESSES.iteritems():
            coinbaser = SimpleCoinbaser(address, bitcoin_rpc)
            self.coinbasers_value.append((coinbaser, percent))
        self.block_template_class = block_template_class
        self.bitcoin_rpc = bitcoin_rpc
        self.on_block_callback = on_block_callback
        self.on_template_callback = on_template_callback
        
        self.last_block = None
        self.last_update = None
        
        # Create first block template on startup
        # self.update_block()
        
    def get_new_extranonce1(self):
        '''Generates unique extranonce1 (e.g. for newly
        subscribed connection.'''
        return self.extranonce_counter.get_new_bin()
    
    def get_last_broadcast_args(self):
        '''Returns arguments for mining.notify
        from last known template.'''
        return self.last_block.broadcast_args
        
    def add_template(self, block):
        '''Adds new template to the registry.
        It also clean up templates which should
        not be used anymore.'''
        
        prevhash = block.prevhash_hex

        if prevhash in self.prevhashes.keys():
            new_block = False
        else:
            new_block = True
            self.prevhashes[prevhash] = []
               
        # Blocks sorted by prevhash, so it's easy to drop
        # them on blockchain update
        self.prevhashes[prevhash].append(block)
        
        # Weak reference for fast lookup using job_id
        self.jobs[block.job_id] = block
        
        # Use this template for every new request
        self.last_block = block
        
        # Drop templates of obsolete blocks
        for ph in self.prevhashes.keys():
            if ph != prevhash:
                del self.prevhashes[ph]
                
        logger.log('debug', "New template for %s" % prevhash)

        if new_block:
            # Tell the system about new block
            # It is mostly important for share manager
            self.on_block_callback(prevhash)

        else:
            self.on_template_callback(new_block)
        

    def update_block(self):
        '''Registry calls the getblocktemplate() RPC
        and build new block template.'''
        
        self.last_update = time.time()
        
        data = self.bitcoin_rpc.getblocktemplate()
        
        start = time.time()
                
        template = self.block_template_class(self.coinbasers_value, JobIdGenerator.get_new_id())
        template.fill_from_rpc(data)
        self.add_template(template)

        logger.log('debug', "Update finished, %.03f sec, %d txes" % \
                    (time.time() - start, len(template.vtx)))
        
        return data
    
    def diff_to_target(self, difficulty):
        '''Converts difficulty to target'''
#.........这里部分代码省略.........
开发者ID:sumory,项目名称:BTC,代码行数:103,代码来源:template_registry.py

示例6: TemplateRegistry

# 需要导入模块: from extranonce_counter import ExtranonceCounter [as 别名]
# 或者: from extranonce_counter.ExtranonceCounter import get_new_bin [as 别名]
class TemplateRegistry(object):
    '''Implements the main logic of the pool. Keep track
    on valid block templates, provide internal interface for stratum
    service and implements block validation and submits.'''
    
    def __init__(self, block_template_class, coinbaser, bitcoin_rpc, aux_rpc, instance_id,
                 on_template_callback, on_block_callback):
        self.prevhashes = {}
        self.jobs = weakref.WeakValueDictionary()
        
        self.extranonce_counter = ExtranonceCounter(instance_id)
        self.extranonce2_size = block_template_class.coinbase_transaction_class.extranonce_size \
                - self.extranonce_counter.get_size()
        self.coinbaser = coinbaser
        self.block_template_class = block_template_class
        self.bitcoin_rpc = bitcoin_rpc
        self.on_block_callback = on_block_callback
        self.on_template_callback = on_template_callback
        
        self.last_block = None
        self.update_in_progress = False
        self.last_update = 0
        self.last_height = None

        self.aux_rpc = aux_rpc
        self.aux_update_in_progress = False
        self.aux_new_block = False
        self.aux_last_update = 0
        self.aux_update_counter = 0
        self.aux_data = []
        
        # Create first block template on startup
        self.update_auxs()
        #self.update_block()
        
    def get_new_extranonce1(self):
        '''Generates unique extranonce1 (e.g. for newly
        subscribed connection.'''
        return self.extranonce_counter.get_new_bin()
    
    def get_last_broadcast_args(self):
        '''Returns arguments for mining.notify
        from last known template.'''
        return self.last_block.broadcast_args
        
    def add_template(self, block,block_height):
        '''Adds new template to the registry.
        It also clean up templates which should
        not be used anymore.'''
        
        prevhash = block.prevhash_hex

        if prevhash in self.prevhashes.keys() and not self.aux_new_block:
            new_block = False
        else:
            new_block = True
            self.prevhashes[prevhash] = []
        self.aux_new_block = False       
        # Blocks sorted by prevhash, so it's easy to drop
        # them on blockchain update
        self.prevhashes[prevhash].append(block)
        
        # Weak reference for fast lookup using job_id
        self.jobs[block.job_id] = block
        
        # Use this template for every new request
        self.last_block = block
        
        # Drop templates of obsolete blocks
        for ph in self.prevhashes.keys():
            if ph != prevhash:
                del self.prevhashes[ph]
                
        log.info("New template for %s" % prevhash)

        if new_block:
            # Tell the system about new block
            # It is mostly important for share manager
            self.on_block_callback(block_height)

        # Everything is ready, let's broadcast jobs!
        self.on_template_callback(new_block)

    def update_block(self):
        '''Registry calls the getblocktemplate() RPC
        and build new block template.'''
        
        if self.update_in_progress:
            # Block has been already detected
            return
        
        self.update_in_progress = True
        self.last_update = Interfaces.timestamper.time()
        
        d = self.bitcoin_rpc.getblocktemplate()
        d.addCallback(self._update_block)
        d.addErrback(self._update_block_failed)
        
    def _update_block_failed(self, failure):
        log.error(str(failure))
#.........这里部分代码省略.........
开发者ID:McKenzy83,项目名称:merged-stratum,代码行数:103,代码来源:template_registry.py


注:本文中的extranonce_counter.ExtranonceCounter.get_new_bin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。