@@ -623,22 +623,15 @@ static RPCHelpMan gobject_vote_alias()
623623static UniValue ListObjects (CGovernanceManager& govman, const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman,
624624 const std::string& strCachedSignal, const std::string& strType, int nStartTime)
625625{
626- UniValue objResult (UniValue::VOBJ);
627-
628- // GET MATCHING GOVERNANCE OBJECTS
629-
630626 if (g_txindex) {
631627 g_txindex->BlockUntilSyncedToCurrentChain ();
632628 }
633629
634- LOCK (cs_main);
635-
636630 std::vector<CGovernanceObject> objs;
637631 govman.GetAllNewerThan (objs, nStartTime);
638-
639632 govman.UpdateLastDiffTime (GetTime ());
640- // CREATE RESULTS FOR USER
641633
634+ UniValue objResult (UniValue::VOBJ);
642635 for (const auto & govObj : objs) {
643636 if (strCachedSignal == " valid" && !govObj.IsSetCachedValid ()) continue ;
644637 if (strCachedSignal == " funding" && !govObj.IsSetCachedFunding ()) continue ;
@@ -648,34 +641,13 @@ static UniValue ListObjects(CGovernanceManager& govman, const CDeterministicMNLi
648641 if (strType == " proposals" && govObj.GetObjectType () != GovernanceObject::PROPOSAL) continue ;
649642 if (strType == " triggers" && govObj.GetObjectType () != GovernanceObject::TRIGGER) continue ;
650643
651- UniValue bObj (UniValue::VOBJ);
652- bObj.pushKV (" DataHex" , govObj.GetDataAsHexString ());
653- bObj.pushKV (" DataString" , govObj.GetDataAsPlainString ());
654- bObj.pushKV (" Hash" , govObj.GetHash ().ToString ());
655- bObj.pushKV (" CollateralHash" , govObj.GetCollateralHash ().ToString ());
656- bObj.pushKV (" ObjectType" , ToUnderlying (govObj.GetObjectType ()));
657- bObj.pushKV (" CreationTime" , govObj.GetCreationTime ());
658- const COutPoint& masternodeOutpoint = govObj.GetMasternodeOutpoint ();
659- if (masternodeOutpoint != COutPoint ()) {
660- bObj.pushKV (" SigningMasternode" , masternodeOutpoint.ToStringShort ());
661- }
662-
663- // REPORT STATUS FOR FUNDING VOTES SPECIFICALLY
664- bObj.pushKV (" AbsoluteYesCount" , govObj.GetAbsoluteYesCount (tip_mn_list, VOTE_SIGNAL_FUNDING));
665- bObj.pushKV (" YesCount" , govObj.GetYesCount (tip_mn_list, VOTE_SIGNAL_FUNDING));
666- bObj.pushKV (" NoCount" , govObj.GetNoCount (tip_mn_list, VOTE_SIGNAL_FUNDING));
667- bObj.pushKV (" AbstainCount" , govObj.GetAbstainCount (tip_mn_list, VOTE_SIGNAL_FUNDING));
668-
669- // REPORT VALIDITY AND CACHING FLAGS FOR VARIOUS SETTINGS
670- std::string strError;
671- bObj.pushKV (" fBlockchainValidity" , govObj.IsValidLocally (tip_mn_list, chainman, strError, false ));
672- bObj.pushKV (" IsValidReason" , strError.c_str ());
673- bObj.pushKV (" fCachedValid" , govObj.IsSetCachedValid ());
674- bObj.pushKV (" fCachedFunding" , govObj.IsSetCachedFunding ());
675- bObj.pushKV (" fCachedDelete" , govObj.IsSetCachedDelete ());
676- bObj.pushKV (" fCachedEndorsed" , govObj.IsSetCachedEndorsed ());
677-
678- objResult.pushKV (govObj.GetHash ().ToString (), bObj);
644+ UniValue entry{govObj.GetStateJson (chainman, tip_mn_list, /* local_valid_key=*/ " fBlockchainValidity" )};
645+ UniValue votes_funding{govObj.GetVotesJson (tip_mn_list, VOTE_SIGNAL_FUNDING)};
646+ entry.pushKV (" AbsoluteYesCount" , votes_funding[" AbsoluteYesCount" ]);
647+ entry.pushKV (" YesCount" , votes_funding[" YesCount" ]);
648+ entry.pushKV (" NoCount" , votes_funding[" NoCount" ]);
649+ entry.pushKV (" AbstainCount" , votes_funding[" AbstainCount" ]);
650+ objResult.pushKV (govObj.GetHash ().ToString (), entry);
679651 }
680652
681653 return objResult;
@@ -763,84 +735,26 @@ static RPCHelpMan gobject_get()
763735 RPCExamples{" " },
764736 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
765737{
766- // COLLECT VARIABLES FROM OUR USER
767- uint256 hash (ParseHashV (request.params [0 ], " GovObj hash" ));
768-
769738 if (g_txindex) {
770739 g_txindex->BlockUntilSyncedToCurrentChain ();
771740 }
772741
773- // FIND THE GOVERNANCE OBJECT THE USER IS LOOKING FOR
774742 const NodeContext& node = EnsureAnyNodeContext (request.context );
775743 const ChainstateManager& chainman = EnsureChainman (node);
776744
777- CHECK_NONFATAL (node.govman );
778- LOCK (cs_main);
779- auto pGovObj = node.govman ->FindConstGovernanceObject (hash);
780-
745+ uint256 hash (ParseHashV (request.params [0 ], " GovObj hash" ));
746+ auto pGovObj = CHECK_NONFATAL (node.govman )->FindConstGovernanceObject (hash);
781747 if (pGovObj == nullptr ) {
782748 throw JSONRPCError (RPC_INVALID_PARAMETER, " Unknown governance object" );
783749 }
784750
785- // REPORT BASIC OBJECT STATS
786-
787- UniValue objResult (UniValue::VOBJ);
788- objResult.pushKV (" DataHex" , pGovObj->GetDataAsHexString ());
789- objResult.pushKV (" DataString" , pGovObj->GetDataAsPlainString ());
790- objResult.pushKV (" Hash" , pGovObj->GetHash ().ToString ());
791- objResult.pushKV (" CollateralHash" , pGovObj->GetCollateralHash ().ToString ());
792- objResult.pushKV (" ObjectType" , ToUnderlying (pGovObj->GetObjectType ()));
793- objResult.pushKV (" CreationTime" , pGovObj->GetCreationTime ());
794- const COutPoint& masternodeOutpoint = pGovObj->GetMasternodeOutpoint ();
795- if (masternodeOutpoint != COutPoint ()) {
796- objResult.pushKV (" SigningMasternode" , masternodeOutpoint.ToStringShort ());
797- }
798-
799- // SHOW (MUCH MORE) INFORMATION ABOUT VOTES FOR GOVERNANCE OBJECT (THAN LIST/DIFF ABOVE)
800- // -- FUNDING VOTING RESULTS
801-
802751 auto tip_mn_list = CHECK_NONFATAL (node.dmnman )->GetListAtChainTip ();
803-
804- UniValue objFundingResult (UniValue::VOBJ);
805- objFundingResult.pushKV (" AbsoluteYesCount" , pGovObj->GetAbsoluteYesCount (tip_mn_list, VOTE_SIGNAL_FUNDING));
806- objFundingResult.pushKV (" YesCount" , pGovObj->GetYesCount (tip_mn_list, VOTE_SIGNAL_FUNDING));
807- objFundingResult.pushKV (" NoCount" , pGovObj->GetNoCount (tip_mn_list, VOTE_SIGNAL_FUNDING));
808- objFundingResult.pushKV (" AbstainCount" , pGovObj->GetAbstainCount (tip_mn_list, VOTE_SIGNAL_FUNDING));
809- objResult.pushKV (" FundingResult" , objFundingResult);
810-
811- // -- VALIDITY VOTING RESULTS
812- UniValue objValid (UniValue::VOBJ);
813- objValid.pushKV (" AbsoluteYesCount" , pGovObj->GetAbsoluteYesCount (tip_mn_list, VOTE_SIGNAL_VALID));
814- objValid.pushKV (" YesCount" , pGovObj->GetYesCount (tip_mn_list, VOTE_SIGNAL_VALID));
815- objValid.pushKV (" NoCount" , pGovObj->GetNoCount (tip_mn_list, VOTE_SIGNAL_VALID));
816- objValid.pushKV (" AbstainCount" , pGovObj->GetAbstainCount (tip_mn_list, VOTE_SIGNAL_VALID));
817- objResult.pushKV (" ValidResult" , objValid);
818-
819- // -- DELETION CRITERION VOTING RESULTS
820- UniValue objDelete (UniValue::VOBJ);
821- objDelete.pushKV (" AbsoluteYesCount" , pGovObj->GetAbsoluteYesCount (tip_mn_list, VOTE_SIGNAL_DELETE));
822- objDelete.pushKV (" YesCount" , pGovObj->GetYesCount (tip_mn_list, VOTE_SIGNAL_DELETE));
823- objDelete.pushKV (" NoCount" , pGovObj->GetNoCount (tip_mn_list, VOTE_SIGNAL_DELETE));
824- objDelete.pushKV (" AbstainCount" , pGovObj->GetAbstainCount (tip_mn_list, VOTE_SIGNAL_DELETE));
825- objResult.pushKV (" DeleteResult" , objDelete);
826-
827- // -- ENDORSED VIA MASTERNODE-ELECTED BOARD
828- UniValue objEndorsed (UniValue::VOBJ);
829- objEndorsed.pushKV (" AbsoluteYesCount" , pGovObj->GetAbsoluteYesCount (tip_mn_list, VOTE_SIGNAL_ENDORSED));
830- objEndorsed.pushKV (" YesCount" , pGovObj->GetYesCount (tip_mn_list, VOTE_SIGNAL_ENDORSED));
831- objEndorsed.pushKV (" NoCount" , pGovObj->GetNoCount (tip_mn_list, VOTE_SIGNAL_ENDORSED));
832- objEndorsed.pushKV (" AbstainCount" , pGovObj->GetAbstainCount (tip_mn_list, VOTE_SIGNAL_ENDORSED));
833- objResult.pushKV (" EndorsedResult" , objEndorsed);
834-
835- // --
836- std::string strError;
837- objResult.pushKV (" fLocalValidity" , pGovObj->IsValidLocally (tip_mn_list, chainman, strError, false ));
838- objResult.pushKV (" IsValidReason" , strError.c_str ());
839- objResult.pushKV (" fCachedValid" , pGovObj->IsSetCachedValid ());
840- objResult.pushKV (" fCachedFunding" , pGovObj->IsSetCachedFunding ());
841- objResult.pushKV (" fCachedDelete" , pGovObj->IsSetCachedDelete ());
842- objResult.pushKV (" fCachedEndorsed" , pGovObj->IsSetCachedEndorsed ());
843- return objResult;
752+ UniValue ret{pGovObj->GetStateJson (chainman, tip_mn_list, /* local_valid_key=*/ " fLocalValidity" )};
753+ ret.pushKV (" FundingResult" , pGovObj->GetVotesJson (tip_mn_list, VOTE_SIGNAL_FUNDING));
754+ ret.pushKV (" ValidResult" , pGovObj->GetVotesJson (tip_mn_list, VOTE_SIGNAL_VALID));
755+ ret.pushKV (" DeleteResult" , pGovObj->GetVotesJson (tip_mn_list, VOTE_SIGNAL_DELETE));
756+ ret.pushKV (" EndorsedResult" , pGovObj->GetVotesJson (tip_mn_list, VOTE_SIGNAL_ENDORSED));
757+ return ret;
844758},
845759 };
846760}
0 commit comments