Skip to content

Commit 89d5e26

Browse files
committed
refactor: replace bunch of bool flags to the enum
1 parent 1351bc9 commit 89d5e26

File tree

1 file changed

+23
-38
lines changed

1 file changed

+23
-38
lines changed

src/rpc/evo.cpp

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -344,13 +344,20 @@ static std::string SignAndSendSpecialTx(const JSONRPCRequest& request, CChainsta
344344
}
345345

346346
// forward declaration
347+
namespace {
348+
enum class ProTxRegisterAction
349+
{
350+
External,
351+
Fund,
352+
Prepare,
353+
};
354+
} // anonumous namespace
355+
347356
static UniValue protx_register_common_wrapper(const JSONRPCRequest& request,
348357
CChainstateHelper& chain_helper,
349358
const ChainstateManager& chainman,
350359
const bool specific_legacy_bls_scheme,
351-
const bool isExternalRegister,
352-
const bool isFundRegister,
353-
const bool isPrepareRegister,
360+
ProTxRegisterAction action,
354361
const MnType mnType);
355362

356363
static UniValue protx_update_service_common_wrapper(const JSONRPCRequest& request, const MnType mnType);
@@ -397,10 +404,7 @@ static RPCHelpMan protx_register_fund_wrapper(const bool legacy)
397404
CHECK_NONFATAL(node.chain_helper);
398405
CChainstateHelper& chain_helper = *node.chain_helper;
399406

400-
const bool isExternalRegister = false;
401-
const bool isFundRegister = true;
402-
const bool isPrepareRegister = false;
403-
return protx_register_common_wrapper(request, chain_helper, chainman, legacy, isExternalRegister, isFundRegister, isPrepareRegister, MnType::Regular);
407+
return protx_register_common_wrapper(request, chain_helper, chainman, legacy, ProTxRegisterAction::Fund, MnType::Regular);
404408
},
405409
};
406410
}
@@ -453,11 +457,7 @@ static RPCHelpMan protx_register_wrapper(bool legacy)
453457
CHECK_NONFATAL(node.chain_helper);
454458
CChainstateHelper& chain_helper = *node.chain_helper;
455459

456-
const bool isExternalRegister = true;
457-
const bool isFundRegister = false;
458-
const bool isPrepareRegister = false;
459-
460-
return protx_register_common_wrapper(request, chain_helper, chainman, legacy, isExternalRegister, isFundRegister, isPrepareRegister, MnType::Regular);
460+
return protx_register_common_wrapper(request, chain_helper, chainman, legacy, ProTxRegisterAction::External, MnType::Regular);
461461
},
462462
};
463463
}
@@ -511,10 +511,7 @@ static RPCHelpMan protx_register_prepare_wrapper(const bool legacy)
511511
CHECK_NONFATAL(node.chain_helper);
512512
CChainstateHelper& chain_helper = *node.chain_helper;
513513

514-
const bool isExternalRegister = false;
515-
const bool isFundRegister = false;
516-
const bool isPrepareRegister = true;
517-
return protx_register_common_wrapper(request, chain_helper, chainman, legacy, isExternalRegister, isFundRegister, isPrepareRegister, MnType::Regular);
514+
return protx_register_common_wrapper(request, chain_helper, chainman, legacy, ProTxRegisterAction::Prepare, MnType::Regular);
518515
},
519516
};
520517
}
@@ -574,10 +571,7 @@ static RPCHelpMan protx_register_fund_evo_wrapper(bool use_hpmn_suffix)
574571
CHECK_NONFATAL(node.chain_helper);
575572
CChainstateHelper& chain_helper = *node.chain_helper;
576573

577-
const bool isExternalRegister = false;
578-
const bool isFundRegister = true;
579-
const bool isPrepareRegister = false;
580-
return protx_register_common_wrapper(request, chain_helper, chainman, false, isExternalRegister, isFundRegister, isPrepareRegister, MnType::Evo);
574+
return protx_register_common_wrapper(request, chain_helper, chainman, false, ProTxRegisterAction::Fund, MnType::Evo);
581575
},
582576
};
583577
}
@@ -636,11 +630,7 @@ static RPCHelpMan protx_register_evo_wrapper(bool use_hpmn_suffix)
636630
CHECK_NONFATAL(node.chain_helper);
637631
CChainstateHelper& chain_helper = *node.chain_helper;
638632

