Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,42 @@ static UniValue getmempoolentry(const JSONRPCRequest& request)
return info;
}


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"
"\nResult:\n"
"[\n"
" \"hash\" (string) The block hash\n"
"]\n"
"\nExamples:\n"
+ HelpExampleCli("getblockhashes", "1231614698 1231024505")
+ HelpExampleRpc("getblockhashes", "1231614698, 1231024505")
);

unsigned int high = request.params[0].get_int();
unsigned int low = request.params[1].get_int();
std::vector<uint256> blockHashes;

if (!GetTimestampIndex(high, low, blockHashes)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available for block hashes");
}

UniValue result(UniValue::VARR);
for (std::vector<uint256>::const_iterator it=blockHashes.begin(); it!=blockHashes.end(); it++) {
result.push_back(it->GetHex());
}

return result;
}


static UniValue getblockhash(const JSONRPCRequest& request)
{
RPCHelpMan{"getblockhash",
Expand Down Expand Up @@ -2346,6 +2382,7 @@ static UniValue getblockfilter(const JSONRPCRequest& request)
static const CRPCCommand commands[] =
{ // category name actor (function) argNames
// --------------------- ------------------------ ----------------------- ----------
{ "blockchain", "getblockhashes", &getblockhashes, {"high","low"} },
{ "blockchain", "getblockchaininfo", &getblockchaininfo, {} },
{ "blockchain", "getchaintxstats", &getchaintxstats, {"nblocks", "blockhash"} },
{ "blockchain", "getblockstats", &getblockstats, {"hash_or_height", "stats"} },
Expand Down
2 changes: 2 additions & 0 deletions src/rpc/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "sendmany", 5 , "replaceable" },
{ "sendmany", 6 , "conf_target" },
{ "deriveaddresses", 1, "range" },
{ "getblockhashes", 0, "high"},
{ "getblockhashes", 1, "low" },
{ "scantxoutset", 1, "scanobjects" },
{ "addmultisigaddress", 0, "nrequired" },
{ "addmultisigaddress", 1, "keys" },
Expand Down
10 changes: 9 additions & 1 deletion src/rpc/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,15 @@ bool getIndexKey(const std::string& str, uint160& hashBytes, int& type)
}
const PKHash *pkID = boost::get<PKHash>(&dest);
type = pkID ? 1 : 2;
hashBytes = *pkID;
if(type == 2)
{
const ScriptHash *sID = boost::get<ScriptHash>(&dest);
hashBytes = *sID;
}
else
{
hashBytes = *pkID;
}
return true;
}

Expand Down