class BlockchainLite::Bitcoin::Block::Header

Attributes

data[R]
hash[R]
index[R]
previous_hash[R]
timestamp[R]

Public Class Methods

new(index, data, previous_hash) click to toggle source
# File lib/blockchain-lite/bitcoin/block.rb, line 26
def initialize(index, data, previous_hash)
  @index         = index
  @timestamp     = Time.now.utc    ## note: use coordinated universal time (utc)
  @data          = data
  @previous_hash = previous_hash
  @hash          = calc_hash
end

Private Instance Methods

calc_hash() click to toggle source
# File lib/blockchain-lite/bitcoin/block.rb, line 36
def calc_hash
  sha = Digest::SHA256.new
  sha.update( @index.to_s + @timestamp.to_s + @data + @previous_hash )
  sha.hexdigest
end