Class: Zold::Emission

Inherits:
Object
  • Object
show all
Defined in:
lib/zold/node/emission.rb

Overview

The emission control poine

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ Emission

Returns a new instance of Emission.



40
41
42
# File 'lib/zold/node/emission.rb', line 40

def initialize(root)
  @root = root
end

Instance Method Details

#checkObject



54
55
56
57
58
59
# File 'lib/zold/node/emission.rb', line 54

def check
  return unless @root.root?
  allowed = limit * -1
  balance = @root.balance
  raise "The balance #{balance} of the root wallet is too low (max allowed: #{allowed})" if balance < allowed
end

#limitObject



49
50
51
52
# File 'lib/zold/node/emission.rb', line 49

def limit
  max = Amount::MAX
  Amount.new(coins: (max * quota).to_i)
end

#quotaObject



44
45
46
47
# File 'lib/zold/node/emission.rb', line 44

def quota
  years = @root.age / (24 * 1024)
  1 - (2**-years)
end