class KeyValueChain::KVPair

Attributes

key[R]
value[R]

Public Class Methods

new(prevBlockHash, key, value, nonce = -1) click to toggle source
# File lib/key_value_chain.rb, line 19
def initialize(prevBlockHash, key, value, nonce = -1)
  @prevBlockHash = prevBlockHash
  @key = key
  @value = value
  @nonce = nonce
  if @nonce < 0
    @none = 0
    until self.is_valid?
      @nonce += 1
    end
  end
end

Public Instance Methods

from_json(json) click to toggle source
# File lib/key_value_chain.rb, line 34
def from_json(json)
  h = JSON.parse(json)
  @prevBlockHash = h["prevBlock"]
  @nonce = h["nonce"]
  @key = h["key"]
  @value = h["value"]
end
is_valid?() click to toggle source
# File lib/key_value_chain.rb, line 45
def is_valid?
  self.to_hash[0,4] == "0000"
end
to_hash() click to toggle source
# File lib/key_value_chain.rb, line 31
def to_hash
  Digest::SHA1.hexdigest self.to_json
end
to_json() click to toggle source
# File lib/key_value_chain.rb, line 41
def to_json
  pairhash = {:prevBlock => @prevBlockHash, :nonce => @nonce, :key => @key, :value => @value}
  JSON.generate(pairhash)
end