Class: Lapidar::Miner
- Inherits:
-
Object
- Object
- Lapidar::Miner
- Defined in:
- lib/lapidar/miner.rb
Instance Method Summary collapse
-
#initialize ⇒ Miner
constructor
A new instance of Miner.
- #mine(base_block, data = "") ⇒ Object
Constructor Details
#initialize ⇒ Miner
Returns a new instance of Miner.
5 6 7 |
# File 'lib/lapidar/miner.rb', line 5 def initialize @stomach = Digest::SHA2.new(256) end |
Instance Method Details
#mine(base_block, data = "") ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/lapidar/miner.rb', line 9 def mine(base_block, data = "") base_block ||= god nonce = 0 until meets_difficulty?(digest(base_block, nonce, data)) nonce += 1 # Let others do work as well (TODO: nicer solution without thread context in the miner?) Thread.pass if (nonce % 1000).zero? end Block.new(number: base_block.number + 1, hash: digest(base_block, nonce, data), nonce: nonce, data: data) end |