Last active
March 20, 2018 17:44
-
-
Save gipsh/eb71951da4cfeddd3120cefb3af0f3aa to your computer and use it in GitHub Desktop.
blockchain with ruby
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 '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