@@ -275,35 +275,75 @@ UniValue getrawmempool(const UniValue& params, bool fHelp)
275275 return mempoolToJSON (fVerbose );
276276}
277277
278+
278279UniValue getblockhashes (const UniValue& params, bool fHelp )
279280{
280- if (fHelp || params.size () != 2 )
281+ if (fHelp || params.size () < 2 )
281282 throw runtime_error (
282283 " getblockhashes timestamp\n "
283284 " \n Returns array of hashes of blocks within the timestamp range provided.\n "
284285 " \n Arguments:\n "
285286 " 1. high (numeric, required) The newer block timestamp\n "
286287 " 2. low (numeric, required) The older block timestamp\n "
288+ " 3. options (string, required) A json object\n "
289+ " {\n "
290+ " \" noOrphans\" :true (boolean) will only include blocks on the main chain\n "
291+ " \" logicalTimes\" :true (boolean) will include logical timestamps with hashes\n "
292+ " }\n "
287293 " \n Result:\n "
288294 " [\n "
289295 " \" hash\" (string) The block hash\n "
290296 " ]\n "
297+ " [\n "
298+ " {\n "
299+ " \" blockhash\" : (string) The block hash\n "
300+ " \" logicalts\" : (numeric) The logical timestamp\n "
301+ " }\n "
302+ " ]\n "
291303 " \n Examples:\n "
292304 + HelpExampleCli (" getblockhashes" , " 1231614698 1231024505" )
293305 + HelpExampleRpc (" getblockhashes" , " 1231614698, 1231024505" )
294- );
306+ + HelpExampleCli (" getblockhashes" , " 1231614698 1231024505 '{\" noOrphans\" :false, \" logicalTimes\" :true}'" )
307+ );
295308
296309 unsigned int high = params[0 ].get_int ();
297310 unsigned int low = params[1 ].get_int ();
298- std::vector<uint256> blockHashes;
311+ bool fActiveOnly = false ;
312+ bool fLogicalTS = false ;
313+
314+ if (params.size () > 2 ) {
315+ if (params[2 ].isObject ()) {
316+ UniValue noOrphans = find_value (params[2 ].get_obj (), " noOrphans" );
317+ UniValue returnLogical = find_value (params[2 ].get_obj (), " logicalTimes" );
299318
300- if (!GetTimestampIndex (high, low, blockHashes)) {
319+ if (noOrphans.isBool ())
320+ fActiveOnly = noOrphans.get_bool ();
321+
322+ if (returnLogical.isBool ())
323+ fLogicalTS = returnLogical.get_bool ();
324+ }
325+ }
326+
327+ std::vector<std::pair<uint256, unsigned int > > blockHashes;
328+
329+ if (fActiveOnly )
330+ LOCK (cs_main);
331+
332+ if (!GetTimestampIndex (high, low, fActiveOnly , blockHashes)) {
301333 throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " No information available for block hashes" );
302334 }
303335
304336 UniValue result (UniValue::VARR);
305- for (std::vector<uint256>::const_iterator it=blockHashes.begin (); it!=blockHashes.end (); it++) {
306- result.push_back (it->GetHex ());
337+
338+ for (std::vector<std::pair<uint256, unsigned int > >::const_iterator it=blockHashes.begin (); it!=blockHashes.end (); it++) {
339+ if (fLogicalTS ) {
340+ UniValue item (UniValue::VOBJ);
341+ item.push_back (Pair (" blockhash" , it->first .GetHex ()));
342+ item.push_back (Pair (" logicalts" , (int )it->second ));
343+ result.push_back (item);
344+ } else {
345+ result.push_back (it->first .GetHex ());
346+ }
307347 }
308348
309349 return result;
0 commit comments