639-
const bool isExternalRegister = true;
640-
const bool isFundRegister = false;
641-
const bool isPrepareRegister = false;
642-
643-
return protx_register_common_wrapper(request, chain_helper, chainman, false, isExternalRegister, isFundRegister, isPrepareRegister, MnType::Evo);
633+
return protx_register_common_wrapper(request, chain_helper, chainman, false, ProTxRegisterAction::External, MnType::Evo);
644634
},
645635
};
646636
}
@@ -696,10 +686,7 @@ static RPCHelpMan protx_register_prepare_evo_wrapper(bool use_hpmn_suffix)
696686
CHECK_NONFATAL(node.chain_helper);
697687
CChainstateHelper& chain_helper = *node.chain_helper;
698688

699-
const bool isExternalRegister = false;
700-
const bool isFundRegister = false;
701-
const bool isPrepareRegister = true;
702-
return protx_register_common_wrapper(request, chain_helper, chainman, false, isExternalRegister, isFundRegister, isPrepareRegister, MnType::Evo);
689+
return protx_register_common_wrapper(request, chain_helper, chainman, false, ProTxRegisterAction::Prepare, MnType::Evo);
703690
},
704691
};
705692
}
@@ -718,17 +705,15 @@ static UniValue protx_register_common_wrapper(const JSONRPCRequest& request,
718705
CChainstateHelper& chain_helper,
719706
const ChainstateManager& chainman,
720707
const bool specific_legacy_bls_scheme,
721-
const bool isExternalRegister,
722-
const bool isFundRegister,
723-
const bool isPrepareRegister,
708+
const ProTxRegisterAction action,
724709
const MnType mnType)
725710
{
726711
const bool isEvoRequested = mnType == MnType::Evo;
727712

728713
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
729714
if (!wallet) return NullUniValue;
730715

731-
if (isExternalRegister || isFundRegister) {
716+
if (action == ProTxRegisterAction::External || action == ProTxRegisterAction::Fund) {
732717
EnsureWalletIsUnlocked(wallet.get());
733718
}
734719

@@ -748,7 +733,7 @@ static UniValue protx_register_common_wrapper(const JSONRPCRequest& request,
748733
CProRegTx ptx;
749734
ptx.nType = mnType;
750735

751-
if (isFundRegister) {
736+
if (action == ProTxRegisterAction::Fund) {
752737
CTxDestination collateralDest = DecodeDestination(request.params[paramIdx].get_str());
753738
if (!IsValidDestination(collateralDest)) {
754739
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("invalid collaterall address: %s", request.params[paramIdx].get_str()));
@@ -826,7 +811,7 @@ static UniValue protx_register_common_wrapper(const JSONRPCRequest& request,
826811
ptx.keyIDVoting = keyIDVoting;
827812
ptx.scriptPayout = GetScriptForDestination(payoutDest);
828813

829-
if (!isFundRegister) {
814+
if (action != ProTxRegisterAction::Fund) {
830815
// make sure fee calculation works
831816
ptx.vchSig.resize(65);
832817
}
@@ -839,11 +824,11 @@ static UniValue protx_register_common_wrapper(const JSONRPCRequest& request,
839824
}
840825

841826
bool fSubmit{true};
842-
if ((isExternalRegister || isFundRegister) && !request.params[paramIdx + 7].isNull()) {
827+
if ((action == ProTxRegisterAction::External || action == ProTxRegisterAction::Fund) && !request.params[paramIdx + 7].isNull()) {
843828
fSubmit = ParseBoolV(request.params[paramIdx + 7], "submit");
844829
}
845830

846-
if (isFundRegister) {
831+
if (action == ProTxRegisterAction::Fund) {
847832
FundSpecialTx(wallet.get(), tx, ptx, fundDest);
848833
UpdateSpecialTxInputsHash(tx, ptx);
849834
CAmount fundCollateral = GetMnType(mnType).collat_amount;
@@ -883,7 +868,7 @@ static UniValue protx_register_common_wrapper(const JSONRPCRequest& request,
883868
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("collateral type not supported: %s", ptx.collateralOutpoint.ToStringShort()));
884869
}
885870

886-
if (isPrepareRegister) {
871+
if (action == ProTxRegisterAction::Prepare) {
887872
// external signing with collateral key
888873
ptx.vchSig.clear();
889874
SetTxPayload(tx, ptx);

0 commit comments

Comments
 (0)