示例#1
0
    def test_against_real_implementation(self):
        self.assertEquals(SHA256.new("").hexdigest(), sha256.hash(""))

        for _ in xrange(10000):
            length = random.randint(3, 1024)
            random_string = "".join([random.choice(string.letters) for _ in xrange(length)])
            real_hash = SHA256.new(random_string).hexdigest()
            my_hash = sha256.hash(random_string)
            self.assertEquals(len(real_hash), len(my_hash))
            self.assertEquals(real_hash, my_hash)
示例#2
0
	def send(self, result, send_callback):
		for nonce in result.miner.nonce_generator(result.nonces):

			h = hash(result.state, result.merkle_end, result.time, result.difficulty, nonce)

			if h[7] != 0:
				hash6 = pack('<I', long(h[6])).encode('hex')
				say_line('Verification failed, check hardware! (%s, %s)', (result.miner.id(), hash6))
				return True # consume this particular result
			else:
				self.diff1_found(bytereverse(h[6]), result.target[6])
				if belowOrEquals(h[:7], result.target[:7]):
					is_block = belowOrEquals(h[:7], self.true_target[:7])

					hash6 = pack('<I', long(h[6])).encode('hex')
					hash5 = pack('<I', long(h[5])).encode('hex')
					self.sent[nonce] = (is_block, hash6, hash5)
					ntime = long(pack('<I', long(result.time)).encode('hex'),16)
					resnonce = long(pack('<I', long(nonce)).encode('hex'),16)
					block = self.source.create_block_header(self.source.merkle_root, ntime, self.source.bits, resnonce)
					hash_header = hashlib.sha256(hashlib.sha256(block).digest()).digest()[::-1]
					shouldSend = int(hash_header.encode('hex_codec'), 16) < self.source.server_difficulty
					print "t->" + str(ntime) + " nonce->" + str(resnonce) + " shouldSend->" + str(shouldSend)
					if shouldSend:
						if not send_callback(result, nonce):
							return False

		return True
示例#3
0
	def send(self, result, send_callback):
		for nonce in result.miner.nonce_generator(result.nonces):
			h = hash(result.state, result.merkle_end, result.time, result.difficulty, nonce)
			if h[7] != 0:
				hash6 = pack('I', long(h[6])).encode('hex')
				say_line('Verification failed, check hardware! (%s, %s)', (result.miner.id(), hash6))
				return True # consume this particular result
			else:
				self.diff1_found(bytereverse(h[6]), result.target[6])
				if belowOrEquals(h[:7], result.target[:7]):
					is_block = belowOrEquals(h[:7], self.true_target[:7])
					hash6 = pack('I', long(h[6])).encode('hex')
					hash5 = pack('I', long(h[5])).encode('hex')
					self.sent[nonce] = (is_block, hash6, hash5)
					if not send_callback(result, nonce):
						return False
		return True
示例#4
0
文件: Switch.py 项目: asasas/poclbm
	def send(self, result, send_callback):
		for nonce in result.miner.nonce_generator(result.nonces):
			h = hash(result.state, result.merkle_end, result.time, result.difficulty, nonce)
			if h[7] != 0:
				hash6 = pack('I', long(h[6])).encode('hex')
				say_line('Verification failed, check hardware! (%s, %s)', (result.miner.id(), hash6))
				return True # consume this particular result
			else:
				self.diff1_found(bytereverse(h[6]), result.target[6])
				if belowOrEquals(h[:7], result.target[:7]):
					is_block = belowOrEquals(h[:7], self.true_target[:7])
					hash6 = pack('I', long(h[6])).encode('hex')
					hash5 = pack('I', long(h[5])).encode('hex')
					self.sent[nonce] = (is_block, hash6, hash5)
					if not send_callback(result, nonce):
						return False
		return True
示例#5
0
def printHash(element):
    print("\"",element,"\"", " => ","\"", sha256.hash(element),"\"")