Class: ItsyBtc::Commands::PushCommand

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

Instance Attribute Summary

Attributes inherited from Command

#wallet

Instance Method Summary collapse

Methods inherited from Command

args, name, summary

Constructor Details

#initialize(tx_path) ⇒ PushCommand

Returns a new instance of PushCommand.



10
11
12
# File 'lib/itsy-btc/commands/push_command.rb', line 10

def initialize(tx_path)
  @tx_path = tx_path
end

Instance Method Details

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/itsy-btc/commands/push_command.rb', line 14

def run
  tx = Bitcoin::Protocol::Tx.from_json_file(@tx_path)
  hex = tx.to_payload.unpack("H*")[0]
  
  uri = URI("http://blockchain.info/pushtx")
  response = Net::HTTP.post_form(uri, "tx" => hex)
  if response.is_a? Net::HTTPSuccess
    puts "Transaction pushed successfully."
  else
    puts "#{response.code} Error!"
    puts "Blockchain.info says: #{response.body}" if response.response_body_permitted?
  end
end