Skip to content

Commit 3b4095c

Browse files
committed
fix: add proper RPC result for governance RPC
- gobject (composite command) - gobject check - gobject count - gobject deserialize - gobject get - gobject getcurrentvotes - gobject list - gobject listprepared - gobject prepare - gobject submit - gobject vote-alias - gobject vote-many - gobject voteraw
1 parent b216d13 commit 3b4095c

File tree

1 file changed

+94
-13
lines changed

1 file changed

+94
-13
lines changed

src/rpc/governance.cpp

Lines changed: 94 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,20 @@ static RPCHelpMan gobject_count()
4343
{
4444
{"mode", RPCArg::Type::STR, RPCArg::DefaultHint{"json"}, "Output format: json (\"json\") or string in free form (\"all\")"},
4545
},
46-
RPCResults{},
46+
{
47+
RPCResult{"for mode = json",
48+
RPCResult::Type::OBJ, "", "",
49+
{
50+
{RPCResult::Type::NUM, "objects_total", "Total number of all governance objects"},
51+
{RPCResult::Type::NUM, "proposals", "Number of governance proposals"},
52+
{RPCResult::Type::NUM, "triggers", "Number of triggers"},
53+
{RPCResult::Type::NUM, "other", "Total number of unknown governance objects"},
54+
{RPCResult::Type::NUM, "erased", "Number of removed (expired) objects"},
55+
{RPCResult::Type::NUM, "votes", "Total number of votes"},
56+
}
57+
},
58+
RPCResult{"for mode = all", RPCResult::Type::STR, "", "Human-friendly summary string for proposals and votes"},
59+
},
4760
RPCExamples{""},
4861
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
4962
{
@@ -71,7 +84,18 @@ static RPCHelpMan gobject_deserialize()
7184
{
7285
{"hex_data", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "data in hex string form"},
7386
},
74-
RPCResults{},
87+
{
88+
RPCResult{
89+
RPCResult::Type::OBJ, "", "Deserialized governance object",
90+
{
91+
// TODO: list fields of output for RPC help instead ELISION
92+
{RPCResult::Type::ELISION, "", ""}
93+
}
94+
},
95+
RPCResult{"for mode = all",
96+
RPCResult::Type::STR, "", "The transaction hash in hex"
97+
},
98+
},
7599
RPCExamples{""},
76100
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
77101
{
@@ -96,7 +120,12 @@ static RPCHelpMan gobject_check()
96120
{
97121
{"hex_data", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "data in hex string format"},
98122
},
99-
RPCResults{},
123+
RPCResult{"if object is valid",
124+
RPCResult::Type::OBJ, "", "",
125+
{
126+
{RPCResult::Type::STR, "Object status", "OK"},
127+
}
128+
},
100129
RPCExamples{""},
101130
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
102131
{
@@ -145,7 +174,9 @@ static RPCHelpMan gobject_prepare()
145174
{"outputHash", RPCArg::Type::STR_HEX, RPCArg::Default{""}, "the single output to submit the proposal fee from"},
146175
{"outputIndex", RPCArg::Type::NUM, RPCArg::Default{0}, "The output index."},
147176
},
148-
RPCResults{},
177+
{
178+
RPCResult{"if object valid", RPCResult::Type::STR, "", "serialized governance object"},
179+
},
149180
RPCExamples{""},
150181
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
151182
{
@@ -254,7 +285,16 @@ static RPCHelpMan gobject_list_prepared()
254285
{
255286
{"count", RPCArg::Type::NUM, RPCArg::Default{10}, "Maximum number of objects to return."},
256287
},
257-
RPCResults{},
288+
RPCResult{
289+
RPCResult::Type::ARR, "", "list of governance objects",
290+
{
291+
{RPCResult::Type::OBJ, "", "",
292+
{
293+
// TODO: list fields of output for RPC help instead ELISION
294+
{RPCResult::Type::ELISION, "", ""}
295+
}},
296+
}
297+
},
258298
RPCExamples{""},
259299
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
260300
{
@@ -303,7 +343,7 @@ static RPCHelpMan gobject_submit()
303343
{"data-hex", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "data in hex string form"},
304344
{"fee-txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "txid of the corresponding proposal fee transaction"},
305345
},
306-
RPCResults{},
346+
RPCResult{RPCResult::Type::STR_HEX, "data", "A string that is serialized, hex-encoded data for the gobject"},
307347
RPCExamples{""},
308348
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
309349
{
@@ -484,6 +524,23 @@ static bool CheckWalletOwnsKey(const CWallet& wallet, const CKeyID& keyid)
484524
return wallet.IsMine(script) == isminetype::ISMINE_SPENDABLE;
485525
}
486526

527+
namespace {
528+
const RPCResult vote_results{
529+
RPCResult::Type::OBJ, "", "",
530+
{
531+
{RPCResult::Type::STR, "overall", "Total amount of successful and failed votes"},
532+
{RPCResult::Type::OBJ, "detail", "Detailed information for each vote",
533+
{
534+
{RPCResult::Type::OBJ, "protx", "ProTx of masternode for voting",
535+
{
536+
{RPCResult::Type::STR, "result", "Result of voting: {success|failed}"},
537+
{RPCResult::Type::STR, "errorMessage", /*optional=*/true, "Error message if failed"},
538+
}},
539+
}},
540+
},
541+
};
542+
} // anonymous namespace
543+
487544
static RPCHelpMan gobject_vote_many()
488545
{
489546
return RPCHelpMan{"gobject vote-many",
@@ -494,7 +551,7 @@ static RPCHelpMan gobject_vote_many()
494551
{"vote", RPCArg::Type::STR, RPCArg::Optional::NO, "vote, possible values: [funding|valid|delete|endorsed]"},
495552
{"vote-outcome", RPCArg::Type::STR, RPCArg::Optional::NO, "vote outcome, possible values: [yes|no|abstain]"},
496553
},
497-
RPCResults{},
554+
vote_results,
498555
RPCExamples{""},
499556
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
500557
{
@@ -547,7 +604,7 @@ static RPCHelpMan gobject_vote_alias()
547604
{"vote-outcome", RPCArg::Type::STR, RPCArg::Optional::NO, "vote outcome, possible values: [yes|no|abstain]"},
548605
{"protx-hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "masternode's proTxHash"},
549606
},
550-
RPCResults{},
607+
vote_results,
551608
RPCExamples{""},
552609
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
553610
{
@@ -669,7 +726,18 @@ static RPCHelpMan gobject_list_helper(const bool make_a_diff)
669726
{"signal", RPCArg::Type::STR, RPCArg::Default{"valid"}, "cached signal, possible values: [valid|funding|delete|endorsed|all]"},
670727
{"type", RPCArg::Type::STR, RPCArg::Default{"all"}, "object type, possible values: [proposals|triggers|all]"},
671728
},
672-
RPCResults{},
729+
{
730+
RPCResult{"if request is valid",
731+
RPCResult::Type::OBJ, "hash", "Object details",
732+
{
733+
// TODO: list fields of output for RPC help instead ELISION
734+
{RPCResult::Type::ELISION, "", ""}
735+
},
736+
},
737+
RPCResult{"if request is invalid",
738+
RPCResult::Type::STR_HEX, "", "Error string"
739+
},
740+
},
673741
RPCExamples{""},
674742
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
675743
{
@@ -715,7 +783,15 @@ static RPCHelpMan gobject_get()
715783
{
716784
{"governance-hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "object id"},
717785
},
718-
RPCResults{},
786+
{
787+
RPCResult{
788+
RPCResult::Type::OBJ, "", "",
789+
{
790+
// TODO: list fields of output for RPC help instead ELISION
791+
{RPCResult::Type::ELISION, "", ""}
792+
}
793+
},
794+
},
719795
RPCExamples{""},
720796
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
721797
{
@@ -811,7 +887,12 @@ static RPCHelpMan gobject_getcurrentvotes()
811887
{"txid", RPCArg::Type::STR_HEX, RPCArg::Default{""}, "masternode collateral txid"},
812888
{"vout", RPCArg::Type::STR, RPCArg::Default{""}, "masternode collateral output index, required if <txid> present"},
813889
},
814-
RPCResults{},
890+
RPCResult{
891+
RPCResult::Type::OBJ, "", "Map with governance votes",
892+
{
893+
{RPCResult::Type::STR, "votehash", "Human-friendly presentation of vote"},
894+
},
895+
},
815896
RPCExamples{""},
816897
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
817898
{
@@ -877,7 +958,7 @@ static RPCHelpMan gobject()
877958
{
878959
{"command", RPCArg::Type::STR, RPCArg::Optional::NO, "The command to execute"},
879960
},
880-
RPCResults{},
961+
RPCResult{RPCResult::Type::NONE, "", ""},
881962
RPCExamples{""},
882963
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
883964
{
@@ -899,7 +980,7 @@ static RPCHelpMan voteraw()
899980
{"time", RPCArg::Type::NUM, RPCArg::Optional::NO, ""},
900981
{"vote-sig", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, ""},
901982
},
902-
RPCResults{},
983+
RPCResult{RPCResult::Type::STR, "", "Result of voting"},
903984
RPCExamples{""},
904985
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
905986
{

0 commit comments

Comments
 (0)