message: Port getblockhashes RPC
diff: @@ -517,6 +517,79 @@ UniValue getaddressmempool(const JSONRPCRequest& request)
  return result;
  }
  +UniValue getblockhashes(const JSONRPCRequest& request)
  +{
  + if (request.fHelp || request.params.size() < 2)
  + throw std::runtime_error(
  + "getblockhashes timestamp\n"
  + "\nReturns array of hashes of blocks within the timestamp range provided.\n"
  + "\nArguments:\n"
  + "1. high (numeric, required) The newer block timestamp\n"
  + "2. low (numeric, required) The older block timestamp\n"
  + "3. options (string, required) A json object\n"
  + " {\n"
  + " \"noOrphans\":true (boolean) will only include blocks on the main chain\n"
  + " \"logicalTimes\":true (boolean) will include logical timestamps with hashes\n"
  + " }\n"
  + "\nResult:\n"
  + "[\n"
  + " \"hash\" (string) The block hash\n"
  + "]\n"
  + "[\n"
  + " {\n"
  + " \"blockhash\": (string) The block hash\n"
  + " \"logicalts\": (numeric) The logical timestamp\n"
  + " }\n"
  + "]\n"
  + "\nExamples:\n"
  + + HelpExampleCli("getblockhashes", "1231614698 1231024505")
  + + HelpExampleRpc("getblockhashes", "1231614698, 1231024505")
  + + HelpExampleCli("getblockhashes", "1231614698 1231024505 '{\"noOrphans\":false, \"logicalTimes\":true}'")
  + );
  +
  + unsigned int high = request.params[0].get_int();
  + unsigned int low = request.params[1].get_int();
  + bool fActiveOnly = false;
  + bool fLogicalTS = false;
  +
  + if (request.params.size() > 2) {
  + if (request.params[2].isObject()) {
  + UniValue noOrphans = find_value(request.params[2].get_obj(), "noOrphans");
  + UniValue returnLogical = find_value(request.params[2].get_obj(), "logicalTimes");
  +
  + if (noOrphans.isBool())
  + fActiveOnly = noOrphans.get_bool();
  +
  + if (returnLogical.isBool())
  + fLogicalTS = returnLogical.get_bool();
  + }
  + }
  +
  + std::vector<std::pair<uint256, unsigned int> > blockHashes;
  +
  + if (fActiveOnly)
  + LOCK(cs_main);
  +
  + if (!GetTimestampIndex(high, low, fActiveOnly, blockHashes)) {
  + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available for block hashes");
  + }
  +
  + UniValue result(UniValue::VARR);
  +
  + for (std::vector<std::pair<uint256, unsigned int> >::const_iterator it=blockHashes.begin(); it!=blockHashes.end(); it++) {
  + if (fLogicalTS) {
  + UniValue item(UniValue::VOBJ);
  + item.pushKV("blockhash", it->first.GetHex());
  + item.pushKV("logicalts", (int)it->second);
  + result.push_back(item);
  + } else {
  + result.push_back(it->first.GetHex());
  + }
  + }
  +
  + return result;
  +}
  +
  // Needed even with !ENABLE_WALLET, to pass (ignored) pointers around
  class CWallet;
  