diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 6578d87eb3..f29c0edbaf 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -25,6 +25,7 @@ #include "evo/providertx.h" #include "evo/deterministicmns.h" #include "evo/cbtx.h" +#include "../sparkname.h" #include "llmq/quorums_chainlocks.h" #include "llmq/quorums_instantsend.h" @@ -176,6 +177,42 @@ UniValue getblockcount(const JSONRPCRequest& request) return chainActive.Height(); } +UniValue getsparknames(const JSONRPCRequest &request) +{ + if (request.fHelp || request.params.size() > 1) { + throw std::runtime_error( + "getsparknames ( height )\n" + "\nReturns a list of all Spark names.\n" + "\nArguments:\n" + "1. height (numeric, optional) The block height to filter Spark names (default is the current height).\n" + "\nResult:\n" + "[\n" + " \"name1\", (string) The Spark name\n" + " \"name2\", (string) Another Spark name\n" + " ...\n" + "]\n" + "\nExamples:\n" + + HelpExampleCli("getsparknames", "1000") + + HelpExampleRpc("getsparknames", "1000") + ); + } + + LOCK(cs_main); + + const Consensus::Params &consensusParams = Params().GetConsensus(); + int nHeight = consensusParams.nSparkNamesStartBlock; + if (request.params.size() == 1) { + nHeight = request.params[0].get_int(); + } + CSparkNameManager *sparkNameManager = CSparkNameManager::GetInstance(); + std::set sparkNames = sparkNameManager->GetSparkNames(nHeight); + UniValue result(UniValue::VARR); + for (const auto &name : sparkNames) { + result.push_back(name); + } + return result; +} + UniValue getbestblockhash(const JSONRPCRequest& request) { if (request.fHelp || request.params.size() != 0) @@ -1658,6 +1695,7 @@ static const CRPCCommand commands[] = { "blockchain", "getblockchaininfo", &getblockchaininfo, true, {} }, { "blockchain", "getbestblockhash", &getbestblockhash, true, {} }, { "blockchain", "getblockcount", &getblockcount, true, {} }, + { "blockchain", "getsparknames", &getsparknames, true, {} }, { "blockchain", "getblock", &getblock, true, {"blockhash","verbose"} }, { "blockchain", "getblockhash", &getblockhash, true, {"height"} }, { "blockchain", "getblockhashes", &getblockhashes, true, {"high", "low"} },