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 25, 2024
1 parent 89d5e26 commit 7b44af2
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 @@ -354,8 +354,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 @@ -398,13 +396,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 @@ -451,13 +443,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 @@ -505,13 +491,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 @@ -565,13 +545,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 @@ -624,13 +598,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 @@ -680,13 +648,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 @@ -702,12 +664,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 7b44af2

Please sign in to comment.