@@ -212,6 +212,11 @@ CMasternode& CMasternode::operator=(CMasternode from)
212212}
213213
214214CScript CMasternode::GetDefaultRewardScript () const
215+ {
216+ return GetDefaultRewardScript (pubKeyCollateralAddress);
217+ }
218+
219+ CScript CMasternode::GetDefaultRewardScript (const CPubKey& pubKeyCollateralAddress)
215220{
216221 return GetScriptForDestination (pubKeyCollateralAddress.GetID ());
217222}
@@ -496,12 +501,15 @@ bool CMasternode::IsValidNetAddr() const
496501 (IsReachable (addr) && addr.IsRoutable ());
497502}
498503
499- CMasternodeBroadcast::CMasternodeBroadcast (CService newAddr, CTxIn newVin, CPubKey pubKeyCollateralAddressNew, CPubKey pubKeyMasternodeNew, const MasternodeTier nMasternodeTier, int protocolVersionIn)
504+ CMasternodeBroadcast::CMasternodeBroadcast (
505+ const CService& newAddr, const CTxIn& newVin,
506+ const CPubKey& pubKeyCollateralAddressNew, const CScript& rewardScriptIn, const CPubKey& pubKeyMasternodeNew,
507+ const MasternodeTier nMasternodeTier, const int protocolVersionIn)
500508{
501509 vin = newVin;
502510 addr = newAddr;
503511 pubKeyCollateralAddress = pubKeyCollateralAddressNew;
504- rewardScript = GetDefaultRewardScript () ;
512+ rewardScript = rewardScriptIn ;
505513 pubKeyMasternode = pubKeyMasternodeNew;
506514 protocolVersion = protocolVersionIn;
507515 nTier = nMasternodeTier;
@@ -511,8 +519,10 @@ CMasternodeBroadcast::CMasternodeBroadcast(const CMasternode& mn)
511519 : CMasternode(mn)
512520{}
513521
522+ namespace
523+ {
514524
515- bool CMasternodeBroadcastFactory:: checkBlockchainSync (std::string& strErrorRet, bool fOffline )
525+ bool checkBlockchainSync (std::string& strErrorRet, bool fOffline )
516526{
517527 if (!fOffline && !masternodeSync.IsBlockchainSynced ()) {
518528 strErrorRet = " Sync in progress. Must wait until sync is complete to start Masternode" ;
@@ -521,7 +531,8 @@ bool CMasternodeBroadcastFactory::checkBlockchainSync(std::string& strErrorRet,
521531 }
522532 return true ;
523533}
524- bool CMasternodeBroadcastFactory::setMasternodeKeys (
534+
535+ bool setMasternodeKeys (
525536 const std::string& strKeyMasternode,
526537 std::pair<CKey,CPubKey>& masternodeKeyPair,
527538 std::string& strErrorRet)
@@ -533,7 +544,8 @@ bool CMasternodeBroadcastFactory::setMasternodeKeys(
533544 }
534545 return true ;
535546}
536- bool CMasternodeBroadcastFactory::setMasternodeCollateralKeys (
547+
548+ bool setMasternodeCollateralKeys (
537549 const std::string& txHash,
538550 const std::string& outputIndex,
539551 const std::string& service,
@@ -558,7 +570,7 @@ bool CMasternodeBroadcastFactory::setMasternodeCollateralKeys(
558570 return true ;
559571}
560572
561- bool CMasternodeBroadcastFactory:: checkMasternodeCollateral (
573+ bool checkMasternodeCollateral (
562574 const CTxIn& txin,
563575 const std::string& txHash,
564576 const std::string& outputIndex,
@@ -590,13 +602,14 @@ bool CMasternodeBroadcastFactory::checkMasternodeCollateral(
590602 return true ;
591603}
592604
593- bool CMasternodeBroadcastFactory:: createArgumentsFromConfig (
605+ bool createArgumentsFromConfig (
594606 const CMasternodeConfig::CMasternodeEntry configEntry,
595607 std::string& strErrorRet,
596608 bool fOffline ,
597609 bool collateralPrivKeyIsRemote,
598610 CTxIn& txin,
599611 std::pair<CKey,CPubKey>& masternodeKeyPair,
612+ CScript& rewardScript,
600613 std::pair<CKey,CPubKey>& masternodeCollateralKeyPair,
601614 MasternodeTier& nMasternodeTier
602615 )
@@ -613,9 +626,23 @@ bool CMasternodeBroadcastFactory::createArgumentsFromConfig(
613626 {
614627 return false ;
615628 }
629+
630+ if (configEntry.getRewardAddress ().empty ())
631+ rewardScript = CMasternode::GetDefaultRewardScript (masternodeCollateralKeyPair.second );
632+ else {
633+ const CBitcoinAddress addr (configEntry.getRewardAddress ());
634+ if (!addr.IsValid ()) {
635+ strErrorRet = strprintf (" Invalid reward address for masternode: %s" , configEntry.getRewardAddress ());
636+ return false ;
637+ }
638+ rewardScript = GetScriptForDestination (addr.Get ());
639+ }
640+
616641 return true ;
617642}
618643
644+ } // anonymous namespace
645+
619646bool CMasternodeBroadcastFactory::Create (const CMasternodeConfig::CMasternodeEntry configEntry,
620647 CPubKey pubkeyCollateralAddress,
621648 std::string& strErrorRet,
@@ -626,6 +653,7 @@ bool CMasternodeBroadcastFactory::Create(const CMasternodeConfig::CMasternodeEnt
626653 const bool deferRelay = true ;
627654 CTxIn txin;
628655 std::pair<CKey,CPubKey> masternodeCollateralKeyPair;
656+ CScript rewardScript;
629657 std::pair<CKey,CPubKey> masternodeKeyPair;
630658 MasternodeTier nMasternodeTier;
631659
@@ -636,6 +664,7 @@ bool CMasternodeBroadcastFactory::Create(const CMasternodeConfig::CMasternodeEnt
636664 collateralPrivateKeyIsRemote,
637665 txin,
638666 masternodeKeyPair,
667+ rewardScript,
639668 masternodeCollateralKeyPair,
640669 nMasternodeTier))
641670 {
@@ -646,6 +675,7 @@ bool CMasternodeBroadcastFactory::Create(const CMasternodeConfig::CMasternodeEnt
646675 txin,
647676 CService (configEntry.getIp ()),
648677 pubkeyCollateralAddress,
678+ rewardScript,
649679 masternodeKeyPair.second ,
650680 nMasternodeTier,
651681 deferRelay,
@@ -674,6 +704,7 @@ bool CMasternodeBroadcastFactory::Create(
674704
675705 CTxIn txin;
676706 std::pair<CKey,CPubKey> masternodeCollateralKeyPair;
707+ CScript rewardScript;
677708 std::pair<CKey,CPubKey> masternodeKeyPair;
678709 MasternodeTier nMasternodeTier;
679710
@@ -684,6 +715,7 @@ bool CMasternodeBroadcastFactory::Create(
684715 collateralPrivateKeyIsRemote,
685716 txin,
686717 masternodeKeyPair,
718+ rewardScript,
687719 masternodeCollateralKeyPair,
688720 nMasternodeTier))
689721 {
@@ -694,6 +726,7 @@ bool CMasternodeBroadcastFactory::Create(
694726 CService (strService),
695727 masternodeCollateralKeyPair.first ,
696728 masternodeCollateralKeyPair.second ,
729+ rewardScript,
697730 masternodeKeyPair.first ,
698731 masternodeKeyPair.second ,
699732 nMasternodeTier,
@@ -772,19 +805,22 @@ CMasternodePing createDelayedMasternodePing(const CMasternodeBroadcast& mnb)
772805} // anonymous namespace
773806
774807void CMasternodeBroadcastFactory::createWithoutSignatures (
775- CTxIn txin,
776- CService service,
777- CPubKey pubKeyCollateralAddressNew,
778- CPubKey pubKeyMasternodeNew,
808+ const CTxIn& txin,
809+ const CService& service,
810+ const CPubKey& pubKeyCollateralAddressNew,
811+ const CScript& rewardScript,
812+ const CPubKey& pubKeyMasternodeNew,
779813 const MasternodeTier nMasternodeTier,
780- bool deferRelay,
814+ const bool deferRelay,
781815 CMasternodeBroadcast& mnbRet)
782816{
783817 LogPrint (" masternode" , " CMasternodeBroadcastFactory::createWithoutSignatures -- pubKeyCollateralAddressNew = %s, pubKeyMasternodeNew.GetID() = %s\n " ,
784818 CBitcoinAddress (pubKeyCollateralAddressNew.GetID ()).ToString (),
785819 pubKeyMasternodeNew.GetID ().ToString ());
786820
787- mnbRet = CMasternodeBroadcast (service, txin, pubKeyCollateralAddressNew, pubKeyMasternodeNew, nMasternodeTier, PROTOCOL_VERSION);
821+ mnbRet = CMasternodeBroadcast (service, txin,
822+ pubKeyCollateralAddressNew, rewardScript, pubKeyMasternodeNew,
823+ nMasternodeTier, PROTOCOL_VERSION);
788824 const CMasternodePing mnp = (deferRelay
789825 ? createDelayedMasternodePing (mnbRet)
790826 : CMasternodePing (txin));
@@ -793,22 +829,23 @@ void CMasternodeBroadcastFactory::createWithoutSignatures(
793829}
794830
795831bool CMasternodeBroadcastFactory::Create (
796- CTxIn txin,
797- CService service,
798- CKey keyCollateralAddressNew,
799- CPubKey pubKeyCollateralAddressNew,
800- CKey keyMasternodeNew,
801- CPubKey pubKeyMasternodeNew,
832+ const CTxIn& txin,
833+ const CService& service,
834+ const CKey& keyCollateralAddressNew,
835+ const CPubKey& pubKeyCollateralAddressNew,
836+ const CScript& rewardScript,
837+ const CKey& keyMasternodeNew,
838+ const CPubKey& pubKeyMasternodeNew,
802839 const MasternodeTier nMasternodeTier,
803840 std::string& strErrorRet,
804841 CMasternodeBroadcast& mnbRet,
805- bool deferRelay)
842+ const bool deferRelay)
806843{
807844 // wait for reindex and/or import to finish
808845 if (fImporting || fReindex ) return false ;
809846
810847 createWithoutSignatures (
811- txin,service,pubKeyCollateralAddressNew,pubKeyMasternodeNew,nMasternodeTier,deferRelay,mnbRet);
848+ txin,service,pubKeyCollateralAddressNew,rewardScript, pubKeyMasternodeNew,nMasternodeTier,deferRelay,mnbRet);
812849
813850 if (!provideSignatures (keyMasternodeNew,pubKeyMasternodeNew,keyCollateralAddressNew,mnbRet,strErrorRet))
814851 {
@@ -1031,7 +1068,7 @@ CMasternodePing::CMasternodePing()
10311068 vchSig = std::vector<unsigned char >();
10321069}
10331070
1034- CMasternodePing::CMasternodePing (CTxIn& newVin)
1071+ CMasternodePing::CMasternodePing (const CTxIn& newVin)
10351072{
10361073 vin = newVin;
10371074 blockHash = chainActive[chainActive.Height () - 12 ]->GetBlockHash ();
0 commit comments