From 6287c14417f6830e6a7604c4db9c7c5423c909d5 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Sun, 22 Sep 2024 13:08:46 +0300 Subject: [PATCH] refactor: make clang format a bit happier --- src/governance/common.cpp | 3 ++- src/governance/common.h | 14 ++++---------- src/governance/governance.cpp | 2 +- src/governance/object.cpp | 23 +++++++++++++++-------- src/governance/object.h | 17 +++++++++-------- src/rpc/governance.cpp | 13 +++++++------ 6 files changed, 38 insertions(+), 34 deletions(-) diff --git a/src/governance/common.cpp b/src/governance/common.cpp index 44e4f24751af9..185800edd38cf 100644 --- a/src/governance/common.cpp +++ b/src/governance/common.cpp @@ -12,7 +12,8 @@ namespace Governance { -Object::Object(const uint256& nHashParent, int nRevision, int64_t nTime, const uint256& commitment_hash, const std::string& strDataHex) : +Object::Object(const uint256& nHashParent, int nRevision, int64_t nTime, const uint256& commitment_hash, + const std::string& strDataHex) : hashParent{nHashParent}, revision{nRevision}, time{nTime}, diff --git a/src/governance/common.h b/src/governance/common.h index d1e0d4ba2c0fb..be76b5928b87c 100644 --- a/src/governance/common.h +++ b/src/governance/common.h @@ -34,7 +34,8 @@ class Object public: Object() = default; - Object(const uint256& nHashParent, int nRevision, int64_t nTime, const uint256& commitment_hash, const std::string& strDataHex); + Object(const uint256& nHashParent, int nRevision, int64_t nTime, const uint256& commitment_hash, + const std::string& strDataHex); UniValue ToJson() const; @@ -67,15 +68,8 @@ class Object SERIALIZE_METHODS(Object, obj) { - READWRITE( - obj.hashParent, - obj.revision, - obj.time, - obj.m_commitment_hash, - obj.vchData, - obj.type, - obj.masternodeOutpoint - ); + READWRITE(obj.hashParent, obj.revision, obj.time, obj.m_commitment_hash, obj.vchData, obj.type, + obj.masternodeOutpoint); if (!(s.GetType() & SER_GETHASH)) { READWRITE(obj.vchSig); } diff --git a/src/governance/governance.cpp b/src/governance/governance.cpp index e2bacab5a90f7..97e96a12d0d46 100644 --- a/src/governance/governance.cpp +++ b/src/governance/governance.cpp @@ -684,7 +684,7 @@ std::optional CGovernanceManager::CreateGovernanceTrigg // no sb_opt, no trigger if (!sb_opt.has_value()) return std::nullopt; - //TODO: Check if nHashParentIn, nRevision and m_commitment_hash are correct + // TODO: Check if nHashParentIn, nRevision and m_commitment_hash are correct LOCK2(cs_main, cs); // Check if identical trigger (equal DataHash()) is already created (signed by other masternode) diff --git a/src/governance/object.cpp b/src/governance/object.cpp index 7fe2336dafdbf..2c3468d315fb4 100644 --- a/src/governance/object.cpp +++ b/src/governance/object.cpp @@ -380,14 +380,16 @@ void CGovernanceObject::UpdateLocalValidity(const CDeterministicMNList& tip_mn_l } -bool CGovernanceObject::IsValidLocally(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman, std::string& strError, bool check_commitment) const +bool CGovernanceObject::IsValidLocally(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman, + std::string& strError, bool check_commitment) const { bool fMissingConfirmations = false; return IsValidLocally(tip_mn_list, chainman, strError, fMissingConfirmations, check_commitment); } -bool CGovernanceObject::IsValidLocally(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman, std::string& strError, bool& fMissingConfirmations, bool check_commitment) const +bool CGovernanceObject::IsValidLocally(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman, + std::string& strError, bool& fMissingConfirmations, bool check_commitment) const { AssertLockHeld(cs_main); @@ -458,7 +460,8 @@ CAmount CGovernanceObject::GetMinCommitmentAmount() const } } -bool CGovernanceObject::IsCommitmentValid(const ChainstateManager& chainman, std::string& strError, bool& fMissingConfirmations) const +bool CGovernanceObject::IsCommitmentValid(const ChainstateManager& chainman, std::string& strError, + bool& fMissingConfirmations) const { AssertLockHeld(cs_main); @@ -468,7 +471,8 @@ bool CGovernanceObject::IsCommitmentValid(const ChainstateManager& chainman, std // RETRIEVE TRANSACTION IN QUESTION uint256 nBlockHash; - CTransactionRef commitment_tx = GetTransaction(/* block_index */ nullptr, /* mempool */ nullptr, m_obj.m_commitment_hash, Params().GetConsensus(), nBlockHash); + CTransactionRef commitment_tx = GetTransaction(/* block_index */ nullptr, /* mempool */ nullptr, + m_obj.m_commitment_hash, Params().GetConsensus(), nBlockHash); if (!commitment_tx) { strError = strprintf("Can't find commitment tx %s", m_obj.m_commitment_hash.ToString()); LogPrintf("CGovernanceObject::%s -- %s\n", __func__, strError); @@ -494,13 +498,14 @@ bool CGovernanceObject::IsCommitmentValid(const ChainstateManager& chainman, std CAmount commitment_amount = GetMinCommitmentAmount(); - LogPrint(BCLog::GOBJECT, "CGovernanceObject::%s -- commitment_tx->vout.size() = %s, findScript = %s, commitment_amount = %lld\n", - __func__, commitment_tx->vout.size(), ScriptToAsmStr(findScript, false), commitment_amount); + LogPrint(BCLog::GOBJECT, /* Continued */ + "CGovernanceObject::%s -- commitment_tx->vout.size() = %s, findScript = %s, commitment_amount = %lld\n", + __func__, commitment_tx->vout.size(), ScriptToAsmStr(findScript, false), commitment_amount); bool foundOpReturn = false; for (const auto& output : commitment_tx->vout) { LogPrint(BCLog::GOBJECT, "CGovernanceObject::%s -- txout = %s, output.nValue = %lld, output.scriptPubKey = %s\n", - __func__, output.ToString(), output.nValue, ScriptToAsmStr(output.scriptPubKey, false)); + __func__, output.ToString(), output.nValue, ScriptToAsmStr(output.scriptPubKey, false)); if (!output.scriptPubKey.IsPayToPublicKeyHash() && !output.scriptPubKey.IsUnspendable()) { strError = strprintf("Invalid Script %s", commitment_tx->ToString()); LogPrintf("CGovernanceObject::%s -- %s\n", __func__, strError); @@ -529,7 +534,9 @@ bool CGovernanceObject::IsCommitmentValid(const ChainstateManager& chainman, std } if (nConfirmationsIn < GOVERNANCE_COMMITMENT_CONFIRMATIONS) { - strError = strprintf("Commitment tx requires at least %d confirmations to be relayed throughout the network (it has only %d)", GOVERNANCE_COMMITMENT_CONFIRMATIONS, nConfirmationsIn); + strError = strprintf("Commitment tx requires at least %d confirmations to be relayed throughout the network " + "(it has only %d)", + GOVERNANCE_COMMITMENT_CONFIRMATIONS, nConfirmationsIn); if (nConfirmationsIn >= GOVERNANCE_COMMITMENT_MIN_RELAY_CONFIRMATIONS) { fMissingConfirmations = true; strError += ", pre-accepted -- waiting for required confirmations"; diff --git a/src/governance/object.h b/src/governance/object.h index 2962eb56e5823..40f243f10a9ce 100644 --- a/src/governance/object.h +++ b/src/governance/object.h @@ -142,7 +142,8 @@ class CGovernanceObject public: CGovernanceObject(); - CGovernanceObject(const uint256& nHashParentIn, int nRevisionIn, int64_t nTime, const uint256& commitment_hash, const std::string& strDataHexIn); + CGovernanceObject(const uint256& nHashParentIn, int nRevisionIn, int64_t nTime, const uint256& commitment_hash, + const std::string& strDataHexIn); CGovernanceObject(const CGovernanceObject& other); @@ -168,10 +169,7 @@ class CGovernanceObject return m_obj.type; } - const uint256& GetCommitmentHash() const - { - return m_obj.m_commitment_hash; - } + const uint256& GetCommitmentHash() const { return m_obj.m_commitment_hash; } const COutPoint& GetMasternodeOutpoint() const { @@ -228,12 +226,15 @@ class CGovernanceObject // CORE OBJECT FUNCTIONS - bool IsValidLocally(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman, std::string& strError, bool check_commitment) const EXCLUSIVE_LOCKS_REQUIRED(cs_main); + bool IsValidLocally(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman, + std::string& strError, bool check_commitment) const EXCLUSIVE_LOCKS_REQUIRED(cs_main); - bool IsValidLocally(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman, std::string& strError, bool& fMissingConfirmations, bool check_commitment) const EXCLUSIVE_LOCKS_REQUIRED(cs_main); + bool IsValidLocally(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman, std::string& strError, + bool& fMissingConfirmations, bool check_commitment) const EXCLUSIVE_LOCKS_REQUIRED(cs_main); /// Check the commitment transaction for the budget proposal/finalized budget - bool IsCommitmentValid(const ChainstateManager& chainman, std::string& strError, bool& fMissingConfirmations) const EXCLUSIVE_LOCKS_REQUIRED(cs_main); + bool IsCommitmentValid(const ChainstateManager& chainman, std::string& strError, bool& fMissingConfirmations) const + EXCLUSIVE_LOCKS_REQUIRED(cs_main); void UpdateLocalValidity(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman); diff --git a/src/rpc/governance.cpp b/src/rpc/governance.cpp index 2005f3bffbaf6..d19e25cc8f373 100644 --- a/src/rpc/governance.cpp +++ b/src/rpc/governance.cpp @@ -125,9 +125,9 @@ static RPCHelpMan gobject_check() // PREPARE THE GOVERNANCE OBJECT BY CREATING A COMMITMENT TRANSACTION static RPCHelpMan gobject_prepare() { - return RPCHelpMan{"gobject prepare", - "Prepare governance object by signing and creating tx\n" - + HELP_REQUIRING_PASSPHRASE, + return RPCHelpMan{ + "gobject prepare", + "Prepare governance object by signing and creating tx\n" + HELP_REQUIRING_PASSPHRASE, { {"parent-hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "hash of the parent object, \"0\" is root"}, {"revision", RPCArg::Type::NUM, RPCArg::Optional::NO, "object revision in the system"}, @@ -287,7 +287,8 @@ static RPCHelpMan gobject_list_prepared() */ static RPCHelpMan gobject_submit() { - return RPCHelpMan{"gobject submit", + return RPCHelpMan{ + "gobject submit", "Submit governance object to network\n", { {"parent-hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "hash of the parent object, \"0\" is root"}, @@ -655,7 +656,7 @@ static UniValue ListObjects(CGovernanceManager& govman, const CDeterministicMNLi bObj.pushKV("DataHex", govObj.GetDataAsHexString()); bObj.pushKV("DataString", govObj.GetDataAsPlainString()); bObj.pushKV("Hash", govObj.GetHash().ToString()); - bObj.pushKV("CommitmentHash", govObj.GetCommitmentHash().ToString()); + bObj.pushKV("CommitmentHash", govObj.GetCommitmentHash().ToString()); bObj.pushKV("ObjectType", ToUnderlying(govObj.GetObjectType())); bObj.pushKV("CreationTime", govObj.GetCreationTime()); const COutPoint& masternodeOutpoint = govObj.GetMasternodeOutpoint(); @@ -773,7 +774,7 @@ static RPCHelpMan gobject_get() objResult.pushKV("DataHex", pGovObj->GetDataAsHexString()); objResult.pushKV("DataString", pGovObj->GetDataAsPlainString()); objResult.pushKV("Hash", pGovObj->GetHash().ToString()); - objResult.pushKV("CommitmentHash", pGovObj->GetCommitmentHash().ToString()); + objResult.pushKV("CommitmentHash", pGovObj->GetCommitmentHash().ToString()); objResult.pushKV("ObjectType", ToUnderlying(pGovObj->GetObjectType())); objResult.pushKV("CreationTime", pGovObj->GetCreationTime()); const COutPoint& masternodeOutpoint = pGovObj->GetMasternodeOutpoint();