Example #1
0
def gen_message(target_long, hash_bin, ntime, nonce, error=None):
    log.info('right here, {"time":%s,"target":"%064x","hash":"%064x","difficulty":"%d","ntime":"%s","nonce":"%s","error":"%s"}' % (
            time.time(),
            target_long,
            utils.uint256_from_str(hash_bin),
            MAX_TARGET / float(utils.uint256_from_str(hash_bin)),
            ntime,
            nonce,
            error
            ))
Example #2
0
    def submit(self, header, worker_name):            
        # Drop unused padding
        header = header[:160]

        # 1. Check if blockheader meets requested difficulty
        header_bin = binascii.unhexlify(header[:160])
        rev = ''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ])
        hash_bin = utils.doublesha(rev)
        block_hash = ''.join([ hash_bin[i*4:i*4+4][::-1] for i in range(0, 8) ])
        
        #log.info('!!! %s' % header[:160])
        log.info("Submitting %s" % utils.format_hash(binascii.hexlify(block_hash)))
        
        if utils.uint256_from_str(hash_bin) > self.target:
            log.debug("Share is below expected target")
            return True
        
        # 2. Lookup for job and extranonce used for creating given block header
        try:
            (job, extranonce2) = self.get_job_from_header(header)
        except KeyError:
            log.info("Job not found")
            return False

        # 3. Format extranonce2 to hex string
        extranonce2_hex = binascii.hexlify(self.extranonce2_padding(extranonce2))

        # 4. Parse ntime and nonce from header
        ntimepos = 17*8 # 17th integer in datastring
        noncepos = 19*8 # 19th integer in datastring       
        ntime = header[ntimepos:ntimepos+8] 
        nonce = header[noncepos:noncepos+8]
            
        # 5. Submit share to the pool
        return self.f.rpc('mining.submit', [worker_name, job.job_id, extranonce2_hex, ntime, nonce])
Example #3
0
    def submit(self, newjob, nonce, worker_name):

        #job_id = newjob['library_number']
        #merkle = newjob['solutions']

        ntime = newjob['timestamp']
        merkle = ''.join('{:02x}'.format(x) for x in newjob['merkle tree root'])
        
        # 2. Lookup for job and extranonce used for creating given block header
        try:
            (job, extranonce2) = self.get_job_from_merkle(merkle)
        except KeyError:
            log.info("Job not found from merkle")
            return False

        ### GET HEADER

        header = job.serialize_header(merkle, ntime, nonce)

        #print(header[:160])

        ### BELOW IS LIKE SUBMIT(header, worker_name)

        # Drop unused padding
        header = header[:160]

        # 1. Check if blockheader meets requested difficulty
        header_bin = binascii.unhexlify(header[:160])
        rev = ''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ])
        hash_bin = utils.doublesha(rev)
        block_hash = ''.join([ hash_bin[i*4:i*4+4][::-1] for i in range(0, 8) ])
        
        if utils.uint256_from_str(hash_bin) > self.target:
            log.debug("Share is below expected target")
            return True
        else:
            #log.info('!!! %s' % header[:160])
            log.info("Submitting %s" % utils.format_hash(binascii.hexlify(block_hash)))
        
        # 2. Lookup for job and extranonce used for creating given block header
        try:
            (job, extranonce2) = self.get_job_from_header(header)
        except KeyError:
            log.info("Job not found from header")
            return False

        # 3. Format extranonce2 to hex string
        extranonce2_hex = binascii.hexlify(self.extranonce2_padding(extranonce2))

        # 4. Parse ntime and nonce from header
        ntimepos = 17*8 # 17th integer in datastring
        noncepos = 19*8 # 19th integer in datastring       
        ntime = header[ntimepos:ntimepos+8] 
        nonce = header[noncepos:noncepos+8]
            
        # 5. Submit share to the pool
        #print(worker_name, job.job_id, extranonce2_hex, ntime, nonce)
        return self.f.rpc('mining.submit', [worker_name, job.job_id, extranonce2_hex, ntime, nonce])
Example #4
0
    def submit(self, newjob, nonce, worker_name):

        #job_id = newjob['library_number']
        #merkle = newjob['solutions']

        ntime = newjob['timestamp']
        merkle = ''.join('{:02x}'.format(x)
                         for x in newjob['merkle tree root'])

        # 2. Lookup for job and extranonce used for creating given block header
        try:
            (job, extranonce2) = self.get_job_from_merkle(merkle)
        except KeyError:
            log.info("Job not found from merkle")
            return False

        ### GET HEADER

        header = job.serialize_header(merkle, ntime, nonce)

        #print(header[:160])

        ### BELOW IS LIKE SUBMIT(header, worker_name)

        # Drop unused padding
        header = header[:160]

        # 1. Check if blockheader meets requested difficulty
        header_bin = binascii.unhexlify(header[:160])
        rev = ''.join(
            [header_bin[i * 4:i * 4 + 4][::-1] for i in range(0, 20)])
        hash_bin = utils.doublesha(rev)
        block_hash = ''.join(
            [hash_bin[i * 4:i * 4 + 4][::-1] for i in range(0, 8)])

        if utils.uint256_from_str(hash_bin) > self.target:
            log.debug("Share is below expected target")
            return True
        else:
            #log.info('!!! %s' % header[:160])
            log.info("Submitting %s" %
                     utils.format_hash(binascii.hexlify(block_hash)))

        # 2. Lookup for job and extranonce used for creating given block header
        try:
            (job, extranonce2) = self.get_job_from_header(header)
        except KeyError:
            log.info("Job not found from header")
            return False

        # 3. Format extranonce2 to hex string
        extranonce2_hex = binascii.hexlify(
            self.extranonce2_padding(extranonce2))

        # 4. Parse ntime and nonce from header
        ntimepos = 17 * 8  # 17th integer in datastring
        noncepos = 19 * 8  # 19th integer in datastring
        ntime = header[ntimepos:ntimepos + 8]
        nonce = header[noncepos:noncepos + 8]

        # 5. Submit share to the pool
        #print(worker_name, job.job_id, extranonce2_hex, ntime, nonce)
        return self.f.rpc(
            'mining.submit',
            [worker_name, job.job_id, extranonce2_hex, ntime, nonce])