From 784a4cd408c64f53e1d6775350d49ec27cc85e56 Mon Sep 17 00:00:00 2001 From: SnowGem Date: Thu, 4 Jun 2020 02:03:00 +0700 Subject: [PATCH 1/2] getblockhashes function: --- src/rpc/blockchain.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/rpc/client.cpp | 2 ++ 2 files changed, 39 insertions(+) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 17593915d8f5..6b67e0fe25ea 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -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 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::const_iterator it=blockHashes.begin(); it!=blockHashes.end(); it++) { + result.push_back(it->GetHex()); + } + + return result; +} + + static UniValue getblockhash(const JSONRPCRequest& request) { RPCHelpMan{"getblockhash", @@ -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"} }, diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index 3550a6be8995..6fe2e2a3b3a7 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -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" }, From 295f535a820d0bf6c554e00d5b6a281f54bbdc18 Mon Sep 17 00:00:00 2001 From: SnowGem Date: Thu, 4 Jun 2020 17:49:39 +0700 Subject: [PATCH 2/2] fix getmempool crash for scrypt address --- src/rpc/misc.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 1e8285578cf4..81cc540fc8fe 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -561,7 +561,15 @@ bool getIndexKey(const std::string& str, uint160& hashBytes, int& type) } const PKHash *pkID = boost::get(&dest); type = pkID ? 1 : 2; - hashBytes = *pkID; + if(type == 2) + { + const ScriptHash *sID = boost::get(&dest); + hashBytes = *sID; + } + else + { + hashBytes = *pkID; + } return true; }