Skip to content

Commit 7b44af2

Browse files
committed
refactor: move common code inside protx_register_common_wrapper
1 parent 89d5e26 commit 7b44af2

File tree

1 file changed

+12
-46
lines changed

1 file changed

+12
-46
lines changed

src/rpc/evo.cpp

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,6 @@ enum class ProTxRegisterAction
354354
} // anonumous namespace
355355

356356
static UniValue protx_register_common_wrapper(const JSONRPCRequest& request,
357-
CChainstateHelper& chain_helper,
358-
const ChainstateManager& chainman,
359357
const bool specific_legacy_bls_scheme,
360358
ProTxRegisterAction action,
361359
const MnType mnType);
@@ -398,13 +396,7 @@ static RPCHelpMan protx_register_fund_wrapper(const bool legacy)
398396
},
399397
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
400398
{
401-
const NodeContext& node = EnsureAnyNodeContext(request.context);
402-
const ChainstateManager& chainman = EnsureChainman(node);
403-
404-
CHECK_NONFATAL(node.chain_helper);
405-
CChainstateHelper& chain_helper = *node.chain_helper;
406-
407-
return protx_register_common_wrapper(request, chain_helper, chainman, legacy, ProTxRegisterAction::Fund, MnType::Regular);
399+
return protx_register_common_wrapper(request, legacy, ProTxRegisterAction::Fund, MnType::Regular);
408400
},
409401
};
410402
}
@@ -451,13 +443,7 @@ static RPCHelpMan protx_register_wrapper(bool legacy)
451443
},
452444
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
453445
{
454-
const NodeContext& node = EnsureAnyNodeContext(request.context);
455-
const ChainstateManager& chainman = EnsureChainman(node);
456-
457-
CHECK_NONFATAL(node.chain_helper);
458-
CChainstateHelper& chain_helper = *node.chain_helper;
459-
460-
return protx_register_common_wrapper(request, chain_helper, chainman, legacy, ProTxRegisterAction::External, MnType::Regular);
446+
return protx_register_common_wrapper(request, legacy, ProTxRegisterAction::External, MnType::Regular);
461447
},
462448
};
463449
}
@@ -505,13 +491,7 @@ static RPCHelpMan protx_register_prepare_wrapper(const bool legacy)
505491
},
506492
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
507493
{
508-
const NodeContext& node = EnsureAnyNodeContext(request.context);
509-
const ChainstateManager& chainman = EnsureChainman(node);
510-
511-
CHECK_NONFATAL(node.chain_helper);
512-
CChainstateHelper& chain_helper = *node.chain_helper;
513-
514-
return protx_register_common_wrapper(request, chain_helper, chainman, legacy, ProTxRegisterAction::Prepare, MnType::Regular);
494+
return protx_register_common_wrapper(request, legacy, ProTxRegisterAction::Prepare, MnType::Regular);
515495
},
516496
};
517497
}
@@ -565,13 +545,7 @@ static RPCHelpMan protx_register_fund_evo_wrapper(bool use_hpmn_suffix)
565545
throw JSONRPCError(RPC_METHOD_DEPRECATED, "*_hpmn methods are deprecated. Use the related *_evo methods or set -deprecatedrpc=hpmn to enable them");
566546
}
567547

568-
const NodeContext& node = EnsureAnyNodeContext(request.context);
569-
const ChainstateManager& chainman = EnsureChainman(node);
570-
571-
CHECK_NONFATAL(node.chain_helper);
572-
CChainstateHelper& chain_helper = *node.chain_helper;
573-
574-
return protx_register_common_wrapper(request, chain_helper, chainman, false, ProTxRegisterAction::Fund, MnType::Evo);
548+
return protx_register_common_wrapper(request, false, ProTxRegisterAction::Fund, MnType::Evo);
575549
},
576550
};
577551
}
@@ -624,13 +598,7 @@ static RPCHelpMan protx_register_evo_wrapper(bool use_hpmn_suffix)
624598
throw JSONRPCError(RPC_METHOD_DEPRECATED, "*_hpmn methods are deprecated. Use the related *_evo methods or set -deprecatedrpc=hpmn to enable them");
625599
}
626600

627-
const NodeContext& node = EnsureAnyNodeContext(request.context);
628-
const ChainstateManager& chainman = EnsureChainman(node);
629-
630-
CHECK_NONFATAL(node.chain_helper);
631-
CChainstateHelper& chain_helper = *node.chain_helper;
632-
633-
return protx_register_common_wrapper(request, chain_helper, chainman, false, ProTxRegisterAction::External, MnType::Evo);
601+
return protx_register_common_wrapper(request, false, ProTxRegisterAction::External, MnType::Evo);
634602
},
635603
};
636604
}
@@ -680,13 +648,7 @@ static RPCHelpMan protx_register_prepare_evo_wrapper(bool use_hpmn_suffix)
680648
throw JSONRPCError(RPC_METHOD_DEPRECATED, "*_hpmn methods are deprecated. Use the related *_evo methods or set -deprecatedrpc=hpmn to enable them");
681649
}
682650

683-
const NodeContext& node = EnsureAnyNodeContext(request.context);
684-
const ChainstateManager& chainman = EnsureChainman(node);
685-
686-
CHECK_NONFATAL(node.chain_helper);
687-
CChainstateHelper& chain_helper = *node.chain_helper;
688-
689-
return protx_register_common_wrapper(request, chain_helper, chainman, false, ProTxRegisterAction::Prepare, MnType::Evo);
651+
return protx_register_common_wrapper(request, false, ProTxRegisterAction::Prepare, MnType::Evo);
690652
},
691653
};
692654
}
@@ -702,12 +664,16 @@ static RPCHelpMan protx_register_prepare_hpmn()
702664
}
703665

704666
static UniValue protx_register_common_wrapper(const JSONRPCRequest& request,
705-
CChainstateHelper& chain_helper,
706-
const ChainstateManager& chainman,
707667
const bool specific_legacy_bls_scheme,
708668
const ProTxRegisterAction action,
709669
const MnType mnType)
710670
{
671+
const NodeContext& node = EnsureAnyNodeContext(request.context);
672+
const ChainstateManager& chainman = EnsureChainman(node);
673+
674+
CHECK_NONFATAL(node.chain_helper);
675+
CChainstateHelper& chain_helper = *node.chain_helper;
676+
711677
const bool isEvoRequested = mnType == MnType::Evo;
712678

713679
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);

0 commit comments

Comments
 (0)