how does one map a transaction number to a block with just the bitcoind client?

1

I realize this can be done at blockchain.info, but would like to find a way to do this with just the bitcoind client. if all I have is the receiving address and the transaction number, I can't figure out what command or set of commands to use. I can get and decode the raw transaction (bitcoind decoderawtransaction $(bitcoind getrawtransaction 3dd264f603f75871c5a36b61db8e137d8cee6b019a8d5bdfdabd7383ccc47068) | less), but that doesn't give me the block number.

note that I can't use gettransaction because my local box (netbook) isn't the origin nor the destination of the transaction; I get error: {"code":-5,"message":"Invalid or non-wallet transaction id"}. I also can't use listreceivedbyaddress for the same reason, although I don't get an error in this case because I did once send to the address in question from my netbook.

jcomeau_ictx

Posted 2014-02-21T21:09:47.813

Reputation: 157

note to people coming across this question: don't mark down Luca's answer, I hadn't made it clear at the beginning that I couldn't use gettransaction. added that in just now.jcomeau_ictx 2014-02-21T23:16:19.210

1This may be impossible to do without looking up each block down until you get to one that contains it.John T 2014-02-23T05:20:02.057

yeah, I'm beginning to think that's probably my only option. I guess that's what blockchain.info does too, just loads all the blocks into a database.jcomeau_ictx 2014-02-23T05:26:15.923

If you're good with Javascript this can be done easily with Bitcore. It's really interesting and powerful.

John T 2014-02-23T05:30:45.470

Answers

0

figured it out after finding my own previous post about how I found out this info with americancoind, coin seems to have gone to a duplicate address, by its error message on attempting to resend the raw transaction. but bitcoind doesn't tell you what block it's in, merely stating error: {"code":-5,"message":"transaction already in block chain"}. however, on searching through the source (rpcrawtransaction.cpp) I noticed that getrawtransaction takes an extra arg, verbose, which if greater than 0 gives the blockhash:

jcomeau@aspire:~/rentacoder/jcomeau/bitcoin/src$ bitcoind getrawtransaction 3dd264f603f75871c5a36b61db8e137d8cee6b019a8d5bdfdabd7383ccc47068 1 | grep block
    "blockhash" : "000000000000000116f3abab7d0f620f620eae189de29ddb06fe8baae566467a",
    "blocktime" : 1393013064

and with the blockhash you can use getblock:

jcomeau@aspire:~/rentacoder/jcomeau/bitcoin/src$ bitcoind getblock 000000000000000116f3abab7d0f620f620eae189de29ddb06fe8baae566467a
{
    "hash" : "000000000000000116f3abab7d0f620f620eae189de29ddb06fe8baae566467a",
    "confirmations" : 255,
    "size" : 341358,
    "height" : 287092,
    "version" : 2,
    "merkleroot" : "d0fd6154ba64682b48c9c15600ee7c8594336cf4c0a2917b5cbcf1f5a74d2096",

so, 287092 is the block number that contains the transaction.

jcomeau_ictx

Posted 2014-02-21T21:09:47.813

Reputation: 157