Class: ItsyBtc::Commands::PushCommand
- Defined in:
- lib/itsy-btc/commands/push_command.rb
Instance Attribute Summary
Attributes inherited from Command
Instance Method Summary collapse
-
#initialize(tx_path) ⇒ PushCommand
constructor
A new instance of PushCommand.
- #run ⇒ Object
Methods inherited from Command
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
#run ⇒ Object
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 |