Skip to content

Commit b857c43

Browse files
committed
RPC: Signblock: Support signblock on rpc/blockchain
QA: Adapt rpc_blockchain tests to signed blocks
1 parent cdb79e9 commit b857c43

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

qa/rpc-tests/blockchain.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,16 @@ def _test_getblockheader(self, getblock=False):
9696
assert 'bits' not in header
9797
assert 'difficulty' not in header
9898
assert 'chainwork' not in header
99+
assert 'signblock_witness_asm' in header
100+
assert 'signblock_witness_hex' in header
99101

100102
def _test_getblockchaininfo(self):
101103
besthash = self.nodes[0].getbestblockhash()
102104
res = self.nodes[0].getblockchaininfo()
103105

104106
assert_equal(res['chain'], 'elementsregtest')
107+
assert_equal(res['signblock_asm'], '1')
108+
assert_equal(res['signblock_hex'], '51')
105109
assert 'difficulty' not in res
106110
assert 'chainwork' not in res
107111
assert_equal(res['blocks'], 200)

src/rpc/blockchain.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ UniValue blockheaderToJSON(const CBlockIndex* blockindex)
6161
result.push_back(Pair("merkleroot", blockindex->hashMerkleRoot.GetHex()));
6262
result.push_back(Pair("time", (int64_t)blockindex->nTime));
6363
result.push_back(Pair("mediantime", (int64_t)blockindex->GetMedianTimePast()));
64+
result.push_back(Pair("signblock_witness_asm", ScriptToAsmStr(blockindex->proof.solution)));
65+
result.push_back(Pair("signblock_witness_hex", HexStr(blockindex->proof.solution.begin(), blockindex->proof.solution.end())));
6466

6567
if (blockindex->pprev)
6668
result.push_back(Pair("previousblockhash", blockindex->pprev->GetBlockHash().GetHex()));
@@ -101,6 +103,8 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx
101103
result.push_back(Pair("tx", txs));
102104
result.push_back(Pair("time", block.GetBlockTime()));
103105
result.push_back(Pair("mediantime", (int64_t)blockindex->GetMedianTimePast()));
106+
result.push_back(Pair("signblock_witness_asm", ScriptToAsmStr(blockindex->proof.solution)));
107+
result.push_back(Pair("signblock_witness_hex", HexStr(blockindex->proof.solution.begin(), blockindex->proof.solution.end())));
104108

105109
if (blockindex->pprev)
106110
result.push_back(Pair("previousblockhash", blockindex->pprev->GetBlockHash().GetHex()));
@@ -600,6 +604,8 @@ UniValue getblockheader(const JSONRPCRequest& request)
600604
" \"merkleroot\" : \"xxxx\", (string) The merkle root\n"
601605
" \"time\" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n"
602606
" \"mediantime\" : ttt, (numeric) The median block time in seconds since epoch (Jan 1 1970 GMT)\n"
607+
" \"signblock_witness_asm\":\"asm\", (string) scriptSig for block signing (asm)'\n"
608+
" \"signblock_witness_hex\":\"hex\", (string) scriptSig for block signing (hex)'\n"
603609
" \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n"
604610
" \"nextblockhash\" : \"hash\", (string) The hash of the next block\n"
605611
"}\n"
@@ -684,6 +690,8 @@ static UniValue getblock(const JSONRPCRequest& request)
684690
" ],\n"
685691
" \"time\" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n"
686692
" \"mediantime\" : ttt, (numeric) The median block time in seconds since epoch (Jan 1 1970 GMT)\n"
693+
" \"signblock_witness_asm\":\"asm\", (string) scriptSig for block signing (asm)'\n"
694+
" \"signblock_witness_hex\":\"hex\", (string) scriptSig for block signing (hex)'\n"
687695
" \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n"
688696
" \"nextblockhash\" : \"hash\" (string) The hash of the next block\n"
689697
"}\n"
@@ -1033,6 +1041,8 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
10331041
"\nResult:\n"
10341042
"{\n"
10351043
" \"chain\": \"xxxx\", (string) current network name as defined in BIP70 (main, test, regtest)\n"
1044+
" \"signblock_asm\":\"asm\", (string) scriptPubKey for block signing (asm)'\n"
1045+
" \"signblock_hex\":\"hex\", (string) scriptPubKey for block signing (hex)'\n"
10361046
" \"blocks\": xxxxxx, (numeric) the current number of blocks processed in the server\n"
10371047
" \"headers\": xxxxxx, (numeric) the current number of headers we have validated\n"
10381048
" \"bestblockhash\": \"...\", (string) the hash of the currently best block\n"
@@ -1066,6 +1076,8 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
10661076
obj.push_back(Pair("mediantime", (int64_t)tip->GetMedianTimePast()));
10671077
obj.push_back(Pair("verificationprogress", GuessVerificationProgress(Params().TxData(), tip)));
10681078
obj.push_back(Pair("pruned", fPruneMode));
1079+
obj.push_back(Pair("signblock_asm", ScriptToAsmStr(tip->proof.challenge)));
1080+
obj.push_back(Pair("signblock_hex", HexStr(tip->proof.challenge.begin(), tip->proof.challenge.end())));
10691081

10701082
const Consensus::Params& consensusParams = Params().GetConsensus();
10711083
UniValue bip9_softforks(UniValue::VOBJ);

src/rpc/mining.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,8 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
774774
result.push_back(Pair("weightlimit", (int64_t)MAX_BLOCK_WEIGHT));
775775
}
776776
result.push_back(Pair("curtime", pblock->GetBlockTime()));
777+
result.push_back(Pair("signblock_asm", ScriptToAsmStr(pblock->proof.challenge)));
778+
result.push_back(Pair("signblock_hex", HexStr(pblock->proof.challenge.begin(), pblock->proof.challenge.end())));
777779
result.push_back(Pair("height", (int64_t)(pindexPrev->nHeight+1)));
778780

779781
if (!pblocktemplate->vchCoinbaseCommitment.empty() && fSupportsSegwit) {

0 commit comments

Comments
 (0)