Can anyone explain the differences in behavior of getrawtransaction and gettransaction in RPC?

0

1

I right clicked the transaction history in the QT client and pasted in the TxID below.

Q1

In the following test, can anyone explain what the purpose of the suffix -000 is and what it's used for?

gettransaction 54b9be14443b152b02ed0b18d27504631cccfa84ce9ada03f9558fbb85b6129c-000

Q2

Why doesn't a raw transaction support the same transaction ID format as the previous command? (I need to remove the -000 characters)

getrawtransaction 54b9be14443b152b02ed0b18d27504631cccfa84ce9ada03f9558fbb85b6129c-000
ERROR: parameter 1 must be hexadecimal string

Q3

When I enable index=1 in bitcoin.conf and reindex, why can't I call GetTransaction for transactions not in my wallet? I would like JSON friendly results

goodguys_activate

Posted 2014-02-18T00:36:22.953

Reputation: 11 898

self-research comment#1 - Here is some commentary on the getrawtransaction feature

goodguys_activate 2014-02-18T00:53:43.193

Answers

1

Q1: A ledger entry in the wallet view corresponds to a single output of a transaction. The suffix is there to distinguish which output of the transaction is used. It's a bit of strange choice to format it that way; in most places, ':' is used as a separator.

Q2: getrawtransaction queries the memory pool, the set of unspent transaction outputs and the blockchain (if txindex is enabled) for a transaction. It doesn't query a single output, so you pass in just the hexadecimal identifier. You can query individual unspent transaction outputs using the gettxout command (which takes a txid + the output index as separate arguments). You can pass an extra 1 as argument to getrawtransaction to have it decoded, instead of just the raw hex. decoderawtransaction can do this for arbitrary hex-encoded raw transactions. Perhaps this is the answer to Q3.

Q3: gettransaction is a wallet RPC. It cannot operate on anything else, as it needs the higher abstraction layer. It computes debit/credit and fee, which requires identifying which outputs are from/to you, and which are change. This requires knowing what keys belong to you. It does not query the blockchain, but you can use 'getrawtransaction [txid] 1' to get a decoded form of blockchain transactions (with txindex enabled).

Pieter Wuille

Posted 2014-02-18T00:36:22.953

Reputation: 54 032

I wonder how the gettransaction command, which uses the accounts feature, will list a transaction (in the GUI) and the corresponding ID when a move is issued. I also wonder about what conditions will cause something other than a -000 to appear.goodguys_activate 2014-02-18T01:08:11.203

I need to generate more test data, but it seems that error checking on the "get a specific output" doesn't work as expected. e.g. I don't get an error with this gettransaction 54b9be14443b152b02ed0b18d27504631cccfa84ce9ada03f9558fbb85b6129c-Invalidgoodguys_activate 2014-02-18T01:14:58.517

If the sender uses sendmany, yoh are unlikely to be the first output, so that will likely result in another suffix than -000. The genesis coinbase transaction is special, and is never processed in terms of the consensus rule. For that reason, it's also not indexed.Pieter Wuille 2014-02-18T08:02:52.260

A move is not a transaction, and you cannot query it using gettransaction.Pieter Wuille 2014-02-18T11:12:01.170