Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change first parameter of listgovproposals and listgovproposalvotes to be string and parsed as JSON in rpc #1732

Merged
merged 2 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions src/masternodes/rpc_proposals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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()) {
Expand Down Expand Up @@ -865,20 +866,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 @@ -1033,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) {
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