class Zold::Tax
A single tax payment
Constants
- EXACT_SCORE
The exact score a wallet can/must buy in order to pay taxes.
- FEE
This is how much we charge per one transaction per hour of storage. A wallet of 4096 transactions will pay approximately 16ZLD per year. Here is the formula: 16.0 / (365 * 24) / 4096 = 1915 But I like the 1917 number better.
- MAX_PAYMENT
The maximum allowed amount in one transaction. The correct amount should be 1 ZLD, but we allow bigger amounts now since the amount of nodes in the network is still small. When the network grows up, let's put this number back to 1 ZLD.
- MILESTONES
When score strengths were updated. The numbers here indicate the strengths we accepted before these dates.
- PREFIX
Text prefix for taxes details
- TRIAL
The maximum debt we can tolerate at the wallet. If the debt is bigger than this threshold, nodes must stop accepting PUSH.
Public Class Methods
# File lib/zold/tax.rb, line 68 def initialize(wallet, ignore_score_weakness: false, strength: Score::STRENGTH) raise "The wallet must be of type Wallet: #{wallet.class.name}" unless wallet.is_a?(Wallet) @wallet = wallet @ignore_score_weakness = ignore_score_weakness @strength = strength end
Public Instance Methods
# File lib/zold/tax.rb, line 96 def debt FEE * @wallet.txns.count * @wallet.age - paid end
# File lib/zold/tax.rb, line 80 def details(best) "#{PREFIX} #{best.reduced(EXACT_SCORE)}" end
Check whether this tax payment already exists in the wallet.
# File lib/zold/tax.rb, line 76 def exists?(details) !@wallet.txns.find { |t| t.details.start_with?("#{PREFIX} ") && t.details == details }.nil? end
# File lib/zold/tax.rb, line 88 def in_debt? debt > TRIAL end
# File lib/zold/tax.rb, line 100 def paid txns = @wallet.txns scored = txns.map do |t| next if t.amount.positive? pfx, body = t.details.split(' ', 2) next if pfx != PREFIX || body.nil? score = Score.parse(body) next unless score.valid? next unless score.value == EXACT_SCORE || @ignore_score_weakness if score.strength < @strength && !@ignore_score_weakness next unless MILESTONES.find { |d, s| t.date < d && score.strength >= s } end next if t.amount * -1 > MAX_PAYMENT t end.compact.uniq(&:details) scored.empty? ? Amount::ZERO : scored.map(&:amount).inject(&:+) * -1 end
# File lib/zold/tax.rb, line 84 def pay(pvt, best) @wallet.sub([MAX_PAYMENT, debt].min, best.invoice, pvt, details(best)) end
# File lib/zold/tax.rb, line 92 def to_text "A=#{@wallet.age.round} hours, F=#{FEE.to_i}z/th, T=#{@wallet.txns.count}t, Paid=#{paid}" end