Class: Zold::Tax
- Inherits:
-
Object
- Object
- Zold::Tax
- Defined in:
- lib/zold/tax.rb
Overview
A single tax payment
Constant Summary collapse
- MIN_SCORE =
The minimum score a wallet can buy in order to pay taxes.
16
- MAX_PAYMENT =
The maximum allowed amount in one transaction.
Amount.new(zld: 1.0)
- FEE_TXN_HOUR =
This is how much we charge per one transaction per hour of storage. A wallet of 4096 transactions will pay approximately 16ZLD per year.
Amount.new(zld: 16.0 / (365 * 24) / 4096)
- TRIAL =
The maximum debt we can tolerate at the wallet. If the debt is bigger than this threshold, nodes must stop accepting PUSH.
Amount.new(zld: 1.0)
- DAYS_INCREMENT =
For how many days to pay at once.
32
Instance Method Summary collapse
- #debt ⇒ Object
-
#initialize(wallet) ⇒ Tax
constructor
A new instance of Tax.
- #pay(pvt, best) ⇒ Object
Constructor Details
#initialize(wallet) ⇒ Tax
Returns a new instance of Tax.
52 53 54 |
# File 'lib/zold/tax.rb', line 52 def initialize(wallet) @wallet = wallet end |
Instance Method Details
#debt ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/zold/tax.rb', line 61 def debt txns = @wallet.txns scores = txns.map do |t| pfx, body = t.details.split(' ') next if pfx != 'TAXES' || body.nil? score = Score.parse_text(body) next if !score.valid? || score.value < MIN_SCORE next if t.amount > Tax::MAX_PAYMENT score end.reject(&:nil?).uniq(&:hash) paid = scores.empty? ? Amount::ZERO : scores.map(&:amount).inject(&:+) * -1 age_hours = txns.empty? ? 0 : (Time.now - txns.sort_by(&:date)[0].date) / 60 owned = Tax::FEE_TXN_HOUR * txns.count * age_hours owned - paid end |
#pay(pvt, best) ⇒ Object
56 57 58 59 |
# File 'lib/zold/tax.rb', line 56 def pay(pvt, best) fee = Tax::FEE * @wallet.txns.count * Tax::DAYS_INCREMENT * 24 @wallet.sub(fee, best.invoice, pvt, "TAXES #{best.to_text}") end |