Skip to content

Commit

Permalink
RPC for spark names
Browse files Browse the repository at this point in the history
  • Loading branch information
levoncrypto committed Jan 12, 2025
1 parent 9fecae3 commit ca3466a
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<std::string> 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)
Expand Down Expand Up @@ -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"} },
Expand Down

0 comments on commit ca3466a

Please sign in to comment.