lian / bitcoin-ruby

bitcoin utils and protocol in ruby.
Other
922 stars 322 forks source link

Reading raw transaction with Bitcoin::P::Tx.new #215

Closed benjii closed 7 years ago

benjii commented 7 years ago

Hi everyone,

I'll come right out and say that I think that I am missing something basic, but I'm tearing my hair our a bit...

I am trying to read this raw transaction: https://live.blockcypher.com/btc-testnet/tx/2d9d3eea9e22829a380e9b5c7a13d00f966d1fe0c43368f8f98cf60ce3839510/

I can get it successfully with;

raw_tx = Faraday.get("https://#{ENV['BTC_BC_EXPLORER_ENDPOINT']}/api/rawtx/#{uo['txid']}").body

which yields the following result:

01000000016ad0753bdf3d69241b44ae085364814d18e64fb5ea5715ca9441357fd75a630f010000006b483045022100aaff866760ae56881d1df2295de850ea1810da9e2201ec1437d0504416d4342c02201e0ae3fd1d5ab4d5ffac33981201d71825ff5c0c2b8ffaae66bfe0b1c2e912d901210299424aff34eda4ade4b53abe1fdbb835e1d840fdf072eb73d6d52e402850a57cffffffff0280a4bf07000000001976a914b7842fbdfe905659e1ee8493aa24e9590a29248988acd1cfe9e4730000001976a914da5ac292f7f6ba760aa88174e92db3fb46648a9f88ac00000000

All good.

But when I try to read it with Bitcoin::P::Tx.new(data) it reads 48 inputs and 0 outputs... perhaps I need to encode it in some alternative format?

Thanks in advance! Ben

azuchi commented 7 years ago

The value of the data is a hex format? If it is hex format, you convert it to binary data. like Bitcoin::P::Tx.new(data.htb)

benjii commented 7 years ago

Thank you!

I feel silly now! :)