Hash vs. "Block Hash" in Introduction to Blockchain - 4. Generating Block Hashes


#1

In 4. Generating Block Hashes, we create a Block object containing some properties. One of the properties is hash, initialized with

 self.hash = self.generate_hash()

but the generate_hash() method is this, in the approved answer:

  def generate_hash(self):
    # hash the blocks contents
    block_contents = \
      str(self.timestamp) + \
      str(self.transactions) + \
      str(self.previous_hash) + \
      str(self.nonce)
    return block_contents

which is just concatenating all the text in the other properties of the Block, resulting in a long but human-readable text string, prior to generating what I think of the “real” hash here:

  def block_hash():
    block_hash = sha256(block_contents.encode())
    return block_hash

which makes a much less-readable ASCII string that I would normally think of as a hash, which Wikipedia says is the result of a hash function, like sha256.

Just so I can make sense of these concepts, does it seem more correct, for the purposes of making a Block object in the lesson, to make the hash property the result of concatenating the string and getting the sha of that encoded string to make a hash object? Like this?:

  def generate_hash(self):
    # hash the blocks contents
    block_contents = \
      str(self.timestamp) + \
      str(self.transactions) + \
      str(self.previous_hash) + \
      str(self.nonce)
   # make the hash
    block_hash = sha256(block_contents.encode())
    return block_hash

Is the human-readable ascii string the hash? Or is the hash the “block hash”, like
32ad45b332a7e5869d6d5aac178a1af413b04b206047709ea021df8d4d21ff56 ?