Example #1
0
    def _target(self, job_id, extranonce2, ntime, preheader_bin):
        try:
            start = time.time()

            X, Y = sha.precalc(preheader_bin)

            if sys.maxint > 2**32:
                max_nonce = 2**32
            else:
                max_nonce = 2**31 - 1
            i = 0
            while i < max_nonce:
                if i % 1000 == 0:
                    print i, "%.1f kh/s" % (i * .001 / (time.time() - start + .001))
                    if self._quit:
                        print "QUITTING WORKER"
                        break

                nonce_bin = struct.pack(">I", i)
                if TEST:
                    nonce_bin = "b2957c02".decode("hex")[::-1]

                # header_bin = preheader_bin + nonce_bin
                # hash_bin = doublesha(header_bin)
                # assert hash_bin == finish_dsha(first_sha, nonce_bin)
                hash_bin = sha.finish_dsha(X, Y, nonce_bin)

                val = struct.unpack("<I", hash_bin[-4:])[0]
                if val < THRESH:
                    nonce = nonce_bin[::-1].encode("hex")
                    print nonce, extranonce2, ntime
                    print hash_bin.encode("hex")
                    hash_int = uint256_from_str(hash_bin)
                    block_hash_hex = "%064x" % hash_int
                    print block_hash_hex


                    self._cl.submit(job_id, extranonce2, ntime, nonce)
                    break
                elif val < THRESH*10:
                    print "almost: %d (<%d)" % (val, THRESH)
                i += 1
                # elif i == 0:
                    # print hash_bin.encode("hex")
            self._done_ev.set()
        except:
            traceback.print_exc()
            os._exit(1)
Example #2
0
    def winning_nonces_gen(self, _X, Y):
        while True:
            while self.last_msg is None:
                yield None
                time.sleep(.01)
            m = self.last_msg
            self.last_msg = None

            assert m[0] == '\xaa'
            nonce = m[1:5]
            print "raw nonce: %s" % (nonce.encode("hex"),)
            assert m[5] == '\xaa'
            real_digest = sha.finish_dsha(_X, Y, nonce)
            print "gives digest: %s" % (real_digest.encode("hex"),)
            # assert digest == real_digest, (digest.encode("hex"), real_digest.encode("hex"))
            assert real_digest.endswith("\x00\x00")
            yield nonce[::-1]
Example #3
0
    def winning_nonces_gen(self, _X, Y):
        while True:
            while self.last_msg is None:
                yield None
                time.sleep(.01)
            m = self.last_msg
            self.last_msg = None

            assert m[0] == '\xaa'
            nonce = m[1:5]
            print "raw nonce: %s" % (nonce.encode("hex"), )
            assert m[5] == '\xaa'
            real_digest = sha.finish_dsha(_X, Y, nonce)
            print "gives digest: %s" % (real_digest.encode("hex"), )
            # assert digest == real_digest, (digest.encode("hex"), real_digest.encode("hex"))
            assert real_digest.endswith("\x00\x00")
            yield nonce[::-1]