Class: Zold::Taxes
- Inherits:
-
Object
- Object
- Zold::Taxes
- Defined in:
- lib/zold/commands/taxes.rb
Overview
Taxes command
Instance Method Summary collapse
- #debt(wallet, _) ⇒ Object
-
#initialize(wallets:, remotes:, log: Log::Quiet.new) ⇒ Taxes
constructor
A new instance of Taxes.
- #pay(wallet, _) ⇒ Object
- #run(args = []) ⇒ Object
- #show(_, _) ⇒ Object
Constructor Details
Instance Method Details
#debt(wallet, _) ⇒ Object
106 107 108 109 110 |
# File 'lib/zold/commands/taxes.rb', line 106 def debt(wallet, _) raise 'The wallet is absent' unless wallet.exists? tax = Tax.new(wallet) @log.info(tax.debt) end |
#pay(wallet, _) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/zold/commands/taxes.rb', line 85 def pay(wallet, _) raise 'The wallet is absent' unless wallet.exists? tax = Tax.new(wallet) debt = tax.debt @log.debug("The current debt is #{debt} (#{debt.to_i} zents)") if debt <= Tax::TRIAL @log.debug("No need to pay taxes yet, until the debt is less than #{Tax::TRIAL} (#{Tax::TRIAL.to_i} zents)") return end top = top_scores while debt > Amount::ZERO raise 'No acceptable remote nodes, try later' if top.empty? best = top.shift txn = tax.pay(Zold::Key.new(file: opts['private-key']), best) wallet.add(txn) debt -= txn.amount @log.info("#{txn.amount} of taxes paid to #{txn.bnf}, #{debt} left to pay") end @log.info('The wallet is in good standing, all taxes paid') end |
#run(args = []) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/zold/commands/taxes.rb', line 45 def run(args = []) opts = Slop.parse(args, help: true, suppress_errors: true) do |o| o. = "Usage: zold taxes command [options] Available commands: #{Rainbow('taxes pay').green} wallet Pay taxes for the given wallet #{Rainbow('taxes show').green} Show taxes status for the given wallet #{Rainbow('taxes debt').green} Show current debt Available options:" o.string '--private-key', 'The location of RSA private key (default: ~/.ssh/id_rsa)', require: true, default: '~/.ssh/id_rsa' o.bool '--help', 'Print instructions' end mine = Args.new(opts, @log).take || return command = mine[0] case command when 'show' raise 'At least one wallet ID is required' unless mine[1] mine[1..-1].each do |id| show(@wallets.find(Id.new(id), opts)) end when 'debt' raise 'At least one wallet ID is required' unless mine[1] mine[1..-1].each do |id| debt(@wallets.find(Id.new(id), opts)) end when 'pay' raise 'At least one wallet ID is required' unless mine[1] mine[1..-1].each do |id| pay(@wallets.find(Id.new(id)), opts) end else @log.info(opts.to_s) end end |
#show(_, _) ⇒ Object
112 113 114 |
# File 'lib/zold/commands/taxes.rb', line 112 def show(_, _) raise 'Not implemented yet' end |