Author

Topic: how to dig through the block chain (Read 2404 times)

legendary
Activity: 3682
Merit: 1580
August 04, 2013, 09:21:20 PM
#8
You can also use the bitcoind rpc interface directly from your ruby code. I bet you can send it larger arguments than you could over the command line.
jr. member
Activity: 38
Merit: 2
August 01, 2013, 11:50:07 PM
#7

Actually, when I tried transaction 42f4500dec4c6f8cd41337767bdf7e2caa48c153ae2114334a645ac927d03766, I simply get an error -5.  "No information available about transaction".

Code:
$ ./bitcoind getrawtransaction 42f4500dec4c6f8cd41337767bdf7e2caa48c153ae2114334a645ac927d03766
error: {"code":-5,"message":"No information available about transaction"}



never mind.  my mistake. 

in case there are others who run into the same problem. 
after version 0.8.0, you will need to turn on the following
-txindex=1
-reindex=1

after that, you should be able to see the transactions. 
jr. member
Activity: 38
Merit: 2
July 29, 2013, 06:00:39 PM
#6

GetRawTransaction
and then
DecodeRawTransaction


Thanks, this is great! Smiley


BTW, here's a monster transaction:
42f4500dec4c6f8cd41337767bdf7e2caa48c153ae2114334a645ac927d03766
http://blockexplorer.com/tx/42f4500dec4c6f8cd41337767bdf7e2caa48c153ae2114334a645ac927d03766

getrawtransaction gives me a string that's 224 036 (!!!) bytes long.  I just can't use this string as a command line argument to decoderawtransaction because of it's size.

Code:
$ .../bitcoind decoderawtransaction $(.../bitcoind getrawtransaction 42f4500dec4c6f8cd41337767bdf7e2caa48c153ae2114334a645ac927d03766)
bash: ../bitcoin-0.7.0-linux/bin/64/bitcoind: Argument list too long
$ _

This beauty is in the block #55812.

