Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
[RPC] Transaction details in getblock #8704
Conversation
fanquake
added
the
RPC/REST/ZMQ
label
Sep 12, 2016
|
concept NACK, is two RPC requests really so bad? edit: weak concept NACK |
|
@dcousens yes, two RPC calls is really bad, especially when you want the details of all the transactions in a block. Then you end up running getrawtransaction thousands of times. Also, AFAICT, this doesn't require the txindex in order to get the transactions, unlike getrawtransaction. |
Why? In a batched RPC call, the overhead is literally just 1RTT more.
Perhaps edit: In fact, adding that option would be significantly more useful than this RTT optimisation IMHO. |
How?
Well the functionality to this was already in the code. The BlockToJson method took a parameter for txDetails which was by default false. This just lets you set that to true. |
|
http://www.jsonrpc.org/specification#batch What language are you using? Your RPC library should be able to handle this quite easily. |
|
Huh. Didn't know that. I've been using bash with either curl or bitcoin-cli and python. |
|
Saving roundtrip time is not a valid reason to add a RPC API (see discussion in #8457).
This is the only important fact here: you cannot get this information any other way. getrawtransaction won't get you transactions in blocks, at least without tx index. The only way to get this information right now is to getblock raw then parse the block locally. So concept ACK because of that. |
|
@laanwj would it maybe be better to add functionality via getrawtransaction w/ a block id? (perhaps in addition to this) |
Well yes a "gather transaction [X,...] from prespecified block Y" RPC call could be useful in some rare cases. But on the other hand it'll still have to read the entire block from disk and deserialize it. It's terribly inefficient already. |
|
@laanwj indeed! Forgot about the resulting deserialization. |
|
Concept ACK for all the reasons @laanwj already discussed. |
| throw runtime_error( | ||
| - "getblock \"hash\" ( verbose )\n" | ||
| + "getblock \"hash\" ( verbose ) ( extraVerbose )\n" |
luke-jr
Oct 18, 2016
Member
Double boolean here seems ugly. Maybe allow verbose to be boolean or a number 0-2 (with 2 being extraVerbose)?
laanwj
Oct 18, 2016
Owner
It is ugly, but overloading on type in JSON which is essentially dynamically typed is also ugly.
Named parameters as implemented in #8811 would make this more bearable.
laanwj
Oct 18, 2016
•
Owner
I do agree that for a new interface, a scale for verbosity would have made more sense instead of a boolean.
Maybe that's a better choice I'm just not sure. Changing the meaning of existing arguments is always annoying and means extra testing for backwards compatibility.
|
I'm starting to realize that @luke-jr's idea to accept 0-2 isn't such a bad idea after all. Just rename the argument 'verbosityLevel'. It is easier to use and understand from a user perspective than two booleans (we regularly get confused there in the tests ourselves). Also it'd remove having to deal with the redundant and nonsensical combo It should still accept Also: needs rebase. |
laanwj
referenced this pull request
Oct 26, 2016
Merged
getrawtransaction should take a bool for verbose #9025
|
How should it document in the help message that the old behavior is still accepted? |
|
Rebased and made verbose an int from 0-2 |
|
@achow101 The old behaviour should be considered deprecated, and therefore not documented. |
| "\nArguments:\n" | ||
| "1. \"hash\" (string, required) The block hash\n" | ||
| - "2. verbose (boolean, optional, default=true) true for a json object, false for the hex encoded data\n" | ||
| - "\nResult (for verbose = true):\n" | ||
| + "2. verbose (boolean, optional, default=1) 0 for hex encoded data, 1 for a json object, and 2 for json object with transaction data\n" |
|
@luke-jr done |
added a commit
to bitcoinknots/bitcoin
that referenced
this pull request
Dec 21, 2016
|
merge please? |
|
(Needs rebase) |
|
rebased |
achow101
referenced this pull request
Feb 14, 2017
Closed
Add txdetails parameter to getblock. #9762
|
Is this compatible with callers of getblock which send true instead of 0/1 ? |
|
@pstratem Yes. The old style of calling is maintained for compatibility. |
| + " \"version\" : n, (numeric) The block version\n" | ||
| + " \"versionHex\" : \"00000000\", (string) The block version formatted in hexadecimal\n" | ||
| + " \"merkleroot\" : \"xxxx\", (string) The merkle root\n" | ||
| + " \"tx\" : [ (array of Objects) The transactions\n" |
jnewbery
Feb 15, 2017
Member
I'd suggest not including this in the help output, and just having something like:
" \"tx\" : [ (array of Objects) The transactions. Format is the same as for getrawtransaction call\n"
" ,...\n"
" ],\n"If the output format of TxToJSON() ever changes, I'm sure that changing this help text will be forgotten!
|
Needs rebase. |
|
rebased. also added @jnewbery's suggestion with the help text. |
added a commit
to bitcoinknots/bitcoin
that referenced
this pull request
Apr 21, 2017
sdaftuar
referenced this pull request
May 11, 2017
Closed
RPC: getblock returns coinbase scriptsig #10385
| @@ -716,8 +719,29 @@ UniValue getblock(const JSONRPCRequest& request) | ||
| " \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n" | ||
| " \"nextblockhash\" : \"hash\" (string) The hash of the next block\n" | ||
| "}\n" | ||
| - "\nResult (for verbose=false):\n" | ||
| - "\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n" | ||
| + "\nResult (for verbosity = 2):\n" |
paveljanik
May 12, 2017
Contributor
What about mentioning only the differences to verbosity=1 instead?
achow101
May 12, 2017
Member
something like this?
{
..., Same as for verbosity=1
"tx" : [ (array of Objects) The transactions in the format of the getrawtransaction RPC.
, ...
],
... Same as for verbosity=1
}
paveljanik
May 12, 2017
Contributor
Yup, or maybe even better:
Additional output (for verbosity=1):...
|
@paveljanik I made the change. |
|
Tested ACK e3c9f2d |
achow101 commentedSep 12, 2016
Adds an optional parameter extraVerbose to getblock to have transaction details displayed in a getblock call.