26 return self.encode_point(result)
27 elif operation == "hash":
28 message = params["message"]
29 hash = hashlib.sha256(message.encode()).digest()30 return hash.hex()
31 else:
32 raise ValueError("Invalid operation")
8 # Store data in IPFS
9 pass
10
11 def retrieve_data(self, hash):12 # Retrieve data from IPFS
13 pass
14
15 def test_calculate_hash(self):
16 block = {"index": 1, "timestamp": 1643723400, "data": "", "previous_hash": "0", "hash": ""}
17 hash = self.blockchain.calculate_hash(block)18 self.assertIsNotNone(hash)
19 self.assertEqual(len(hash), 64)
20
Defining a local variable or function with the same name as a built-in object makes the built-in object unusable within the current scope and makes the code prone to bugs.
dict = {} # dict is a Python builtin!
for idx, student in enumerate(students):
dict[student] = idx
roll_number = {}
for idx, student in enumerate(students):
roll_number[student] = idx