Class: Lapidar::Assessment

Inherits:
Object
  • Object
show all
Defined in:
lib/lapidar/assessment.rb

Class Method Summary collapse

Class Method Details

.first?(block) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/lapidar/assessment.rb', line 15

def self.first?(block)
  block.number.zero?
end

.genesis?(block) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/lapidar/assessment.rb', line 11

def self.genesis?(block)
  first?(block) && valid_link?(nil, block)
end

.hash(previous_hash, nonce, data) ⇒ Object



19
20
21
# File 'lib/lapidar/assessment.rb', line 19

def self.hash(previous_hash, nonce, data)
  Digest::SHA256.hexdigest("#{previous_hash}-#{nonce}-#{data}")
end

.meets_difficulty?(block) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/lapidar/assessment.rb', line 7

def self.meets_difficulty?(block)
  block.hash.start_with?("0000")
end

.valid_link?(previous_block, block) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/lapidar/assessment.rb', line 3

def self.valid_link?(previous_block, block)
  hash(previous_block&.hash, block.nonce, block.data) == block.hash
end