@@ -211,6 +211,11 @@ CMasternode& CMasternode::operator=(CMasternode from)
211211}
212212
213213CScript CMasternode::GetDefaultRewardScript () const
214+ {
215+ return GetDefaultRewardScript (pubKeyCollateralAddress);
216+ }
217+
218+ CScript CMasternode::GetDefaultRewardScript (const CPubKey& pubKeyCollateralAddress)
214219{
215220 return GetScriptForDestination (pubKeyCollateralAddress.GetID ());
216221}
@@ -495,12 +500,15 @@ bool CMasternode::IsValidNetAddr() const
495500 (IsReachable (addr) && addr.IsRoutable ());
496501}
497502
498- CMasternodeBroadcast::CMasternodeBroadcast (CService newAddr, CTxIn newVin, CPubKey pubKeyCollateralAddressNew, CPubKey pubKeyMasternodeNew, const MasternodeTier nMasternodeTier, int protocolVersionIn)
503+ CMasternodeBroadcast::CMasternodeBroadcast (
504+ const CService& newAddr, const CTxIn& newVin,
505+ const CPubKey& pubKeyCollateralAddressNew, const CScript& rewardScriptIn, const CPubKey& pubKeyMasternodeNew,
506+ const MasternodeTier nMasternodeTier, const int protocolVersionIn)
499507{
500508 vin = newVin;
501509 addr = newAddr;
502510 pubKeyCollateralAddress = pubKeyCollateralAddressNew;
503- rewardScript = GetDefaultRewardScript () ;
511+ rewardScript = rewardScriptIn ;
504512 pubKeyMasternode = pubKeyMasternodeNew;
505513 protocolVersion = protocolVersionIn;
506514 nTier = nMasternodeTier;
@@ -510,8 +518,10 @@ CMasternodeBroadcast::CMasternodeBroadcast(const CMasternode& mn)
510518 : CMasternode(mn)
511519{}
512520
521+ namespace
522+ {
513523
514- bool CMasternodeBroadcastFactory:: checkBlockchainSync (std::string& strErrorRet, bool fOffline )
524+ bool checkBlockchainSync (std::string& strErrorRet, bool fOffline )
515525{
516526 if (!fOffline && !masternodeSync.IsBlockchainSynced ()) {
517527 strErrorRet = " Sync in progress. Must wait until sync is complete to start Masternode" ;
@@ -520,7 +530,8 @@ bool CMasternodeBroadcastFactory::checkBlockchainSync(std::string& strErrorRet,
520530 }
521531 return true ;
522532}
523- bool CMasternodeBroadcastFactory::setMasternodeKeys (
533+
534+ bool setMasternodeKeys (
524535 const std::string& strKeyMasternode,
525536 std::pair<CKey,CPubKey>& masternodeKeyPair,
526537 std::string& strErrorRet)
@@ -532,7 +543,8 @@ bool CMasternodeBroadcastFactory::setMasternodeKeys(
532543 }
533544 return true ;
534545}
535- bool CMasternodeBroadcastFactory::setMasternodeCollateralKeys (
546+
547+ bool setMasternodeCollateralKeys (
536548 const std::string& txHash,
537549 const std::string& outputIndex,
538550 const std::string& service,
@@ -557,7 +569,7 @@ bool CMasternodeBroadcastFactory::setMasternodeCollateralKeys(
557569 return true ;
558570}
559571
560- bool CMasternodeBroadcastFactory:: checkMasternodeCollateral (
572+ bool checkMasternodeCollateral (
561573 const CTxIn& txin,
562574 const std::string& txHash,
563575 const std::string& outputIndex,
@@ -589,13 +601,14 @@ bool CMasternodeBroadcastFactory::checkMasternodeCollateral(
589601 return true ;
590602}
591603
592- bool CMasternodeBroadcastFactory:: createArgumentsFromConfig (
604+ bool createArgumentsFromConfig (
593605 const CMasternodeConfig::CMasternodeEntry configEntry,
594606 std::string& strErrorRet,
595607 bool fOffline ,
596608 bool collateralPrivKeyIsRemote,
597609 CTxIn& txin,
598610 std::pair<CKey,CPubKey>& masternodeKeyPair,
611+ CScript& rewardScript,
599612 std::pair<CKey,CPubKey>& masternodeCollateralKeyPair,
600613 MasternodeTier& nMasternodeTier
601614 )
@@ -612,9 +625,23 @@ bool CMasternodeBroadcastFactory::createArgumentsFromConfig(
612625 {
613626 return false ;
614627 }
628+
629+ if (configEntry.getRewardAddress ().empty ())
630+ rewardScript = CMasternode::GetDefaultRewardScript (masternodeCollateralKeyPair.second );
631+ else {
632+ const CBitcoinAddress addr (configEntry.getRewardAddress ());
633+ if (!addr.IsValid ()) {
634+ strErrorRet = strprintf (" Invalid reward address for masternode: %s" , configEntry.getRewardAddress ());
635+ return false ;
636+ }
637+ rewardScript = GetScriptForDestination (addr.Get ());
638+ }
639+
615640 return true ;
616641}
617642
643+ } // anonymous namespace
644+
618645bool CMasternodeBroadcastFactory::Create (const CMasternodeConfig::CMasternodeEntry configEntry,
619646 CPubKey pubkeyCollateralAddress,
620647 std::string& strErrorRet,
@@ -625,6 +652,7 @@ bool CMasternodeBroadcastFactory::Create(const CMasternodeConfig::CMasternodeEnt
625652 const bool deferRelay = true ;
626653 CTxIn txin;
627654 std::pair<CKey,CPubKey> masternodeCollateralKeyPair;
655+ CScript rewardScript;
628656 std::pair<CKey,CPubKey> masternodeKeyPair;
629657 MasternodeTier nMasternodeTier;
630658
@@ -635,6 +663,7 @@ bool CMasternodeBroadcastFactory::Create(const CMasternodeConfig::CMasternodeEnt
635663 collateralPrivateKeyIsRemote,
636664 txin,
637665 masternodeKeyPair,
666+ rewardScript,
638667 masternodeCollateralKeyPair,
639668 nMasternodeTier))
640669 {
@@ -645,6 +674,7 @@ bool CMasternodeBroadcastFactory::Create(const CMasternodeConfig::CMasternodeEnt
645674 txin,
646675 CService (configEntry.getIp ()),
647676 pubkeyCollateralAddress,
677+ rewardScript,
648678 masternodeKeyPair.second ,
649679 nMasternodeTier,
650680 deferRelay,
@@ -673,6 +703,7 @@ bool CMasternodeBroadcastFactory::Create(
673703
674704 CTxIn txin;
675705 std::pair<CKey,CPubKey> masternodeCollateralKeyPair;
706+ CScript rewardScript;
676707 std::pair<CKey,CPubKey> masternodeKeyPair;
677708 MasternodeTier nMasternodeTier;
678709
@@ -683,6 +714,7 @@ bool CMasternodeBroadcastFactory::Create(
683714 collateralPrivateKeyIsRemote,
684715 txin,
685716 masternodeKeyPair,
717+ rewardScript,
686718 masternodeCollateralKeyPair,
687719 nMasternodeTier))
688720 {
@@ -693,6 +725,7 @@ bool CMasternodeBroadcastFactory::Create(
693725 CService (strService),
694726 masternodeCollateralKeyPair.first ,
695727 masternodeCollateralKeyPair.second ,
728+ rewardScript,
696729 masternodeKeyPair.first ,
697730 masternodeKeyPair.second ,
698731 nMasternodeTier,
@@ -771,19 +804,22 @@ CMasternodePing createDelayedMasternodePing(const CMasternodeBroadcast& mnb)
771804} // anonymous namespace
772805
773806void CMasternodeBroadcastFactory::createWithoutSignatures (
774- CTxIn txin,
775- CService service,
776- CPubKey pubKeyCollateralAddressNew,
777- CPubKey pubKeyMasternodeNew,
807+ const CTxIn& txin,
808+ const CService& service,
809+ const CPubKey& pubKeyCollateralAddressNew,
810+ const CScript& rewardScript,
811+ const CPubKey& pubKeyMasternodeNew,
778812 const MasternodeTier nMasternodeTier,
779- bool deferRelay,
813+ const bool deferRelay,
780814 CMasternodeBroadcast& mnbRet)
781815{
782816 LogPrint (" masternode" , " CMasternodeBroadcastFactory::createWithoutSignatures -- pubKeyCollateralAddressNew = %s, pubKeyMasternodeNew.GetID() = %s\n " ,
783817 CBitcoinAddress (pubKeyCollateralAddressNew.GetID ()).ToString (),
784818 pubKeyMasternodeNew.GetID ().ToString ());
785819
786- mnbRet = CMasternodeBroadcast (service, txin, pubKeyCollateralAddressNew, pubKeyMasternodeNew, nMasternodeTier, PROTOCOL_VERSION);
820+ mnbRet = CMasternodeBroadcast (service, txin,
821+ pubKeyCollateralAddressNew, rewardScript, pubKeyMasternodeNew,
822+ nMasternodeTier, PROTOCOL_VERSION);
787823 const CMasternodePing mnp = (deferRelay
788824 ? createDelayedMasternodePing (mnbRet)
789825 : CMasternodePing (txin));
@@ -792,22 +828,23 @@ void CMasternodeBroadcastFactory::createWithoutSignatures(
792828}
793829
794830bool CMasternodeBroadcastFactory::Create (
795- CTxIn txin,
796- CService service,
797- CKey keyCollateralAddressNew,
798- CPubKey pubKeyCollateralAddressNew,
799- CKey keyMasternodeNew,
800- CPubKey pubKeyMasternodeNew,
831+ const CTxIn& txin,
832+ const CService& service,
833+ const CKey& keyCollateralAddressNew,
834+ const CPubKey& pubKeyCollateralAddressNew,
835+ const CScript& rewardScript,
836+ const CKey& keyMasternodeNew,
837+ const CPubKey& pubKeyMasternodeNew,
801838 const MasternodeTier nMasternodeTier,
802839 std::string& strErrorRet,
803840 CMasternodeBroadcast& mnbRet,
804- bool deferRelay)
841+ const bool deferRelay)
805842{
806843 // wait for reindex and/or import to finish
807844 if (fImporting || fReindex ) return false ;
808845
809846 createWithoutSignatures (
810- txin,service,pubKeyCollateralAddressNew,pubKeyMasternodeNew,nMasternodeTier,deferRelay,mnbRet);
847+ txin,service,pubKeyCollateralAddressNew,rewardScript, pubKeyMasternodeNew,nMasternodeTier,deferRelay,mnbRet);
811848
812849 if (!provideSignatures (keyMasternodeNew,pubKeyMasternodeNew,keyCollateralAddressNew,mnbRet,strErrorRet))
813850 {
@@ -1030,7 +1067,7 @@ CMasternodePing::CMasternodePing()
10301067 vchSig = std::vector<unsigned char >();
10311068}
10321069
1033- CMasternodePing::CMasternodePing (CTxIn& newVin)
1070+ CMasternodePing::CMasternodePing (const CTxIn& newVin)
10341071{
10351072 vin = newVin;
10361073 blockHash = chainActive[chainActive.Height () - 12 ]->GetBlockHash ();
0 commit comments