Page MenuHomePhabricator

Merge #10275: [rpc] Allow fetching tx directly from specified block in getrawtransaction

Authored by jasonbcox on Mar 27 2019, 22:07.



434526a [test] Add tests for getrawtransaction with block hash. (Karl-Johan Alm)
b167951 [rpc] Allow getrawtransaction to take optional blockhash to fetch transaction from a block directly. (Karl-Johan Alm)
a5f5a2c [rpc] Fix fVerbose parsing (remove excess if cases). (Karl-Johan Alm)

Pull request description:

[Reviewer hint: use [?w=1]( to avoid seeing a bunch of indentation changes.]

Presuming a user knows the block hash of the block containing a given transaction, this PR allows them to fetch the raw transaction, even without `-txindex`. It also enables support for getting transactions that are in orphaned blocks.

Note that supplying a block hash will override mempool and txindex support in `GetTransaction`. The rationale behind this is that a transaction may be in multiple places (orphaned blocks) and if the user supplies an explicit block hash it should be adhered to.

$ # a41.. is a tx inside an orphan block ..3c6f.. -- first try getting it normally
$ ./bitcoin-cli getrawtransaction a41e66ee1341aa9fb9475b98cfdc1fe1261faa56c0a49254f33065ec90f7cd79 1
error code: -5
error message:
No such mempool transaction. Use -txindex to enable blockchain transaction queries. Use gettransaction for wallet transactions.
$ # now try with block hash
$ ./bitcoin-cli getrawtransaction a41e66ee1341aa9fb9475b98cfdc1fe1261faa56c0a49254f33065ec90f7cd79 1 0000000000000000003c6fe479122bfa4a9187493937af1734e1e5cd9f198ec7
  "hex": "01000000014e7e81144e42f6d65550e59b715d470c9301fd7ac189[...]90488ac00000000",
  "inMainChain": false,
  "txid": "a41e66ee1341aa9fb9475b98cfdc1fe1261faa56c0a49254f33065ec90f7cd79",
  "hash": "a41e66ee1341aa9fb9475b98cfdc1fe1261faa56c0a49254f33065ec90f7cd79",
  "size": 225,
$ # another tx 6c66... in block 462000
$ ./bitcoin-cli getrawtransaction 6c66b98191e9d6cc671f6817142152ebf6c5cab2ef008397b5a71ac13255a735 1 00000000000000000217f2c12922e321f6d4aa933ce88005a9a493c503054a40
  "hex": "0200000004d157[...]88acaf0c0700",
  "inMainChain": true,
  "txid": "6c66b98191e9d6cc671f6817142152ebf6c5cab2ef008397b5a71ac13255a735",
  "hash": "6c66b98191e9d6cc671f6817142152ebf6c5cab2ef008397b5a71ac13255a735",
  "size": 666,

Tree-SHA512: 279be3818141edd3cc194a9ee65929331920afb30297ab2d6da07293a2d7311afee5c8b00c6457477d9f1f86e86786a9b56878ea3ee19fa2629b829d042d0cda

Backport of Core PR 10275
Completes T562

Test Plan

make check

Diff Detail

rABC Bitcoin ABC
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

jasonbcox created this revision.Mar 27 2019, 22:07
Herald added a reviewer: Restricted Project. · View Herald TranscriptMar 27 2019, 22:07
Herald added a subscriber: schancel. · View Herald Transcript
Fabien requested changes to this revision.Mar 28 2019, 11:32
Fabien added inline comments.
218 ↗(On Diff #7848)

Add braces, use pushKV

796 ↗(On Diff #7848)


808 ↗(On Diff #7848)


This revision now requires changes to proceed.Mar 28 2019, 11:32
jasonbcox updated this revision to Diff 7869.Mar 29 2019, 16:31

Rebase + feedback

Fabien requested changes to this revision.Mar 30 2019, 09:15

Can you add an entry in the release notes for the new rpc param ?

This revision now requires changes to proceed.Mar 30 2019, 09:15
jasonbcox updated this revision to Diff 7892.Apr 1 2019, 22:08

Added release notes
Depends on D2761

Fabien accepted this revision.Apr 2 2019, 14:49
Fabien added inline comments.
809 ↗(On Diff #7892)

Keep GetId()

This revision is now accepted and ready to land.Apr 2 2019, 14:49
jasonbcox updated this revision to Diff 7915.Apr 2 2019, 18:09

hash -> id

This revision was automatically updated to reflect the committed changes.