Sha256: 75b3c9a6f25a78cadc36dc7b33618d10760438a3a1d69510d817d2bf4e22b9a8

Contents?: true

Size: 705 Bytes

Versions: 3

Compression:

Stored size: 705 Bytes

Contents

module Equestreum
  class Block
    attr_accessor :data, :prev, :difficulty
    attr_reader :hash, :nonce, :time

    def initialize
      @difficulty = 4

      yield self if block_given?
    end

    def mine
      @time = Time.now.to_i
      @nonce = 0
      loop do
        @hash = Equestreum.hash @nonce, @time, @difficulty, @prev, @data
        if Equestreum.difficulty_attained hash, @difficulty
          break
        else
          @nonce += 1
        end
      end
    end

    def to_h
      h = {}
      [
        :data,
        :time,
        :hash,
        :prev,
        :nonce,
        :difficulty
      ].each do |key|
        h[key] = self.send(key)
      end
      h
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
equestreum-0.1.4 lib/equestreum/block.rb
equestreum-0.1.3 lib/equestreum/block.rb
equestreum-0.1.2 lib/equestreum/block.rb