Is there any other way to feed decodetransaction with a string?  (standard input with ".../bitcoind decoderawtransaction -" doesn't work)


Actually, when I tried transaction 42f4500dec4c6f8cd41337767bdf7e2caa48c153ae2114334a645ac927d03766, I simply get an error -5.  "No information available about transaction".

Code:
$ ./bitcoind getrawtransaction 42f4500dec4c6f8cd41337767bdf7e2caa48c153ae2114334a645ac927d03766
error: {"code":-5,"message":"No information available about transaction"}

newbie
Activity: 33
Merit: 0
October 23, 2012, 03:09:41 PM
#5

GetRawTransaction
and then
DecodeRawTransaction


Thanks, this is great! Smiley


BTW, here's a monster transaction:
42f4500dec4c6f8cd41337767bdf7e2caa48c153ae2114334a645ac927d03766
http://blockexplorer.com/tx/42f4500dec4c6f8cd41337767bdf7e2caa48c153ae2114334a645ac927d03766

getrawtransaction gives me a string that's 224 036 (!!!) bytes long.  I just can't use this string as a command line argument to decoderawtransaction because of it's size.

Code:
$ .../bitcoind decoderawtransaction $(.../bitcoind getrawtransaction 42f4500dec4c6f8cd41337767bdf7e2caa48c153ae2114334a645ac927d03766)
bash: ../bitcoin-0.7.0-linux/bin/64/bitcoind: Argument list too long
$ _

This beauty is in the block #55812.

Is there any other way to feed decodetransaction with a string?  (standard input with ".../bitcoind decoderawtransaction -" doesn't work)
legendary
Activity: 2506
Merit: 1010
October 23, 2012, 05:40:34 AM
#4
Now my question is that how can I decode those hexa numbers in the middle to reveal the transaction details?

GetRawTransaction
and then
DecodeRawTransaction

 - http://en.bitcoin.it/wiki/Raw_Transactions#decoderawtransaction_.3Chex_string.3E
newbie
Activity: 33
Merit: 0
October 23, 2012, 05:34:43 AM
#3
I've just discovered that getblockhash and getblock is almost what I need.  The
block number 177666 looks like this:

Code:
$ .../bitcoind getblock $(.../bitcoind getblockhash 177666)
{
    "hash" : "00000000000001df991dc1a906726ef3d4da14445d1da4d0fc2f592c14230e07",
    "confirmations" : 26926,
    "size" : 8885,
    "height" : 177666,
    "version" : 1,
    "merkleroot" : "25eecd8a35132c8509bd720654b173760719f0bc1a6c152782332e025f900f3a",
    "tx" : [
        "91673fc0e244fd861123524e40f408cdfad2a4e5937ca2de18719b7d84208607",
        "7ae132a35fab00488165c8d126216df0abc32c6702312247de6179806e47b18b",
        "27cc4311677cf2fa7eb7483c7c54ab1a01b9bfd659c4c4a6d8fe7674ffc8ac6f",
        "fef0b5d2e668a67dc8c1ad670152845689736bcbaee6564dda6e98f9663c829d",
        "835303eda5e976990008559d530d5f9dc8b8c40aad6e8080f1b334ddde2bda1c",
        "113778e8bdb894e7398361a5e18da7afcef08f43b90e810c8b623c639c047fe2",
        "0ee7d05f049792c929038520771c0d061d326a63d7e517efce1fba651bbf216d",
        "edcbac818fc92e3efe4c2dd7e56a3cc3235451b04408b2c758f1061a47b0dfa9",
        "2d9a5e17b0fa56d8bca18cd2bfc19d2fb6ddcf18b69640b19e7be382e011d2dc",
        "faf5462ecf7b81cb4c373f566961bf2c4f40755b6445c0ac3cdbe12a2c6f795b",
        "fe3b403039639b52520ff7e4361bafef69401daa95610b3eaf31b88713bc8fd2",
        "96d432c162b79bf8289cc36739c2f6c575e24680acda41b27ff545ba0e01968b",
        "4056d2b2fb8e2dab82a2417b7c6f9eb7a94326d4b07a9686855088e99dad777b",
        "fe37bc63e113f0d43beb4659daba54e16724b961e2872a300de93754b61950e7",
        "6c35503c0e27094db57fa5453b897ee32f1ea4b420100165c10861943fe74aaa",
        "97ff1f6a26d3363ac1c1c94c938f6f5a56a30a6401d90527c20e63013de66ddf",
        "bd5b01d4b05d17dd5ac4526b6e38ad3747402c36a9eeffbccd3759c03814ae47",
        "f2ca367d4f3cbf765c546925dbd644a293b91c20bb38f7319abd468b01f22bb2",
        "1be2ff3aceedb10c42ec8f7799db1d03cf90fbf48f819138dba6c35b3c7c816f",
        "41b974db0ae4b7166f242afad28cf7536c0fd742702fa7f246ff1b399666e171",
        "4760c5bb05ec7d0fcf0b900b771eb99d816ad14f249392f42720c0e4bb479ed5",
        "f8027f77d6aa380f2d0f8b43d62e5b0584056d36b9c689c63815361b02609a83",
        "7fdc006c04ae467daf30cb285ebf8ec1ea5fa07519c34abeb7d8c2c945412ec5",
        "a8b602ac2058d07338196753fc898dc9e644f4f62aef49a7a6122d8ad4ebbd7a",
        "44d6023b84bc9e08de5eb93b03ad401a110acc1445708d83a54f722e1725250f",
        "d892ccbee4a99dafdba97ac80b0303229e12f84ec528a06b93e49a7a57cd57ef"
    ],
    "time" : 1335661982,
    "nonce" : 4095730459,
    "bits" : "1a0b1ef7",
    "difficulty" : 1508589.67206029,
    "previousblockhash" : "000000000000005c962ffe88749427c4f9955df639b583419ae717dee05cbf18",
    "nextblockhash" : "00000000000009f8d7ec04748ac5e4a685cb8981fd3ded099ba8c8835f080c24"
}

The same block in blockexplorer is here:
http://blockexplorer.com/block/00000000000001df991dc1a906726ef3d4da14445d1da4d0fc2f592c14230e07

Now my question is that how can I decode those hexa numbers in the middle
to reveal the transaction details?  I want to know the addresses and amounts
encoded here.  Not only those that belong to my wallet but all of them.
legendary
Activity: 2506
Merit: 1010
October 22, 2012, 04:12:54 PM
#2
I would like to do something like this:

Code:
 all_the_transactions_in_the_chain.each { |t|
    puts "#{t.inputs.join(',')} -> #{t.outputs.join(',')}"
  }

Access to the details (inputs and outputs) of a transaction come from Raw Transactions:

 - http://en.bitcoin.it/wiki/Raw_Transactions

To get it in a single query like that, you'ld need to populate a datastore yourself.

And is it possible to write a piece of code that gets called on every confirmed transaction as the bitcoin client gets this information?

Confirmed transaction, or just any new transaction?

The API command "listsinceblock" will let you know new transactions, and then the Raw Transactions will give you the details on it.

[Edit:
I don't want to use blockchain.info, blockexplorer or any other sites.

There are other tools that can help as well.  Armory provides easy access to blockchain data, see the "Extras" folder.   Also libBitcoin might provide this to you as might ABE blockchain explorer source.]
newbie
Activity: 33
Merit: 0
October 22, 2012, 01:33:32 PM
#1
Hello,

I want to iterate through the list of the transactions in Ruby.  Can you
please tell me which gem/lib/solution would be the easiest way?  I
would like to do something like this:

Code:
  all_the_transactions_in_the_chain.each { |t|
    puts "#{t.inputs.join(',')} -> #{t.outputs.join(',')}"
  }

And is it possible to write a piece of code that gets called on every
confirmed transaction as the bitcoin client gets this information?

I don't want to use blockchain.info, blockexplorer or any other
sites.

THX

Jump to: