Skip to content

Commit

Permalink
[squash]: trivial fixes
Browse files Browse the repository at this point in the history
use std::find_if in place of for loop
use const reference
  • Loading branch information
panleone committed Jan 6, 2024
1 parent 4094aca commit 95d34ac
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 25 deletions.
10 changes: 4 additions & 6 deletions src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1707,12 +1707,10 @@ bool CheckProUpRegTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*> p
const auto& ptx{*opt_ptx};

CTxDestination payoutDest;
for (const auto& payoutShare : ptx.payoutShares) {
if (!ExtractDestination(payoutShare.scriptPayout, payoutDest)) {
// should not happen as we checked script types before
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-payee-dest");
}
}
const auto& scriptIterator = std::find_if(ptx.payoutShares.begin(), ptx.payoutShares.end(), [&](const auto& payoutShare){
return !ExtractDestination(payoutShare.scriptPayout, payoutDest);
});
if(scriptIterator != ptx.payoutShares.end()) return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-payee-dest");

auto mnList = deterministicMNManager->GetListForBlock(pindexPrev);
auto dmn = mnList.GetMN(ptx.proTxHash);
Expand Down
4 changes: 2 additions & 2 deletions src/evo/providertx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static bool TriviallyVerifyProRegPayees(const ProRegTx& proRegTx, TxValidationSt
if (payoutShares.size() > 1 && proRegTx.nVersion < ProRegTx::MULTI_PAYOUT_VERSION) {
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-payee-mismatch");
}
for (auto& payoutShare : payoutShares) {
for (const auto& payoutShare : payoutShares) {
CScript scriptPayout = payoutShare.scriptPayout;
if (!scriptPayout.IsPayToPublicKeyHash() && !scriptPayout.IsPayToScriptHash()) {
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-payee");
Expand Down Expand Up @@ -65,7 +65,7 @@ bool CProRegTx::IsTriviallyValid(bool is_basic_scheme_active, bool is_multi_payo
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-operator-reward");
}
if (!TriviallyVerifyProRegPayees<CProRegTx>(*this, state)) return false;
for (auto& payoutShare : payoutShares) {
for (const auto& payoutShare : payoutShares) {
CTxDestination payoutDest;
if (!ExtractDestination(payoutShare.scriptPayout, payoutDest)) {
// should not happen as we checked script types before
Expand Down
2 changes: 1 addition & 1 deletion src/llmq/ehf_signals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void CEHFSignalsHandler::UpdatedBlockTip(const CBlockIndex* const pindexNew)
return;
}

for (const auto& [index, deployment] : enumerate(Params().GetConsensus().vDeployments)) {
for (const auto [index, deployment] : enumerate(Params().GetConsensus().vDeployments)) {
// try only with not yet active deployments based on dip0023
// deployments with an existing RecoveredSignature will be discarded internally
if (deployment.useEHF && !DeploymentActiveAfter(pindexNew, Params().GetConsensus(),
Expand Down
26 changes: 10 additions & 16 deletions src/rpc/evo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1314,20 +1314,17 @@ static UniValue BuildDMNListEntry(CWallet* pwallet, const CDeterministicMN& dmn,
ownsCollateral = CheckWalletOwnsScript(pwallet, collateralTx->vout[dmn.collateralOutpoint.n].scriptPubKey);
}

bool ownAnyPayeeScript = false;
for (const auto& payoutShare : dmn.pdmnState->payoutShares) {
if (CheckWalletOwnsScript(pwallet, payoutShare.scriptPayout)) {
ownAnyPayeeScript = true;
break;
}
}
const auto& scriptIterator = std::find_if(dmn.pdmnState->payoutShares.begin(), dmn.pdmnState->payoutShares.end(), [&](const auto& payoutShare){
return CheckWalletOwnsScript(pwallet, payoutShare.scriptPayout);
});

if (pwallet) {
UniValue walletObj(UniValue::VOBJ);
walletObj.pushKV("hasOwnerKey", hasOwnerKey);
walletObj.pushKV("hasOperatorKey", false);
walletObj.pushKV("hasVotingKey", hasVotingKey);
walletObj.pushKV("ownsCollateral", ownsCollateral);
walletObj.pushKV("ownsPayeeScript", ownAnyPayeeScript);
walletObj.pushKV("ownsPayeeScript", scriptIterator != dmn.pdmnState->payoutShares.end());
walletObj.pushKV("ownsOperatorRewardScript", CheckWalletOwnsScript(pwallet, dmn.pdmnState->scriptOperatorPayout));
o.pushKV("wallet", walletObj);
}
Expand Down Expand Up @@ -1390,17 +1387,14 @@ static UniValue protx_list(const JSONRPCRequest& request, const ChainstateManage

CDeterministicMNList mnList = deterministicMNManager->GetListForBlock(chainman.ActiveChain()[height]);
mnList.ForEachMN(false, [&](const auto& dmn) {
bool ownAnyPayeeScript = false;
for (const auto& payoutShare : dmn.pdmnState->payoutShares) {
if (CheckWalletOwnsScript(wallet.get(), payoutShare.scriptPayout)) {
ownAnyPayeeScript = true;
break;
}
}
const auto& scriptIterator = std::find_if(dmn.pdmnState->payoutShares.begin(), dmn.pdmnState->payoutShares.end(), [&](const auto& payoutShare){
return CheckWalletOwnsScript(wallet.get(), payoutShare.scriptPayout);
});

if (setOutpts.count(dmn.collateralOutpoint) ||
CheckWalletOwnsKey(wallet.get(), dmn.pdmnState->keyIDOwner) ||
CheckWalletOwnsKey(wallet.get(), dmn.pdmnState->keyIDVoting) ||
ownAnyPayeeScript ||
(scriptIterator != dmn.pdmnState->payoutShares.end()) ||
CheckWalletOwnsScript(wallet.get(), dmn.pdmnState->scriptOperatorPayout)) {
ret.push_back(BuildDMNListEntry(wallet.get(), dmn, detailed));
}
Expand Down

0 comments on commit 95d34ac

Please sign in to comment.