RPC - Update getblock

Add missing versionHex field (dashpay/dash@e7d9ffa)
Change to use verbosity syntax (dashpay/dash#2506 and
bitcoin/bitcoin#8704)
This commit is contained in:
thephez 2018-12-17 13:17:15 -05:00
parent 003e987621
commit b652fe17d3
No known key found for this signature in database
GPG key ID: BBC8A06DBE236099
3 changed files with 235 additions and 40 deletions

View file

@ -101,7 +101,7 @@ These RPCs are all Dash-specific and not found in Bitcoin Core
{% autocrossref %}
* [GetBestBlockHash][rpc getbestblockhash]: {{summary_getBestBlockHash}}
* [GetBlock][rpc getblock]: {{summary_getBlock}} {{UPDATED0_13_0}}
* [GetBlock][rpc getblock]: {{summary_getBlock}} {{DASH_UPDATED0_13_0}}
* [GetBlockChainInfo][rpc getblockchaininfo]: {{summary_getBlockChainInfo}} {{DASH_UPDATED0_13_0}} {{UPDATED0_12_1}}
* [GetBlockCount][rpc getblockcount]: {{summary_getBlockCount}}
* [GetBlockHash][rpc getblockhash]: {{summary_getBlockHash}}

View file

@ -13,10 +13,10 @@ http://opensource.org/licenses/MIT.
The `getblock` RPC {{summary_getBlock}}
*Parameter #1---header hash*
*Parameter #1---block hash*
{% itemplate ntpd1 %}
- n: "Header Hash"
- n: "Block Hash"
t: "string (hex)"
p: "Required<br>(exactly 1)"
d: "The hash of the header of the block to get, encoded as hex in RPC byte order"
@ -26,14 +26,14 @@ The `getblock` RPC {{summary_getBlock}}
*Parameter #2---whether to get JSON or hex output*
{% itemplate ntpd1 %}
- n: "Format"
t: "boolean"
p: "Optional<br>(true or false)"
d: "Set to `false` to get the block in serialized block format; set to `true` (the default) to get the decoded block as a JSON object"
- n: "Verbosity"
t: "number (int)"
p: "Optional<br>(0 or 1)"
d: "Set to one of the following verbosity levels:<br>`0` - Get the block in serialized block format;<br>`1` - Get the decoded block as a JSON object (default)<br>`2` - Get the decoded block as a JSON object with transaction details"
{% enditemplate %}
*Result (if format was `false`)---a serialized block*
*Result (if verbosity was `0`)---a serialized block*
{% itemplate ntpd1 %}
- n: "`result`"
@ -43,7 +43,7 @@ The `getblock` RPC {{summary_getBlock}}
{% enditemplate %}
*Result (if format was `true` or omitted)---a JSON block*
*Result (if verbosity was `1` or omitted)---a JSON block with transaction hashes*
{% itemplate ntpd1 %}
- n: "`result`"
@ -76,6 +76,11 @@ The `getblock` RPC {{summary_getBlock}}
p: "Required<br>(exactly 1)"
d: "This block's version number. See [block version numbers][section block versions]"
- n: "→<br>`versionHex`"
t: "string (hex)"
p: "Required<br>(exactly 1)"
d: "_Added in Bitcoin Core 0.13.0_<br><br>The block version formatted in hexadecimal"
- n: "→<br>`merkleroot`"
t: "string (hex)"
p: "Required<br>(exactly 1)"
@ -133,63 +138,253 @@ The `getblock` RPC {{summary_getBlock}}
{% enditemplate %}
*Example from Dash Core 0.12.2*
*Result (if verbosity was `2`---a JSON block with full transaction details*
{% assign DEPTH="→" %}
{% include helpers/vars.md %}
{% itemplate ntpd1 %}
- n: "`result`"
t: "object/null"
p: "Required<br>(exactly 1)"
d: "An object containing the requested block, or JSON `null` if an error occurred"
- n: "→<br>`hash`"
t: "string (hex)"
p: "Required<br>(exactly 1)"
d: "The hash of this block's block header encoded as hex in RPC byte order. This is the same as the hash provided in parameter #1"
- n: "→<br>`confirmations`"
t: "number (int)"
p: "Required<br>(exactly 1)"
d: "The number of confirmations the transactions in this block have, starting at 1 when this block is at the tip of the best block chain. This score will be -1 if the the block is not part of the best block chain"
- n: "→<br>`size`"
t: "number (int)"
p: "Required<br>(exactly 1)"
d: "The size of this block in serialized block format, counted in bytes"
- n: "→<br>`height`"
t: "number (int)"
p: "Required<br>(exactly 1)"
d: "The height of this block on its block chain"
- n: "→<br>`version`"
t: "number (int)"
p: "Required<br>(exactly 1)"
d: "This block's version number. See [block version numbers][section block versions]"
- n: "→<br>`versionHex`"
t: "string (hex)"
p: "Required<br>(exactly 1)"
d: "_Added in Bitcoin Core 0.13.0_<br><br>The block version formatted in hexadecimal"
- n: "→<br>`merkleroot`"
t: "string (hex)"
p: "Required<br>(exactly 1)"
d: "The merkle root for this block, encoded as hex in RPC byte order"
- n: "→<br>`tx`"
t: "array"
p: "Required<br>(exactly 1)"
d: "An array containing the TXIDs of all transactions in this block. The transactions appear in the array in the same order they appear in the serialized block"
{{INCLUDE_DECODE_RAW_TRANSACTION}}
- n: "→<br>`time`"
t: "number (int)"
p: "Required<br>(exactly 1)"
d: "The value of the *time* field in the block header, indicating approximately when the block was created"
- n: "→<br>`mediantime`"
t: "number (int)"
p: "Required<br>(exactly 1)"
d: "*Added in Bitcoin Core 0.12.0*<br><br>The median block time in Unix epoch time"
- n: "→<br>`nonce`"
t: "number (int)"
p: "Required<br>(exactly 1)"
d: "The nonce which was successful at turning this particular block into one that could be added to the best block chain"
- n: "→<br>`bits`"
t: "string (hex)"
p: "Required<br>(exactly 1)"
d: "The value of the *nBits* field in the block header, indicating the target threshold this block's header had to pass"
- n: "→<br>`difficulty`"
t: "number (real)"
p: "Required<br>(exactly 1)"
d: "The estimated amount of work done to find this block relative to the estimated amount of work done to find block 0"
- n: "→<br>`chainwork`"
t: "string (hex)"
p: "Required<br>(exactly 1)"
d: "The estimated number of block header hashes miners had to check from the genesis block to this block, encoded as big-endian hex"
- n: "→<br>`previousblockhash`"
t: "string (hex)"
p: "Optional<br>(0 or 1)"
d: "The hash of the header of the previous block, encoded as hex in RPC byte order. Not returned for genesis block"
- n: "→<br>`nextblockhash`"
t: "string (hex)"
p: "Optional<br>(0 or 1)"
d: "The hash of the next block on the best block chain, if known, encoded as hex in RPC byte order"
{% enditemplate %}
*Example from Dash Core 0.13.0*
Get a block in raw hex:
{% highlight bash %}
dash-cli -testnet getblock \
0000000037955fcc39af8b1ae75914ffb422313c0fca7eba96a1ac99c2e57f84 \
false
00000012e877c56af0b33d79aae888b5cb40b47809b4bee764e8fea7a9033994 \
0
{% endhighlight %}
Result (wrapped):
{% highlight text %}
0100002011f5719a0a0c4881ff98b4a68c1c828dc3b10f5b51033f5f93d48dbf\
000000004b8e38f197d6ee878e160d2bae3ce05ab898a6252458ec67ce770140\
260397c4dd2ed659a1dd001d00636b5601010000000100000000000000000000\
00000000000000000000000000000000000000000000ffffffff4b02041204dd\
2ed65908fabe6d6d7445746d63506b62572d2d35584853467a765a6748696972\
30657a3a6f6d656e010000000000000017fffff9020000000d2f6e6f64655374\
726174756d2f00000000058028bb13010000001976a914bad55652dffb1af943\
41015c94feea79793442fd88ac40e553b1020000001976a9142b7856de53d4c1\
823090c98f8ad79862842c09b588ac4094dd89000000001976a914c2c29ebc78\
7954ef99d01c5f79115abf7012fb8e88ac4094dd89000000001976a914d7b47d\
4b40a23c389f5a17754d7f60f511c7d0ec88ac4094dd89000000001976a914dc\
3e0793134b081145ec0c67a9c72a7b297df27c88ac00000000
01000020d2fb795188566bd52deaa8e62de6f59c2833e842f9f6a48cea026689\
04000000c7274c45e043e5953f2d62a1938818b513d8fd4c9f99c2c1541d1449\
7f368602c2d8175c417b4d1d0007a96501010000000100000000000000000000\
00000000000000000000000000000000000000000000ffffffff1202a91a0e2f\
5032506f6f6c2d74444153482fffffffff0404e65a96010000001976a9144f79\
c383bc5d3e9d4d81b98f87337cedfa78953688ac40c3609a010000001976a914\
f627e64c0453f74d879f6e6a37709189af0298da88ac3cdd0504000000001976\
a914badadfdebaa6d015a0299f23fbc1fcbdd72ba96f88ac0000000000000000\
2a6a285fb560df18bc5145faa0860841df9daf30dc544c7b0cdb52ff28c06fa3\
b33924000000000100000000000000
{% endhighlight %}
Get the same block in JSON:
{% highlight bash %}
dash-cli -testnet getblock \
0000000037955fcc39af8b1ae75914ffb422313c0fca7eba96a1ac99c2e57f84
00000012e877c56af0b33d79aae888b5cb40b47809b4bee764e8fea7a9033994
{% endhighlight %}
Result:
{% highlight json %}
{
"hash": "0000000037955fcc39af8b1ae75914ffb422313c0fca7eba96a1ac99c2e57f84",
"confirmations": 3,
"size": 377,
"height": 4612,
"hash": "00000012e877c56af0b33d79aae888b5cb40b47809b4bee764e8fea7a9033994",
"confirmations": 1,
"size": 303,
"height": 6825,
"version": 536870913,
"merkleroot": "c4970326400177ce67ec582425a698b85ae03cae2b0d168e87eed697f1388e4b",
"versionHex": "20000001",
"merkleroot": "0286367f49141d54c1c2999f4cfdd813b5188893a1622d3f95e543e0454c27c7",
"tx": [
"c4970326400177ce67ec582425a698b85ae03cae2b0d168e87eed697f1388e4b"
"0286367f49141d54c1c2999f4cfdd813b5188893a1622d3f95e543e0454c27c7"
],
"time": 1507208925,
"mediantime": 1507208645,
"nonce": 1449878272,
"bits": "1d00dda1",
"difficulty": 1.155066358813473,
"chainwork": "000000000000000000000000000000000000000000000000000001c3e86f0f04",
"previousblockhash": "00000000bf8dd4935f3f03515b0fb1c38d821c8ca6b498ff81480c0a9a71f511",
"nextblockhash": "0000000028817c7fce55d802f3647640600535a983d00e16076f284ec6cb001b"
"time": 1545066690,
"mediantime": 1545065992,
"nonce": 1705576192,
"bits": "1d4d7b41",
"difficulty": 0.01290611629979371,
"chainwork": "00000000000000000000000000000000000000000000000000000647104aa574",
"previousblockhash": "00000004896602ea8ca4f6f942e833289cf5e62de6a8ea2dd56b56885179fbd2"
}
{% endhighlight %}
Get the same block in JSON with transaction details:
{% highlight bash %}
dash-cli -testnet getblock \
00000012e877c56af0b33d79aae888b5cb40b47809b4bee764e8fea7a9033994 2
{% endhighlight %}
Result:
{% highlight json %}
{
"hash": "00000012e877c56af0b33d79aae888b5cb40b47809b4bee764e8fea7a9033994",
"confirmations": 1,
"size": 303,
"height": 6825,
"version": 536870913,
"versionHex": "20000001",
"merkleroot": "0286367f49141d54c1c2999f4cfdd813b5188893a1622d3f95e543e0454c27c7",
"tx": [
{
"txid": "0286367f49141d54c1c2999f4cfdd813b5188893a1622d3f95e543e0454c27c7",
"size": 222,
"version": 1,
"type": 0,
"locktime": 0,
"vin": [
{
"coinbase": "02a91a0e2f5032506f6f6c2d74444153482f",
"sequence": 4294967295
}
],
"vout": [
{
"value": 68.17506820,
"valueSat": 6817506820,
"n": 0,
"scriptPubKey": {
"asm": "OP_DUP OP_HASH160 4f79c383bc5d3e9d4d81b98f87337cedfa789536 OP_EQUALVERIFY OP_CHECKSIG",
"hex": "76a9144f79c383bc5d3e9d4d81b98f87337cedfa78953688ac",
"reqSigs": 1,
"type": "pubkeyhash",
"addresses": [
"yTZg6eePKxbJZyoaC93bVrTUq5vjhFrbst"
]
}
},
{
"value": 68.85000000,
"valueSat": 6885000000,
"n": 1,
"scriptPubKey": {
"asm": "OP_DUP OP_HASH160 f627e64c0453f74d879f6e6a37709189af0298da OP_EQUALVERIFY OP_CHECKSIG",
"hex": "76a914f627e64c0453f74d879f6e6a37709189af0298da88ac",
"reqSigs": 1,
"type": "pubkeyhash",
"addresses": [
"yikzsfaaQ2eZ1RpVUpf1EvedzgGdJD17dC"
]
}
},
{
"value": 0.67493180,
"valueSat": 67493180,
"n": 2,
"scriptPubKey": {
"asm": "OP_DUP OP_HASH160 badadfdebaa6d015a0299f23fbc1fcbdd72ba96f OP_EQUALVERIFY OP_CHECKSIG",
"hex": "76a914badadfdebaa6d015a0299f23fbc1fcbdd72ba96f88ac",
"reqSigs": 1,
"type": "pubkeyhash",
"addresses": [
"ydMSjYqwv4xTossPJ1xndTxwS1Hho9DmuM"
]
}
},
{
"value": 0.00000000,
"valueSat": 0,
"n": 3,
"scriptPubKey": {
"asm": "OP_RETURN 5fb560df18bc5145faa0860841df9daf30dc544c7b0cdb52ff28c06fa3b339240000000001000000",
"hex": "6a285fb560df18bc5145faa0860841df9daf30dc544c7b0cdb52ff28c06fa3b339240000000001000000",
"type": "nulldata"
}
}
],
"instantlock": false
}
],
"time": 1545066690,
"mediantime": 1545065992,
"nonce": 1705576192,
"bits": "1d4d7b41",
"difficulty": 0.01290611629979371,
"chainwork": "00000000000000000000000000000000000000000000000000000647104aa574",
"previousblockhash": "00000004896602ea8ca4f6f942e833289cf5e62de6a8ea2dd56b56885179fbd2"
}
{% endhighlight %}
*See also*

View file

@ -71,7 +71,7 @@ th.tg-sort-header::-moz-selection { background:transparent; }th.tg-sort-header::
<td class="tg-b7b8">Blockchain</td>
<td class="tg-b7b8"><a href="#getblock">GetBlock</a></td>
<td class="tg-dzk6">Y</td>
<td class="tg-dzk6"></td>
<td class="tg-dzk6">Updated in 0.13.0.0</td>
</tr>
<tr>
<td class="tg-yw4l">Blockchain</td>