Last active
March 20, 2018 17:55
-
-
Save gipsh/91021481bed58da26980da051189de0b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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