Class: ItsyBtc::Commands::GenCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/itsy-btc/commands/gen_command.rb

Instance Attribute Summary

Attributes inherited from Command

#wallet

Instance Method Summary collapse

Methods inherited from Command

args, name, summary

Constructor Details

#initialize(comment = "") ⇒ GenCommand

Returns a new instance of GenCommand.



8
9
10
# File 'lib/itsy-btc/commands/gen_command.rb', line 8

def initialize(comment = "")
  @comment = comment.to_s
end

Instance Method Details

#runObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/itsy-btc/commands/gen_command.rb', line 12

def run
  if @wallet.nil?
    puts "No wallet found. Run `itsy init` to create one."
    exit
  end

  key_gen = Bitcoin::Wallet::KeyGenerator.new
  key = key_gen.get_key
  @wallet.add(key.to_base58, @comment)

  puts "Address #{@wallet.entries.last.address} added to wallet."
end