Skip to content

Commit

Permalink
refactor: make clang format a bit happier
Browse files Browse the repository at this point in the history
  • Loading branch information
UdjinM6 committed Sep 22, 2024
1 parent fdf36d3 commit 6287c14
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 34 deletions.
3 changes: 2 additions & 1 deletion src/governance/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
14 changes: 4 additions & 10 deletions src/governance/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/governance/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ std::optional<const CGovernanceObject> 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)
Expand Down
23 changes: 15 additions & 8 deletions src/governance/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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";
Expand Down
17 changes: 9 additions & 8 deletions src/governance/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
{
Expand Down Expand Up @@ -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);

Expand Down
13 changes: 7 additions & 6 deletions src/rpc/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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"},
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 6287c14

Please sign in to comment.