Class: Zold::Send

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

Overview

Money sending command

Instance Method Summary collapse

Constructor Details

#initialize(payer:, receiver:, amount:, pvtkey:, log: Log::Quiet.new) ⇒ Send

Returns a new instance of Send.



30
31
32
33
34
35
36
# File 'lib/zold/commands/send.rb', line 30

def initialize(payer:, receiver:, amount:, pvtkey:, log: Log::Quiet.new)
  @payer = payer
  @receiver = receiver
  @amount = amount
  @pvtkey = pvtkey
  @log = log
end

Instance Method Details

#runObject



38
39
40
41
42
43
44
# File 'lib/zold/commands/send.rb', line 38

def run
  raise "The amount can't be negative: #{@amount}" if @amount.negative?
  txn = @payer.sub(@amount, @receiver.id, @pvtkey)
  @receiver.add(txn)
  @log.info("#{@amount} sent from #{@payer} to #{@receiver}")
  txn[:id]
end