blockchain.rb
# Determine if a given blockchain is valid
Determine if a given blockchain is valid
Determine if a given blockchain is valid
def valid_chain?(chain)
    last_block = chain[0]
    current_index = 1
    while current_index < chain.length do
      block = chain[current_index]
      puts last_block
      puts block
      puts "\n------------------\n"
      return false if block['previous_hash'] != hash(block: last_block)
      return false unless valid_proof?(last_proof: last_block['proof'], proof: block['proof'])
      last_block = block
      current_index += 1
    end
    true
  end
def valid_chain? ( chain ) last_block = chain [ 0 ] current_index = 1 while current_index < chain . length do block = chain [ current_index ] puts last_block puts block puts "\n------------------\n" return false if block [ 'previous_hash' ] != hash ( block : last_block ) return false unless valid_proof? ( last_proof : last_block [ 'proof' ] , proof : block [ 'proof' ] ) last_block = block current_index += 1 end true end
Determine if a given blockchain is valid
Determine if a given blockchain is valid
# validate hash of block # validate proof of work
chain