Page MenuHomePhabricator

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

Authored by jasonbcox on Wed, Mar 27, 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
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

jasonbcox created this revision.Wed, Mar 27, 22:07
Herald added a reviewer: Restricted Project. · View Herald TranscriptWed, Mar 27, 22:07
Herald added a subscriber: schancel. · View Herald Transcript
Fabien requested changes to this revision.Thu, Mar 28, 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.Thu, Mar 28, 11:32
jasonbcox updated this revision to Diff 7869.Fri, Mar 29, 16:31

Rebase + feedback

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

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

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

Added release notes
Depends on D2761

Fabien accepted this revision.Tue, Apr 2, 14:49
Fabien added inline comments.
src/validation.cpp
809 ↗(On Diff #7892)

Keep GetId()

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

hash -> id

This revision was automatically updated to reflect the committed changes.