Skip to content

Instantly share code, notes, and snippets.

@gipsh
Last active March 20, 2018 17:55
Show Gist options
  • Save gipsh/91021481bed58da26980da051189de0b to your computer and use it in GitHub Desktop.
Save gipsh/91021481bed58da26980da051189de0b to your computer and use it in GitHub Desktop.
require_relative './block'
class Blockchain
attr_reader :blocks
def initialize
genesis = Block.new "genesis block", ""
@blocks = [genesis]
end
def add_block(block)
@blocks << block
end
def create_block(data)
last_block = @blocks.last
new_block = Block.new(data, last_block.hash)
add_block(new_block)
puts "new block added"
end
def dump
@blocks.each_with_index do |block, idx|
puts "#{idx} #{block.hash} #{block.data}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment