From 82e524de4429e5c8735638837f1db98a0e30fcee Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Fri, 21 Jun 2024 22:32:49 +0700 Subject: [PATCH] refactor: move common code inside protx_register_common_wrapper --- src/rpc/evo.cpp | 58 ++++++++++--------------------------------------- 1 file changed, 12 insertions(+), 46 deletions(-) diff --git a/src/rpc/evo.cpp b/src/rpc/evo.cpp index e9c5884b5aa337..e1c4d2c05cb3ba 100644 --- a/src/rpc/evo.cpp +++ b/src/rpc/evo.cpp @@ -366,8 +366,6 @@ enum class ProTxRegisterAction } // anonumous namespace static UniValue protx_register_common_wrapper(const JSONRPCRequest& request, - CChainstateHelper& chain_helper, - const ChainstateManager& chainman, const bool specific_legacy_bls_scheme, ProTxRegisterAction action, const MnType mnType); @@ -410,13 +408,7 @@ static RPCHelpMan protx_register_fund_wrapper(const bool legacy) }, [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { - const NodeContext& node = EnsureAnyNodeContext(request.context); - const ChainstateManager& chainman = EnsureChainman(node); - - CHECK_NONFATAL(node.chain_helper); - CChainstateHelper& chain_helper = *node.chain_helper; - - return protx_register_common_wrapper(request, chain_helper, chainman, legacy, ProTxRegisterAction::Fund, MnType::Regular); + return protx_register_common_wrapper(request, legacy, ProTxRegisterAction::Fund, MnType::Regular); }, }; } @@ -463,13 +455,7 @@ static RPCHelpMan protx_register_wrapper(bool legacy) }, [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { - const NodeContext& node = EnsureAnyNodeContext(request.context); - const ChainstateManager& chainman = EnsureChainman(node); - - CHECK_NONFATAL(node.chain_helper); - CChainstateHelper& chain_helper = *node.chain_helper; - - return protx_register_common_wrapper(request, chain_helper, chainman, legacy, ProTxRegisterAction::External, MnType::Regular); + return protx_register_common_wrapper(request, legacy, ProTxRegisterAction::External, MnType::Regular); }, }; } @@ -517,13 +503,7 @@ static RPCHelpMan protx_register_prepare_wrapper(const bool legacy) }, [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { - const NodeContext& node = EnsureAnyNodeContext(request.context); - const ChainstateManager& chainman = EnsureChainman(node); - - CHECK_NONFATAL(node.chain_helper); - CChainstateHelper& chain_helper = *node.chain_helper; - - return protx_register_common_wrapper(request, chain_helper, chainman, legacy, ProTxRegisterAction::Prepare, MnType::Regular); + return protx_register_common_wrapper(request, legacy, ProTxRegisterAction::Prepare, MnType::Regular); }, }; } @@ -577,13 +557,7 @@ static RPCHelpMan protx_register_fund_evo_wrapper(bool use_hpmn_suffix) throw JSONRPCError(RPC_METHOD_DEPRECATED, "*_hpmn methods are deprecated. Use the related *_evo methods or set -deprecatedrpc=hpmn to enable them"); } - const NodeContext& node = EnsureAnyNodeContext(request.context); - const ChainstateManager& chainman = EnsureChainman(node); - - CHECK_NONFATAL(node.chain_helper); - CChainstateHelper& chain_helper = *node.chain_helper; - - return protx_register_common_wrapper(request, chain_helper, chainman, false, ProTxRegisterAction::Fund, MnType::Evo); + return protx_register_common_wrapper(request, false, ProTxRegisterAction::Fund, MnType::Evo); }, }; } @@ -636,13 +610,7 @@ static RPCHelpMan protx_register_evo_wrapper(bool use_hpmn_suffix) throw JSONRPCError(RPC_METHOD_DEPRECATED, "*_hpmn methods are deprecated. Use the related *_evo methods or set -deprecatedrpc=hpmn to enable them"); } - const NodeContext& node = EnsureAnyNodeContext(request.context); - const ChainstateManager& chainman = EnsureChainman(node); - - CHECK_NONFATAL(node.chain_helper); - CChainstateHelper& chain_helper = *node.chain_helper; - - return protx_register_common_wrapper(request, chain_helper, chainman, false, ProTxRegisterAction::External, MnType::Evo); + return protx_register_common_wrapper(request, false, ProTxRegisterAction::External, MnType::Evo); }, }; } @@ -692,13 +660,7 @@ static RPCHelpMan protx_register_prepare_evo_wrapper(bool use_hpmn_suffix) throw JSONRPCError(RPC_METHOD_DEPRECATED, "*_hpmn methods are deprecated. Use the related *_evo methods or set -deprecatedrpc=hpmn to enable them"); } - const NodeContext& node = EnsureAnyNodeContext(request.context); - const ChainstateManager& chainman = EnsureChainman(node); - - CHECK_NONFATAL(node.chain_helper); - CChainstateHelper& chain_helper = *node.chain_helper; - - return protx_register_common_wrapper(request, chain_helper, chainman, false, ProTxRegisterAction::Prepare, MnType::Evo); + return protx_register_common_wrapper(request, false, ProTxRegisterAction::Prepare, MnType::Evo); }, }; } @@ -714,12 +676,16 @@ static RPCHelpMan protx_register_prepare_hpmn() } static UniValue protx_register_common_wrapper(const JSONRPCRequest& request, - CChainstateHelper& chain_helper, - const ChainstateManager& chainman, const bool specific_legacy_bls_scheme, const ProTxRegisterAction action, const MnType mnType) { + const NodeContext& node = EnsureAnyNodeContext(request.context); + const ChainstateManager& chainman = EnsureChainman(node); + + CHECK_NONFATAL(node.chain_helper); + CChainstateHelper& chain_helper = *node.chain_helper; + const bool isEvoRequested = mnType == MnType::Evo; std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request);