比特币(Bitcoin) RPC Mining API中getblocktemplate的用法及代码示例。
用法:
getblocktemplate "template_request"
如果请求参数包含‘mode’ key ,则用于在默认的‘template’请求或‘proposal’之间进行显式选择。
它返回构造一个要工作的块所需的数据。
有关完整规范,请参阅BIP 22、23、9和145:
参数1 - template_request
类型:json对象,必需
- 以下规范中的json对象
“rules”:[(必须为json数组)字符串列表“support”,(字符串)客户端支持的软叉部署…],}
{
"mode": "str", (string, optional) This must be set to "template", "proposal" (see BIP 23), or omitted
"capabilities": [ (json array, optional) A list of strings
"support", (string) client side supported feature, 'longpoll', 'coinbasetxn', 'coinbasevalue', 'proposal', 'serverlist', 'workid'
...
],
返回结果
{
"version" : n, (numeric) The preferred block version
"rules" : [ "rulename", ... ], (array of strings) specific block rules that are to be enforced
"vbavailable" : { (json object) set of pending, supported versionbit (BIP 9) softfork deployments
"rulename" : bitnumber (numeric) identifies the bit number as indicating acceptance and readiness for the named softfork rule
,...
},
"vbrequired" : n, (numeric) bit mask of versionbits the server requires set in submissions
"previousblockhash" : "xxxx", (string) The hash of current highest block
"transactions" : [ (array) contents of non-coinbase transactions that should be included in the next block
{
"data" : "xxxx", (string) transaction data encoded in hexadecimal (byte-for-byte)
"txid" : "xxxx", (string) transaction id encoded in little-endian hexadecimal
"hash" : "xxxx", (string) hash encoded in little-endian hexadecimal (including witness data)
"depends" : [ (array) array of numbers
n (numeric) transactions before this one (by 1-based index in 'transactions' list) that must be present in the final block if this one is
,...
],
"fee": n, (numeric) difference in value between transaction inputs and outputs (in satoshis); for coinbase transactions, this is a negative Number of the total collected block fees (ie, not including the block subsidy); if key is not present, fee is unknown and clients MUST NOT assume there isn't one
"sigops" : n, (numeric) total SigOps cost, as counted for purposes of block limits; if key is not present, sigop cost is unknown and clients MUST NOT assume it is zero
"weight" : n, (numeric) total transaction weight, as counted for purposes of block limits
}
,...
],
"coinbaseaux" : { (json object) data that should be included in the coinbase's scriptSig content
"flags" : "xx" (string) key name is to be ignored, and value included in scriptSig
},
"coinbasevalue" : n, (numeric) maximum allowable input to coinbase transaction, including the generation award and transaction fees (in satoshis)
"coinbasetxn" : { ... }, (json object) information for coinbase transaction
"target" : "xxxx", (string) The hash target
"mintime" : xxx, (numeric) The minimum timestamp appropriate for next block time in seconds since epoch (Jan 1 1970 GMT)
"mutable" : [ (array of string) list of ways the block template may be changed
"value" (string) A way the block template may be changed, e.g. 'time', 'transactions', 'prevblock'
,...
],
"noncerange" : "00000000ffffffff",(string) A range of valid nonces
"sigoplimit" : n, (numeric) limit of sigops in blocks
"sizelimit" : n, (numeric) limit of block size
"weightlimit" : n, (numeric) limit of block weight
"curtime" : ttt, (numeric) current timestamp in seconds since epoch (Jan 1 1970 GMT)
"bits" : "xxxxxxxx", (string) compressed target of next block
"height" : n (numeric) The height of the next block
}
示例
bitcoin-cli getblocktemplate {"rules": ["segwit"]}
curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblocktemplate", "params": [{"rules": ["segwit"]}] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/
相关用法
- Bitcoin getmininginfo用法及代码示例
- Bitcoin getnetworkhashps用法及代码示例
- Bitcoin prioritisetransaction用法及代码示例
- Bitcoin submitblock用法及代码示例
- Bitcoin submitheader用法及代码示例
注:本文由纯净天空筛选整理自bitcoin.org大神的英文原创作品 Bitcoin getblocktemplate。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。