From 1e959d5188bbf5c0624478cfa85bd04a31addc95 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Wed, 1 Feb 2023 12:10:11 +0100 Subject: [PATCH 1/2] Change firstparameter of listgovproposals and listgovproposalvotes to be string and parsed as JSON in rpc. --- src/masternodes/rpc_proposals.cpp | 23 ++++++++++++----------- src/rpc/client.cpp | 4 +++- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/masternodes/rpc_proposals.cpp b/src/masternodes/rpc_proposals.cpp index db41c63ef2..bddaf53e90 100644 --- a/src/masternodes/rpc_proposals.cpp +++ b/src/masternodes/rpc_proposals.cpp @@ -562,10 +562,12 @@ UniValue listgovproposalvotes(const JSONRPCRequest &request) { } .Check(request); - if (request.params[0].isObject()) - RPCTypeCheck(request.params, {UniValue::VOBJ}, true); - else + UniValue optionsObj(UniValue::VOBJ); + + if (!request.params[0].isObject() && !optionsObj.read(request.params[0].getValStr())) RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VSTR, UniValue::VNUM, UniValue::VOBJ}, true); + else if (request.params[0].isObject()) + optionsObj = request.params[0].get_obj(); CCustomCSView view(*pcustomcsview); @@ -579,8 +581,7 @@ UniValue listgovproposalvotes(const JSONRPCRequest &request) { size_t start = 0; bool including_start = true; - if (request.params[0].isObject()) { - auto optionsObj = request.params[0].get_obj(); + if (!optionsObj.empty()) { propId = ParseHashV(optionsObj["proposalId"].get_str(), "proposalId"); if (!optionsObj["masternode"].isNull()) { @@ -865,10 +866,12 @@ UniValue listgovproposals(const JSONRPCRequest &request) { } .Check(request); - if (request.params[0].isObject()) - RPCTypeCheck(request.params, {UniValue::VOBJ}, true); - else + UniValue optionsObj(UniValue::VOBJ); + + if (!request.params[0].isObject() && !optionsObj.read(request.params[0].getValStr())) RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VSTR, UniValue::VNUM, UniValue::VOBJ}, true); + else if (request.params[0].isObject()) + optionsObj = request.params[0].get_obj(); uint8_t type{0}, status{0}; int cycle{0}; @@ -876,9 +879,7 @@ UniValue listgovproposals(const JSONRPCRequest &request) { CProposalId start = {}; bool including_start = true; - if (request.params[0].isObject()) { - auto optionsObj = request.params[0].get_obj(); - + if (!optionsObj.empty()) { if (optionsObj.exists("type")) { auto str = optionsObj["type"].get_str(); if (str == "cfp") { diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index f9796e781f..b701a6d9cf 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -356,7 +356,9 @@ static const CRPCConvertParam vRPCConvertParams[] = { "creategovvoc", 0, "data" }, { "creategovvoc", 1, "inputs" }, { "listgovproposalvotes", 2, "cycle" }, - { "listgovproposals", 0, "type" }, + { "listgovproposalvotes", 3, "pagination" }, + { "listgovproposals", 2, "cycle" }, + { "listgovproposals", 3, "pagination" }, }; // clang-format on From 2b9d5eaf3b09baeae862e1a950f798c42281262f Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Fri, 3 Feb 2023 12:58:29 +0100 Subject: [PATCH 2/2] Fix lint --- src/masternodes/rpc_proposals.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/masternodes/rpc_proposals.cpp b/src/masternodes/rpc_proposals.cpp index bddaf53e90..d885545db0 100644 --- a/src/masternodes/rpc_proposals.cpp +++ b/src/masternodes/rpc_proposals.cpp @@ -1034,9 +1034,9 @@ static const CRPCCommand commands[] = { {"proposals", "creategovcfp", &creategovcfp, {"data", "inputs"} }, {"proposals", "creategovvoc", &creategovvoc, {"data", "inputs"} }, {"proposals", "votegov", &votegov, {"proposalId", "masternodeId", "decision", "inputs"}}, - {"proposals", "listgovproposalvotes", &listgovproposalvotes, {"proposalId", "masternode", "cycle"} }, + {"proposals", "listgovproposalvotes", &listgovproposalvotes, {"proposalId", "masternode", "cycle", "pagination"} }, {"proposals", "getgovproposal", &getgovproposal, {"proposalId"} }, - {"proposals", "listgovproposals", &listgovproposals, {"type", "status", "cycle"} }, + {"proposals", "listgovproposals", &listgovproposals, {"type", "status", "cycle", "pagination"} }, }; void RegisterProposalRPCCommands(CRPCTable &tableRPC) {