def verify(self, data_hash, position, proof): ''' Proof will have the format of dict(height: hash) ''' data = self.data[data_hash].data values = [data[i:i+split_n] for i in range(0, len(data), split_n)] merkle = MerkleTree(values) # Need to make sure the position is right as well? block_hash = merkle.get(position) if proof[-1][0] == block_hash or proof[0][0] == block_hash: return merkle.contains(proof) return None
def test_merkle(): # Handle some data filename = 'merkle.txt' data = read_data(filename) size = check_filesize(filename) # Test Merkle tree first # Split into 8 parts values = data.splitlines() # Test the address is root address is always the same merkle = MerkleTree(values) # print(merkle.address()) # Test contain text merkle_1 in merkle (should have) test_1 = merkle.prove(0) # Prove is correct # Need to check for contains print(merkle.contains(test_1)) return