Skip to content

Commit 562aeb7

Browse files
committed
rpc: add JSON help defs for CGovernanceObject fragments
Also gives us the help text for `gobject {diff,list}`
1 parent 57edf31 commit 562aeb7

3 files changed

Lines changed: 57 additions & 16 deletions

File tree

src/governance/core_write.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,38 @@ UniValue CGovernanceObject::GetInnerJson() const
6565
return m_obj.ToJson();
6666
}
6767

68+
// CGovernanceObject::GetStateJson() defined in governance/object.cpp
69+
RPCResult CGovernanceObject::GetStateJsonHelp(const std::string& key, bool optional, const std::string& local_valid_key)
70+
{
71+
return {RPCResult::Type::OBJ, key, optional, key.empty() ? "" : "Object state info",
72+
{
73+
{RPCResult::Type::STR_HEX, "DataHex", "Governance object (hex)"},
74+
{RPCResult::Type::STR, "DataString", "Governance object (string)"},
75+
{RPCResult::Type::STR_HEX, "Hash", "Hash of governance object"},
76+
GetRpcResult("collateralHash", /*optional=*/false, /*override_name=*/"CollateralHash"),
77+
{RPCResult::Type::NUM, "ObjectType", "Object types"},
78+
{RPCResult::Type::NUM, "CreationTime", "Object creation timestamp"},
79+
{RPCResult::Type::STR_HEX, "SigningMasternode", /*optional=*/true, "Signing masternode’s vin (for triggers only)"},
80+
{RPCResult::Type::BOOL, local_valid_key, "Returns true if valid"},
81+
{RPCResult::Type::STR, "IsValidReason", strprintf("%s error (human-readable string, empty if %s true)", local_valid_key, local_valid_key)},
82+
{RPCResult::Type::BOOL, "fCachedValid", "Returns true if minimum support has been reached flagging object as valid"},
83+
{RPCResult::Type::BOOL, "fCachedFunding", "Returns true if minimum support has been reached flagging object as fundable"},
84+
{RPCResult::Type::BOOL, "fCachedDelete", "Returns true if minimum support has been reached flagging object as marked for deletion"},
85+
{RPCResult::Type::BOOL, "fCachedEndorsed", "Returns true if minimum support has been reached flagging object as endorsed"},
86+
}};
87+
}
88+
89+
RPCResult CGovernanceObject::GetVotesJsonHelp(const std::string& key, bool optional)
90+
{
91+
return {RPCResult::Type::OBJ, key, optional, key.empty() ? "" : "Object vote counts",
92+
{
93+
{RPCResult::Type::NUM, "AbsoluteYesCount", "Number of Yes votes minus number of No votes"},
94+
{RPCResult::Type::NUM, "YesCount", "Number of Yes votes"},
95+
{RPCResult::Type::NUM, "NoCount", "Number of No votes"},
96+
{RPCResult::Type::NUM, "AbstainCount", "Number of Abstain votes"},
97+
}};
98+
}
99+
68100
UniValue CGovernanceObject::GetVotesJson(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t signal) const
69101
{
70102
UniValue obj(UniValue::VOBJ);

src/governance/object.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,11 @@ class CGovernanceObject
265265
[[nodiscard]] static RPCResult GetInnerJsonHelp(const std::string& key, bool optional);
266266
[[nodiscard]] UniValue GetInnerJson() const;
267267

268+
[[nodiscard]] static RPCResult GetStateJsonHelp(const std::string& key, bool optional, const std::string& local_valid_key);
268269
[[nodiscard]] UniValue GetStateJson(const ChainstateManager& chainman, const CDeterministicMNList& tip_mn_list, const std::string& local_valid_key) const
269270
EXCLUSIVE_LOCKS_REQUIRED(!cs);
270271

272+
[[nodiscard]] static RPCResult GetVotesJsonHelp(const std::string& key, bool optional);
271273
[[nodiscard]] UniValue GetVotesJson(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t signal) const
272274
EXCLUSIVE_LOCKS_REQUIRED(!cs);
273275

src/rpc/governance.cpp

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,16 @@ static UniValue ListObjects(CGovernanceManager& govman, const CDeterministicMNLi
653653
return objResult;
654654
}
655655

656-
// USERS CAN QUERY THE SYSTEM FOR A LIST OF VARIOUS GOVERNANCE ITEMS
656+
static RPCResult ListObjectsHelp()
657+
{
658+
auto ret = CGovernanceObject::GetStateJsonHelp(/*key=*/"", /*optional=*/false, /*local_valid_key=*/"fBlockchainValidity");
659+
auto mod_inner = ret.m_inner;
660+
for (const auto& result : CGovernanceObject::GetVotesJsonHelp(/*key=*/"", /*optional=*/false).m_inner) {
661+
mod_inner.push_back(result);
662+
}
663+
return RPCResult{ret.m_type, ret.m_key_name, ret.m_description, mod_inner};
664+
}
665+
657666
static RPCHelpMan gobject_list_helper(const bool make_a_diff)
658667
{
659668
const std::string command{make_a_diff ? "gobject diff" : "gobject list"};
@@ -668,11 +677,7 @@ static RPCHelpMan gobject_list_helper(const bool make_a_diff)
668677
},
669678
{
670679
RPCResult{"If request is valid",
671-
RPCResult::Type::OBJ, "hash", "Object details",
672-
{
673-
// TODO: list fields of output for RPC help instead ELISION
674-
{RPCResult::Type::ELISION, "", ""}
675-
},
680+
RPCResult::Type::OBJ, "hash", "Object details", {ListObjectsHelp()},
676681
},
677682
RPCResult{"If request is invalid",
678683
RPCResult::Type::STR, "", "Error string"
@@ -715,23 +720,25 @@ static RPCHelpMan gobject_diff()
715720
return gobject_list_helper(true);
716721
}
717722

718-
// GET SPECIFIC GOVERNANCE ENTRY
723+
static RPCResult gobject_get_help()
724+
{
725+
auto ret = CGovernanceObject::GetStateJsonHelp(/*key=*/"", /*optional=*/false, /*local_valid_key=*/"fLocalValidity");
726+
auto mod_inner = ret.m_inner;
727+
mod_inner.push_back({RPCResult::Type::OBJ, "FundingResult", "Funding vote details", {CGovernanceObject::GetVotesJsonHelp(/*key=*/"", /*optional=*/false)}});
728+
mod_inner.push_back({RPCResult::Type::OBJ, "ValidResult", "Object validity vote details", {CGovernanceObject::GetVotesJsonHelp(/*key=*/"", /*optional=*/false)}});
729+
mod_inner.push_back({RPCResult::Type::OBJ, "DeleteResult", "Delete vote details", {CGovernanceObject::GetVotesJsonHelp(/*key=*/"", /*optional=*/false)}});
730+
mod_inner.push_back({RPCResult::Type::OBJ, "EndorsedResult", "Endorsed vote details", {CGovernanceObject::GetVotesJsonHelp(/*key=*/"", /*optional=*/false)}});
731+
return RPCResult{ret.m_type, ret.m_key_name, ret.m_description, mod_inner};
732+
}
733+
719734
static RPCHelpMan gobject_get()
720735
{
721736
return RPCHelpMan{"gobject get",
722737
"Get governance object by hash\n",
723738
{
724739
{"governance-hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "object id"},
725740
},
726-
{
727-
RPCResult{
728-
RPCResult::Type::OBJ, "", "",
729-
{
730-
// TODO: list fields of output for RPC help instead ELISION
731-
{RPCResult::Type::ELISION, "", ""}
732-
}
733-
},
734-
},
741+
gobject_get_help(),
735742
RPCExamples{""},
736743
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
737744
{

0 commit comments

Comments
 (0)