Class: Zold::Invoice

Inherits:
Object
  • Object
show all
Defined in:
lib/zold/commands/invoice.rb

Overview

Generate invoice

Instance Method Summary collapse

Constructor Details

#initialize(wallets:, log: Log::Quiet.new) ⇒ Invoice

Returns a new instance of Invoice.


33
34
35
36
# File 'lib/zold/commands/invoice.rb', line 33

def initialize(wallets:, log: Log::Quiet.new)
  @wallets = wallets
  @log = log
end

Instance Method Details

#run(args = []) ⇒ Object


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/zold/commands/invoice.rb', line 38

def run(args = [])
  opts = Slop.parse(args, help: true, suppress_errors: true) do |o|
    o.banner = "Usage: zold invoice ID [options]
Where:
'ID' is the wallet ID of the money receiver
Available options:"
    o.integer '--length',
      'The length of the invoice prefix (default: 8)',
      default: 8
    o.bool '--help', 'Print instructions'
  end
  mine = Args.new(opts, @log).take || return
  raise 'Receiver wallet ID is required' if mine[0].nil?
  id = Zold::Id.new(mine[0])
  wallet = @wallets.find(id)
  raise "Wallet #{id} doesn\'t exist in #{@wallets}, do 'zold pull' first" unless wallet.exists?
  invoice(wallet, opts)
end