Skip to content

Instantly share code, notes, and snippets.

@gipsh
Last active March 20, 2018 17:44
Show Gist options
  • Save gipsh/eb71951da4cfeddd3120cefb3af0f3aa to your computer and use it in GitHub Desktop.
Save gipsh/eb71951da4cfeddd3120cefb3af0f3aa to your computer and use it in GitHub Desktop.
blockchain with ruby
require 'digest'
class Block
attr_accessor :hash, :prev_hash, :data, :time
def initialize(data, prev_hash)
@data = data
@prev_hash = prev_hash
@time = Time.now.getutc.to_i
@hash = gen_hash @data,@prev_hash,@time
end
def gen_hash(data, prev_hash, time)
Digest::SHA2.hexdigest "#{data}#{prev_hash}#{time}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment