Skip to content

Commit

Permalink
Change first parameter of listgovproposals and listgovproposalvotes t…
Browse files Browse the repository at this point in the history
…o be string and parsed as JSON in rpc (#1732)

* Change firstparameter of listgovproposals and listgovproposalvotes to be string and parsed as JSON in rpc.

* Fix lint
  • Loading branch information
Mixa84 authored Feb 6, 2023
1 parent 58a9984 commit aa9549b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
27 changes: 14 additions & 13 deletions src/masternodes/rpc_proposals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,10 +576,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);

Expand All @@ -593,8 +595,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()) {
Expand Down Expand Up @@ -883,20 +884,20 @@ 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};
size_t limit = 100;
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") {
Expand Down Expand Up @@ -1051,9 +1052,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) {
Expand Down
4 changes: 3 additions & 1 deletion src/rpc/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit aa9549b

Please sign in to comment.