GetBlockHeader/获取指定哈希区块头
getblockheader
调用返回本地最优链中指定哈希区块的头,可以指定
不同的参数来返回序列化表示,或者JSON对象表示。
参数
- HeaderHash:区块头哈希
- Format:结果格式,false:序列化格式,true:JSON格式,默认值:true
返回值
getblockheader
调用返回指定的区块头。
如果Format参数值为false,那么返回一个序列化的区块头,否则返回一个JSON 对象格式的区块头,其结构如下:
- hash
- confirmations
- height
- version
- versionHex
- merkleroot
- time
- mediantime
- nonce
- bits
- difficulty
- chainwork
- previousblockhash
- nextblockhash
示例代码
下面的命令返回指定区块头的序列化表示:
~$ bitcoin-cli -testnet getblockheader \
00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09 \
false
输出结果如下:
010000007de867cc8adc5cc8fb6b898ca4462cf9fd667d7830a275277447e608\
00000000338f121232e169d3100edd82004dc2a1f0e1f030c6c488fa61eafa93\
0b0528fe021f7449ffff001d36b4af9a
下面的命令返回同一区块头的JSON表示:
~$ bitcoin-cli -testnet getblockheader \
00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09
输出结果如下:
{
"hash": "00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09",
"confirmations": 437926,
"height": 1000,
"version": 1,
"versionHex": "00000001",
"merkleroot": "fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33",
"time": 1232346882,
"mediantime": 1232344831,
"nonce": 2595206198,
"bits": "1d00ffff",
"difficulty": 1,
"chainwork": "000000000000000000000000000000000000000000000000000003e903e903e9",
"previousblockhash": "0000000008e647742775a230787d66fdf92c46a48c896bfbc85cdc8acc67e87d",
"nextblockhash": "00000000a2887344f8db859e372e7e4bc26b23b9de340f725afbf2edb265b4c6"
}