Class: Lapidar::Assessment
- Inherits:
-
Object
- Object
- Lapidar::Assessment
- Defined in:
- lib/lapidar/assessment.rb
Class Method Summary collapse
- .first?(block) ⇒ Boolean
- .genesis?(block) ⇒ Boolean
- .hash(previous_hash, nonce, data) ⇒ Object
- .meets_difficulty?(block) ⇒ Boolean
- .valid_link?(previous_block, block) ⇒ Boolean
Class Method Details
.first?(block) ⇒ Boolean
15 16 17 |
# File 'lib/lapidar/assessment.rb', line 15 def self.first?(block) block.number.zero? end |
.genesis?(block) ⇒ 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
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
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 |