Page MenuHomePhabricator

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

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

Details

Summary

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](https://github.com/bitcoin/bitcoin/pull/10275/files?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.

```Bash
$ # 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
https://github.com/bitcoin/bitcoin/pull/10275/files
Completes T562

Test Plan

make check
test_runner.py

Diff Detail

Repository
rABC Bitcoin ABC
Branch
arcpatch-D2746
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 5362
Build 8786: Bitcoin ABC Buildbot (legacy)
Build 8785: arc lint + arc unit

Event Timeline

Fabien requested changes to this revision.Mar 28 2019, 11:32
Fabien added inline comments.
src/rpc/rawtransaction.cpp
218 ↗(On Diff #7848)

Add braces, use pushKV

src/validation.cpp
796 ↗(On Diff #7848)

Braces

808 ↗(On Diff #7848)

Braces

This revision now requires changes to proceed.Mar 28 2019, 11:32
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

Added release notes
Depends on D2761

Fabien added inline comments.
src/validation.cpp
809 ↗(On Diff #7892)

Keep GetId()

This revision is now accepted and ready to land.Apr 2 2019, 14:49