@@ -344,13 +344,20 @@ static std::string SignAndSendSpecialTx(const JSONRPCRequest& request, CChainsta
344
344
}
345
345
346
346
// forward declaration
347
+ namespace {
348
+ enum class ProTxRegisterAction
349
+ {
350
+ External,
351
+ Fund,
352
+ Prepare,
353
+ };
354
+ } // anonumous namespace
355
+
347
356
static UniValue protx_register_common_wrapper (const JSONRPCRequest& request,
348
357
CChainstateHelper& chain_helper,
349
358
const ChainstateManager& chainman,
350
359
const bool specific_legacy_bls_scheme,
351
- const bool isExternalRegister,
352
- const bool isFundRegister,
353
- const bool isPrepareRegister,
360
+ ProTxRegisterAction action,
354
361
const MnType mnType);
355
362
356
363
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)
397
404
CHECK_NONFATAL (node.chain_helper );
398
405
CChainstateHelper& chain_helper = *node.chain_helper ;
399
406
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);
404
408
},
405
409
};
406
410
}
@@ -453,11 +457,7 @@ static RPCHelpMan protx_register_wrapper(bool legacy)
453
457
CHECK_NONFATAL (node.chain_helper );
454
458
CChainstateHelper& chain_helper = *node.chain_helper ;
455
459
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);
461
461
},
462
462
};
463
463
}
@@ -511,10 +511,7 @@ static RPCHelpMan protx_register_prepare_wrapper(const bool legacy)
511
511
CHECK_NONFATAL (node.chain_helper );
512
512
CChainstateHelper& chain_helper = *node.chain_helper ;
513
513
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);
518
515
},
519
516
};
520
517
}
@@ -574,10 +571,7 @@ static RPCHelpMan protx_register_fund_evo_wrapper(bool use_hpmn_suffix)
574
571
CHECK_NONFATAL (node.chain_helper );
575
572
CChainstateHelper& chain_helper = *node.chain_helper ;
576
573
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);
581
575
},
582
576
};
583
577
}
@@ -636,11 +630,7 @@ static RPCHelpMan protx_register_evo_wrapper(bool use_hpmn_suffix)
636
630
CHECK_NONFATAL (node.chain_helper );
637
631
CChainstateHelper& chain_helper = *node.chain_helper ;
638
632
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);
644
634
},
645
635
};
646
636
}
@@ -696,10 +686,7 @@ static RPCHelpMan protx_register_prepare_evo_wrapper(bool use_hpmn_suffix)
696
686
CHECK_NONFATAL (node.chain_helper );
697
687
CChainstateHelper& chain_helper = *node.chain_helper ;
698
688
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);
703
690
},
704
691
};
705
692
}
@@ -718,17 +705,15 @@ static UniValue protx_register_common_wrapper(const JSONRPCRequest& request,
718
705
CChainstateHelper& chain_helper,
719
706
const ChainstateManager& chainman,
720
707
const bool specific_legacy_bls_scheme,
721
- const bool isExternalRegister,
722
- const bool isFundRegister,
723
- const bool isPrepareRegister,
708
+ const ProTxRegisterAction action,
724
709
const MnType mnType)
725
710
{
726
711
const bool isEvoRequested = mnType == MnType::Evo;
727
712
728
713
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (request);
729
714
if (!wallet) return NullUniValue;
730
715
731
- if (isExternalRegister || isFundRegister ) {
716
+ if (action == ProTxRegisterAction::External || action == ProTxRegisterAction::Fund ) {
732
717
EnsureWalletIsUnlocked (wallet.get ());
733
718
}
734
719
@@ -748,7 +733,7 @@ static UniValue protx_register_common_wrapper(const JSONRPCRequest& request,
748
733
CProRegTx ptx;
749
734
ptx.nType = mnType;
750
735
751
- if (isFundRegister ) {
736
+ if (action == ProTxRegisterAction::Fund ) {
752
737
CTxDestination collateralDest = DecodeDestination (request.params [paramIdx].get_str ());
753
738
if (!IsValidDestination (collateralDest)) {
754
739
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,
826
811
ptx.keyIDVoting = keyIDVoting;
827
812
ptx.scriptPayout = GetScriptForDestination (payoutDest);
828
813
829
- if (!isFundRegister ) {
814
+ if (action != ProTxRegisterAction::Fund ) {
830
815
// make sure fee calculation works
831
816
ptx.vchSig .resize (65 );
832
817
}
@@ -839,11 +824,11 @@ static UniValue protx_register_common_wrapper(const JSONRPCRequest& request,
839
824
}
840
825
841
826
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 ()) {
843
828
fSubmit = ParseBoolV (request.params [paramIdx + 7 ], " submit" );
844
829
}
845
830
846
- if (isFundRegister ) {
831
+ if (action == ProTxRegisterAction::Fund ) {
847
832
FundSpecialTx (wallet.get (), tx, ptx, fundDest);
848
833
UpdateSpecialTxInputsHash (tx, ptx);
849
834
CAmount fundCollateral = GetMnType (mnType).collat_amount ;
@@ -883,7 +868,7 @@ static UniValue protx_register_common_wrapper(const JSONRPCRequest& request,
883
868
throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, strprintf (" collateral type not supported: %s" , ptx.collateralOutpoint .ToStringShort ()));
884
869
}
885
870
886
- if (isPrepareRegister ) {
871
+ if (action == ProTxRegisterAction::Prepare ) {
887
872
// external signing with collateral key
888
873
ptx.vchSig .clear ();
889
874
SetTxPayload (tx, ptx);
0 commit comments