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

new(wallet, ignore_score_weakness: false, strength: Score::STRENGTH) click to toggle source
# 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

debt() click to toggle source
# File lib/zold/tax.rb, line 96
def debt
  FEE * @wallet.txns.count * @wallet.age - paid
end
details(best) click to toggle source
# File lib/zold/tax.rb, line 80
def details(best)
  "#{PREFIX} #{best.reduced(EXACT_SCORE)}"
end
exists?(details) click to toggle source

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
in_debt?() click to toggle source
# File lib/zold/tax.rb, line 88
def in_debt?
  debt > TRIAL
end
paid() click to toggle source
pay(pvt, best) click to toggle source
# File lib/zold/tax.rb, line 84
def pay(pvt, best)
  @wallet.sub([MAX_PAYMENT, debt].min, best.invoice, pvt, details(best))
end
to_text() click to toggle source
# 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