Class: Zold::Push

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

Overview

Wallet pushing command

Instance Method Summary collapse

Constructor Details

#initialize(wallet:, log: Log::Quiet.new) ⇒ Push

Returns a new instance of Push.



31
32
33
34
# File 'lib/zold/commands/push.rb', line 31

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

Instance Method Details

#runObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/zold/commands/push.rb', line 36

def run
  raise 'The wallet is absent' unless @wallet.exists?
  request = Net::HTTP::Put.new("/wallets/#{@wallet.id}")
  request.body = File.read(@wallet.path)
  response = Net::HTTP.new('b1.zold.io', 80).start do |http|
    http.request(request)
  end
  unless response.code.to_i == 200
    raise "Failed to push to the node, code=#{response.code}"
  end
  @log.info("The #{@wallet.id} pushed to the server")
end