Skip to content

Commit

Permalink
refactor: move common code inside protx_register_common_wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
knst committed Jun 21, 2024
1 parent a849374 commit 82e524d
Showing 1 changed file with 12 additions and 46 deletions.
58 changes: 12 additions & 46 deletions src/rpc/evo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
},
};
}
Expand Down Expand Up @@ -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);
},
};
}
Expand Down Expand Up @@ -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);
},
};
}
Expand Down Expand Up @@ -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);
},
};
}
Expand Down Expand Up @@ -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);
},
};
}
Expand Down Expand Up @@ -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);
},
};
}
Expand All @@ -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<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
Expand Down

0 comments on commit 82e524d

Please sign in to comment.