@@ -232,39 +232,61 @@ static RPCHelpMan getbestblockhash()
232232static RPCHelpMan getbestchainlock ()
233233{
234234 return RPCHelpMan{" getbestchainlock" ,
235- " \n Returns information about the best ChainLock. Throws an error if there is no known ChainLock yet." ,
236- {},
237- RPCResult{
238- RPCResult::Type::OBJ, " " , " " ,
239- {
240- {RPCResult::Type::STR_HEX, " hash" , " The block hash hex-encoded" },
241- {RPCResult::Type::NUM, " height" , " The block height or index" },
242- {RPCResult::Type::STR_HEX, " signature" , " The ChainLock's BLS signature" },
243- {RPCResult::Type::BOOL, " known_block" , " True if the block is known by our node" },
244- }},
235+ " \n If verbose is 0, returns a string that is serialized, hex-encoded data for the best ChainLock.\n "
236+ " If verbose is 1, returns information about the best ChainLock.\n "
237+ " Throws an error if there is no known ChainLock yet." ,
238+ {
239+ {" verbose" , RPCArg::Type::NUM, RPCArg::Default{1 }, " 0 for hex-encoded data, 1 for a json object" },
240+ },
241+ {
242+ RPCResult{" for verbose = 0" ,
243+ RPCResult::Type::STR, " data" , " The serialized, hex-encoded data for best ChainLock" },
244+ RPCResult{" for verbose = 1" ,
245+ RPCResult::Type::OBJ, " " , " " ,
246+ {
247+ {RPCResult::Type::STR_HEX, " hash" , " The block hash hex-encoded" },
248+ {RPCResult::Type::NUM, " height" , " The block height or index" },
249+ {RPCResult::Type::STR_HEX, " signature" , " The ChainLock's BLS signature" },
250+ {RPCResult::Type::BOOL, " known_block" , " True if the block is known by our node" },
251+ }},
252+ },
245253 RPCExamples{
246254 HelpExampleCli (" getbestchainlock" , " " )
247255 + HelpExampleRpc (" getbestchainlock" , " " )
248256 },
249257 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
250258{
251- UniValue result (UniValue::VOBJ);
252-
259+ int verbose = 1 ;
260+ if (!request.params [0 ].isNull ()) {
261+ if (request.params [0 ].isBool ()) {
262+ verbose = request.params [0 ].get_bool () ? 1 : 0 ;
263+ } else {
264+ verbose = request.params [0 ].get_int ();
265+ }
266+ }
253267 const NodeContext& node = EnsureAnyNodeContext (request.context );
254268
255269 const LLMQContext& llmq_ctx = EnsureLLMQContext (node);
256270 const llmq::CChainLockSig clsig = llmq_ctx.clhandler ->GetBestChainLock ();
257271 if (clsig.IsNull ()) {
258272 throw JSONRPCError (RPC_INTERNAL_ERROR, " Unable to find any ChainLock" );
259273 }
260- result.pushKV (" blockhash" , clsig.getBlockHash ().GetHex ());
261- result.pushKV (" height" , clsig.getHeight ());
262- result.pushKV (" signature" , clsig.getSig ().ToString ());
274+ if (verbose) {
275+ UniValue result (UniValue::VOBJ);
263276
264- const ChainstateManager& chainman = EnsureChainman (node);
265- LOCK (cs_main);
266- result.pushKV (" known_block" , chainman.m_blockman .LookupBlockIndex (clsig.getBlockHash ()) != nullptr );
267- return result;
277+ result.pushKV (" blockhash" , clsig.getBlockHash ().GetHex ());
278+ result.pushKV (" height" , clsig.getHeight ());
279+ result.pushKV (" signature" , clsig.getSig ().ToString ());
280+
281+ const ChainstateManager& chainman = EnsureChainman (node);
282+ LOCK (cs_main);
283+ result.pushKV (" known_block" , chainman.m_blockman .LookupBlockIndex (clsig.getBlockHash ()) != nullptr );
284+ return result;
285+ } else {
286+ CDataStream ssTx (SER_NETWORK, PROTOCOL_VERSION);
287+ ssTx << clsig;
288+ return HexStr (ssTx);
289+ }
268290},
269291 };
270292}
0 commit comments