@@ -214,20 +214,9 @@ UniValue blockheaderToJSON(const CBlockIndex* tip, const CBlockIndex* blockindex
214
214
215
215
UniValue blockToJSON (const CBlock& block, const CBlockIndex* tip, const CBlockIndex* blockindex, llmq::CChainLocksHandler& clhandler, llmq::CInstantSendManager& isman, bool txDetails)
216
216
{
217
- // Serialize passed information without accessing chain state of the active chain!
218
- AssertLockNotHeld (cs_main); // For performance reasons
217
+ UniValue result = blockheaderToJSON (tip, blockindex, clhandler, isman);
219
218
220
- UniValue result (UniValue::VOBJ);
221
- result.pushKV (" hash" , blockindex->GetBlockHash ().GetHex ());
222
- const CBlockIndex* pnext;
223
- int confirmations = ComputeNextBlockAndDepth (tip, blockindex, pnext);
224
- result.pushKV (" confirmations" , confirmations);
225
219
result.pushKV (" size" , (int )::GetSerializeSize (block, PROTOCOL_VERSION));
226
- result.pushKV (" height" , blockindex->nHeight );
227
- result.pushKV (" version" , block.nVersion );
228
- result.pushKV (" versionHex" , strprintf (" %08x" , block.nVersion ));
229
- result.pushKV (" merkleroot" , block.hashMerkleRoot .GetHex ());
230
- bool chainLock = clhandler.HasChainLock (blockindex->nHeight , blockindex->GetBlockHash ());
231
220
UniValue txs (UniValue::VARR);
232
221
for (const auto & tx : block.vtx )
233
222
{
@@ -236,7 +225,7 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* tip, const CBlockIn
236
225
UniValue objTx (UniValue::VOBJ);
237
226
TxToUniv (*tx, uint256 (), objTx, true );
238
227
bool fLocked = isman.IsLocked (tx->GetHash ());
239
- objTx.pushKV (" instantlock" , fLocked || chainLock );
228
+ objTx.pushKV (" instantlock" , fLocked || result[ " chainlock " ]. get_bool () );
240
229
objTx.pushKV (" instantlock_internal" , fLocked );
241
230
txs.push_back (objTx);
242
231
}
@@ -249,20 +238,6 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* tip, const CBlockIn
249
238
result.pushKV (" cbTx" , opt_cbTx->ToJson ());
250
239
}
251
240
}
252
- result.pushKV (" time" , block.GetBlockTime ());
253
- result.pushKV (" mediantime" , (int64_t )blockindex->GetMedianTimePast ());
254
- result.pushKV (" nonce" , (uint64_t )block.nNonce );
255
- result.pushKV (" bits" , strprintf (" %08x" , block.nBits ));
256
- result.pushKV (" difficulty" , GetDifficulty (blockindex));
257
- result.pushKV (" chainwork" , blockindex->nChainWork .GetHex ());
258
- result.pushKV (" nTx" , (uint64_t )blockindex->nTx );
259
-
260
- if (blockindex->pprev )
261
- result.pushKV (" previousblockhash" , blockindex->pprev ->GetBlockHash ().GetHex ());
262
- if (pnext)
263
- result.pushKV (" nextblockhash" , pnext->GetBlockHash ().GetHex ());
264
-
265
- result.pushKV (" chainlock" , chainLock);
266
241
267
242
return result;
268
243
}
@@ -1168,11 +1143,20 @@ static UniValue getblock(const JSONRPCRequest& request)
1168
1143
{
1169
1144
{RPCResult::Type::STR_HEX, " hash" , " the block hash (same as provided)" },
1170
1145
{RPCResult::Type::NUM, " confirmations" , " The number of confirmations, or -1 if the block is not on the main chain" },
1171
- {RPCResult::Type::NUM, " size" , " The block size" },
1172
1146
{RPCResult::Type::NUM, " height" , " The block height or index" },
1173
1147
{RPCResult::Type::NUM, " version" , " The block version" },
1174
1148
{RPCResult::Type::STR_HEX, " versionHex" , " The block version formatted in hexadecimal" },
1175
1149
{RPCResult::Type::STR_HEX, " merkleroot" , " The merkle root" },
1150
+ {RPCResult::Type::NUM_TIME, " time" , " The block time expressed in " + UNIX_EPOCH_TIME},
1151
+ {RPCResult::Type::NUM_TIME, " mediantime" , " The median block time expressed in " + UNIX_EPOCH_TIME},
1152
+ {RPCResult::Type::NUM, " nonce" , " The nonce" },
1153
+ {RPCResult::Type::STR_HEX, " bits" , " The bits" },
1154
+ {RPCResult::Type::NUM, " difficulty" , " The difficulty" },
1155
+ {RPCResult::Type::STR_HEX, " chainwork" , " Expected number of hashes required to produce the current chain" },
1156
+ {RPCResult::Type::NUM, " nTx" , " The number of transactions in the block" },
1157
+ {RPCResult::Type::STR_HEX, " previousblockhash" , /* optional */ true , " The hash of the previous block (if available)" },
1158
+ {RPCResult::Type::STR_HEX, " nextblockhash" , /* optional */ true , " The hash of the next block (if available)" },
1159
+ {RPCResult::Type::NUM, " size" , " The block size" },
1176
1160
{RPCResult::Type::ARR, " tx" , " The transaction ids" ,
1177
1161
{{RPCResult::Type::STR_HEX, " " , " The transaction id" }}},
1178
1162
{RPCResult::Type::OBJ, " cbTx" , " The coinbase special transaction" ,
@@ -1182,15 +1166,6 @@ static UniValue getblock(const JSONRPCRequest& request)
1182
1166
{RPCResult::Type::STR_HEX, " merkleRootMNList" , " The merkle root of the masternode list" },
1183
1167
{RPCResult::Type::STR_HEX, " merkleRootQuorums" , " The merkle root of the quorum list" },
1184
1168
}},
1185
- {RPCResult::Type::NUM_TIME, " time" , " The block time expressed in " + UNIX_EPOCH_TIME},
1186
- {RPCResult::Type::NUM_TIME, " mediantime" , " The median block time expressed in " + UNIX_EPOCH_TIME},
1187
- {RPCResult::Type::NUM, " nonce" , " The nonce" },
1188
- {RPCResult::Type::STR_HEX, " bits" , " The bits" },
1189
- {RPCResult::Type::NUM, " difficulty" , " The difficulty" },
1190
- {RPCResult::Type::STR_HEX, " chainwork" , " Expected number of hashes required to produce the chain up to this block (in hex)" },
1191
- {RPCResult::Type::NUM, " nTx" , " The number of transactions in the block" },
1192
- {RPCResult::Type::STR_HEX, " previousblockhash" , " The hash of the previous block" },
1193
- {RPCResult::Type::STR_HEX, " nextblockhash" , " The hash of the next block" },
1194
1169
}},
1195
1170
RPCResult{" for verbosity = 2" ,
1196
1171
RPCResult::Type::OBJ, " " , " " ,
0 commit comments