def __init__(self, left_node, right_node, data): self.left = left_node self.right = right_node if not self.left and not self.right: self.data = sum256_hex(data) else: data = self.left.data + self.right.data self.data = sum256_hex(data)
def __init__(self, left_node, right_node, data): self.left = left_node self.right = right_node if not self.left and not self.right: self.data = sum256_hex(data) elif (not self.left) and self.right: # change 6.21 self.data = sum256_hex(self.right.data) # change 6.21 elif self.left and (not self.right): # change 6.21 self.data = sum256_hex(self.left.data) # change 6.21 else: data = self.left.data + self.right.data self.data = sum256_hex(data)
def run(self): nonce = 0 found = False hash_hex = None while nonce < self.MAX_SIZE: data = self._prepare_data(nonce) hash_hex = utils.sum256_hex(data) hash_val = int(hash_hex, 16) # sys.stdout.write("data: %s\n" % data) # 7.11 # sys.stdout.write("try nonce == %d\thash_hex == %s \n" % (nonce, hash_hex)) # 7.11 if (hash_val < self._target_bits): found = True break nonce += 1 if found: for i in range(0, 60): try: st = StopMine() if st.h >= st.mine_h: raise NonceNotFoundError time.sleep(1) except: time.sleep(1) else: # print('Not Found nonce') raise NonceNotFoundError('nonce not found') return nonce, hash_hex
def run(self): nonce = 0 found = False hash_hex = None # print('Mining a new block') # change delete while nonce < self.MAX_SIZE: try: st = StopMine() if st.h >= st.mine_h: raise NonceNotFoundError except: pass data = self._prepare_data(nonce) hash_hex = utils.sum256_hex(data) hash_val = int(hash_hex, 16) # sys.stdout.write("data: %s\n" % data) # 7.11 # sys.stdout.write("try nonce == %d\thash_hex == %s \n" % (nonce, hash_hex)) # 7.11 if (hash_val < self._target_bits): found = True break nonce += 1 if found: # print('Found nonce == %d' % nonce) # change delete pass # change else: # print('Not Found nonce') raise NonceNotFoundError('nonce not found') return nonce, hash_hex
def set_id(self): data_list = [str(vin.serialize()) for vin in self.vins] vouts_list = [str(vout.serialize()) for vout in self.vouts] data_list.extend(vouts_list) data = ''.join(data_list) hash = sum256_hex(data) self.txid = hash
def validate(self): # Validates a block's PoW data = self._prepare_data(self._block.nonce) hash_hex = utils.sum256_hex(data) hash_int = int(hash_hex, 16) return True if hash_int < self._target else False
def validate(self): """ validate the block """ data = self._prepare_data(self._block.block_header.nonce) print("data:" + str(data)) hash_hex = utils.sum256_hex(data) hash_val = int(hash_hex, 16) print(hash_hex) return hash_val < self._target_bits
def set_hash(self): """ Set hash of the header """ data_list = [str(self.timestamp), str(self.prev_block_hash), str(self.hash_merkle_root), str(self.height), str(self.nonce)] data = ''.join(data_list) self.hash = sum256_hex(data)
def getHash(self): data_lst = [self.prev_block_hash, self.hash_transactions(), self.timestamp, str(self.bits), str(self._nonce)] data = utils.encode(''.join(map(str, data_lst))) hash_hex = utils.sum256_hex(data) self._hash = utils.encode(hash_hex) return hash_hex
def run(self): nonce = 0 # print('Mining a new block') while nonce < Pow.max_nonce: prepared_data = self.prepare_data(nonce) hash_hex = utils.sum256_hex(prepared_data) hash_int = int(hash_hex, 16) # sys.stdout.write("%s \r" % (hash_hex)) if self._target > hash_int: break else: nonce += 1 return nonce, hash_hex
def new_genesis_block(self, transaction): if 'l' not in self.db: transactions = [transaction] genesis_block = Block.new_genesis_block(transactions) # genesis_block.set_header_hash() data_list = [str(0), str(""), str(""), str(0), str("")] data = ''.join(data_list) genesis_block.block_header.hash = sum256_hex(data) self.db.create(genesis_block.block_header.hash, genesis_block.serialize()) self.set_last_hash(genesis_block.block_header.hash) utxo = UTXOSet() utxo.update(genesis_block)
def run(self): # Performs a proof-of-work nonce = 0 while nonce < self.max_nonce: data = self._prepare_data(nonce) hash_hex = utils.sum256_hex(data) hash_int = int(hash_hex, 16) if hash_int < self._target: break else: nonce += 1 return nonce, hash_hex
def run(self): nonce = 0 print(f"Mining the block {self._block.height}\n") while nonce < self.max_nonce: data = self._prepare_data(nonce) hash_hex = utils.sum256_hex(data) hash_int = int(hash_hex, 16) if hash_int < self._target: break else: nonce += 1 return nonce, hash_hex
def run(self): # Performs a proof-of-work nonce = 0 print('Mining a new block') while nonce < self.max_nonce: data = self._prepare_data(nonce) hash_hex = utils.sum256_hex(data) sys.stdout.write("%s \r" % (hash_hex)) hash_int = int(hash_hex, 16) if hash_int < self._target: break else: nonce += 1 print('\n\n') return nonce, hash_hex
def run(self): nonce = 0 found = False hash_hex = None print('Mining a new block') while nonce < self.MAX_SIZE: data = self._prepare_data(nonce) hash_hex = utils.sum256_hex(data) hash_val = int(hash_hex, 16) sys.stdout.write("data: %s\n" % data) sys.stdout.write("try nonce == %d\thash_hex == %s \n" % (nonce, hash_hex)) if (hash_val < self._target_bits): found = True break nonce += 1 if found: print('Found nonce == %d' % nonce) else: print('Not Found nonce') raise NonceNotFoundError('nonce not found') return nonce, hash_hex
def hash(self): return utils.sum256_hex(pickle.dumps(self))
def validate(self): data = self.prepare_data(self._block.nonce) hash_hex = utils.sum256_hex(data) hash_int = int(hash_hex, 16) return self._target > hash_int
def hash(self): # returns the hash of the Transaction return utils.sum256_hex(pickle.dumps(self))
def set_id(self): self._id = utils.sum256_hex(pickle.dumps(self))