@@ -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}
@@ -492,12 +497,15 @@ bool CMasternode::IsValidNetAddr() const
492497 (IsReachable (addr) && addr.IsRoutable ());
493498}
494499
495- CMasternodeBroadcast::CMasternodeBroadcast (CService newAddr, CTxIn newVin, CPubKey pubKeyCollateralAddressNew, CPubKey pubKeyMasternodeNew, const MasternodeTier nMasternodeTier, int protocolVersionIn)
500+ CMasternodeBroadcast::CMasternodeBroadcast (
501+ const CService& newAddr, const CTxIn& newVin,
502+ const CPubKey& pubKeyCollateralAddressNew, const CScript& rewardScriptIn, const CPubKey& pubKeyMasternodeNew,
503+ const MasternodeTier nMasternodeTier, const int protocolVersionIn)
496504{
497505 vin = newVin;
498506 addr = newAddr;
499507 pubKeyCollateralAddress = pubKeyCollateralAddressNew;
500- rewardScript = GetDefaultRewardScript () ;
508+ rewardScript = rewardScriptIn ;
501509 pubKeyMasternode = pubKeyMasternodeNew;
502510 protocolVersion = protocolVersionIn;
503511 nTier = nMasternodeTier;
@@ -507,8 +515,10 @@ CMasternodeBroadcast::CMasternodeBroadcast(const CMasternode& mn)
507515 : CMasternode(mn)
508516{}
509517
518+ namespace
519+ {
510520
511- bool CMasternodeBroadcastFactory:: checkBlockchainSync (std::string& strErrorRet, bool fOffline )
521+ bool checkBlockchainSync (std::string& strErrorRet, bool fOffline )
512522{
513523 if (!fOffline && !masternodeSync.IsBlockchainSynced ()) {
514524 strErrorRet = " Sync in progress. Must wait until sync is complete to start Masternode" ;
@@ -517,7 +527,8 @@ bool CMasternodeBroadcastFactory::checkBlockchainSync(std::string& strErrorRet,
517527 }
518528 return true ;
519529}
520- bool CMasternodeBroadcastFactory::setMasternodeKeys (
530+
531+ bool setMasternodeKeys (
521532 const std::string& strKeyMasternode,
522533 std::pair<CKey,CPubKey>& masternodeKeyPair,
523534 std::string& strErrorRet)
@@ -529,7 +540,8 @@ bool CMasternodeBroadcastFactory::setMasternodeKeys(
529540 }
530541 return true ;
531542}
532- bool CMasternodeBroadcastFactory::setMasternodeCollateralKeys (
543+
544+ bool setMasternodeCollateralKeys (
533545 const std::string& txHash,
534546 const std::string& outputIndex,
535547 const std::string& service,
@@ -554,7 +566,7 @@ bool CMasternodeBroadcastFactory::setMasternodeCollateralKeys(
554566 return true ;
555567}
556568
557- bool CMasternodeBroadcastFactory:: checkMasternodeCollateral (
569+ bool checkMasternodeCollateral (
558570 const CTxIn& txin,
559571 const std::string& txHash,
560572 const std::string& outputIndex,
@@ -586,13 +598,14 @@ bool CMasternodeBroadcastFactory::checkMasternodeCollateral(
586598 return true ;
587599}
588600
589- bool CMasternodeBroadcastFactory:: createArgumentsFromConfig (
601+ bool createArgumentsFromConfig (
590602 const CMasternodeConfig::CMasternodeEntry configEntry,
591603 std::string& strErrorRet,
592604 bool fOffline ,
593605 bool collateralPrivKeyIsRemote,
594606 CTxIn& txin,
595607 std::pair<CKey,CPubKey>& masternodeKeyPair,
608+ CScript& rewardScript,
596609 std::pair<CKey,CPubKey>& masternodeCollateralKeyPair,
597610 MasternodeTier& nMasternodeTier
598611 )
@@ -609,9 +622,23 @@ bool CMasternodeBroadcastFactory::createArgumentsFromConfig(
609622 {
610623 return false ;
611624 }
625+
626+ if (configEntry.getRewardAddress ().empty ())
627+ rewardScript = CMasternode::GetDefaultRewardScript (masternodeCollateralKeyPair.second );
628+ else {
629+ const CBitcoinAddress addr (configEntry.getRewardAddress ());
630+ if (!addr.IsValid ()) {
631+ strErrorRet = strprintf (" Invalid reward address for masternode: %s" , configEntry.getRewardAddress ());
632+ return false ;
633+ }
634+ rewardScript = GetScriptForDestination (addr.Get ());
635+ }
636+
612637 return true ;
613638}
614639
640+ } // anonymous namespace
641+
615642bool CMasternodeBroadcastFactory::Create (const CMasternodeConfig::CMasternodeEntry configEntry,
616643 CPubKey pubkeyCollateralAddress,
617644 std::string& strErrorRet,
@@ -622,6 +649,7 @@ bool CMasternodeBroadcastFactory::Create(const CMasternodeConfig::CMasternodeEnt
622649 const bool deferRelay = true ;
623650 CTxIn txin;
624651 std::pair<CKey,CPubKey> masternodeCollateralKeyPair;
652+ CScript rewardScript;
625653 std::pair<CKey,CPubKey> masternodeKeyPair;
626654 MasternodeTier nMasternodeTier;
627655
@@ -632,6 +660,7 @@ bool CMasternodeBroadcastFactory::Create(const CMasternodeConfig::CMasternodeEnt
632660 collateralPrivateKeyIsRemote,
633661 txin,
634662 masternodeKeyPair,
663+ rewardScript,
635664 masternodeCollateralKeyPair,
636665 nMasternodeTier))
637666 {
@@ -642,6 +671,7 @@ bool CMasternodeBroadcastFactory::Create(const CMasternodeConfig::CMasternodeEnt
642671 txin,
643672 CService (configEntry.getIp ()),
644673 pubkeyCollateralAddress,
674+ rewardScript,
645675 masternodeKeyPair.second ,
646676 nMasternodeTier,
647677 deferRelay,
@@ -670,6 +700,7 @@ bool CMasternodeBroadcastFactory::Create(
670700
671701 CTxIn txin;
672702 std::pair<CKey,CPubKey> masternodeCollateralKeyPair;
703+ CScript rewardScript;
673704 std::pair<CKey,CPubKey> masternodeKeyPair;
674705 MasternodeTier nMasternodeTier;
675706
@@ -680,6 +711,7 @@ bool CMasternodeBroadcastFactory::Create(
680711 collateralPrivateKeyIsRemote,
681712 txin,
682713 masternodeKeyPair,
714+ rewardScript,
683715 masternodeCollateralKeyPair,
684716 nMasternodeTier))
685717 {
@@ -690,6 +722,7 @@ bool CMasternodeBroadcastFactory::Create(
690722 CService (strService),
691723 masternodeCollateralKeyPair.first ,
692724 masternodeCollateralKeyPair.second ,
725+ rewardScript,
693726 masternodeKeyPair.first ,
694727 masternodeKeyPair.second ,
695728 nMasternodeTier,
@@ -747,41 +780,45 @@ bool CMasternodeBroadcastFactory::provideSignatures(
747780}
748781
749782void CMasternodeBroadcastFactory::createWithoutSignatures (
750- CTxIn txin,
751- CService service,
752- CPubKey pubKeyCollateralAddressNew,
753- CPubKey pubKeyMasternodeNew,
783+ const CTxIn& txin,
784+ const CService& service,
785+ const CPubKey& pubKeyCollateralAddressNew,
786+ const CScript& rewardScript,
787+ const CPubKey& pubKeyMasternodeNew,
754788 const MasternodeTier nMasternodeTier,
755- bool deferRelay,
789+ const bool deferRelay,
756790 CMasternodeBroadcast& mnbRet)
757791{
758792 LogPrint (" masternode" , " CMasternodeBroadcastFactory::createWithoutSignatures -- pubKeyCollateralAddressNew = %s, pubKeyMasternodeNew.GetID() = %s\n " ,
759793 CBitcoinAddress (pubKeyCollateralAddressNew.GetID ()).ToString (),
760794 pubKeyMasternodeNew.GetID ().ToString ());
761795
762796 CMasternodePing mnp = (deferRelay)? CMasternodePing::createDelayedMasternodePing (txin): CMasternodePing (txin);
763- mnbRet = CMasternodeBroadcast (service, txin, pubKeyCollateralAddressNew, pubKeyMasternodeNew, nMasternodeTier, PROTOCOL_VERSION);
797+ mnbRet = CMasternodeBroadcast (service, txin,
798+ pubKeyCollateralAddressNew, rewardScript, pubKeyMasternodeNew,
799+ nMasternodeTier, PROTOCOL_VERSION);
764800 mnbRet.lastPing = mnp;
765801 mnbRet.sigTime = mnp.sigTime ;
766802}
767803
768804bool CMasternodeBroadcastFactory::Create (
769- CTxIn txin,
770- CService service,
771- CKey keyCollateralAddressNew,
772- CPubKey pubKeyCollateralAddressNew,
773- CKey keyMasternodeNew,
774- CPubKey pubKeyMasternodeNew,
805+ const CTxIn& txin,
806+ const CService& service,
807+ const CKey& keyCollateralAddressNew,
808+ const CPubKey& pubKeyCollateralAddressNew,
809+ const CScript& rewardScript,
810+ const CKey& keyMasternodeNew,
811+ const CPubKey& pubKeyMasternodeNew,
775812 const MasternodeTier nMasternodeTier,
776813 std::string& strErrorRet,
777814 CMasternodeBroadcast& mnbRet,
778- bool deferRelay)
815+ const bool deferRelay)
779816{
780817 // wait for reindex and/or import to finish
781818 if (fImporting || fReindex ) return false ;
782819
783820 createWithoutSignatures (
784- txin,service,pubKeyCollateralAddressNew,pubKeyMasternodeNew,nMasternodeTier,deferRelay,mnbRet);
821+ txin,service,pubKeyCollateralAddressNew,rewardScript, pubKeyMasternodeNew,nMasternodeTier,deferRelay,mnbRet);
785822
786823 if (!provideSignatures (keyMasternodeNew,pubKeyMasternodeNew,keyCollateralAddressNew,mnbRet,strErrorRet))
787824 {
@@ -967,15 +1004,15 @@ CMasternodePing::CMasternodePing()
9671004 vchSig = std::vector<unsigned char >();
9681005}
9691006
970- CMasternodePing::CMasternodePing (CTxIn& newVin)
1007+ CMasternodePing::CMasternodePing (const CTxIn& newVin)
9711008{
9721009 vin = newVin;
9731010 blockHash = chainActive[chainActive.Height () - 12 ]->GetBlockHash ();
9741011 sigTime = GetAdjustedTime ();
9751012 vchSig = std::vector<unsigned char >();
9761013}
9771014
978- CMasternodePing CMasternodePing::createDelayedMasternodePing (CTxIn& newVin)
1015+ CMasternodePing CMasternodePing::createDelayedMasternodePing (const CTxIn& newVin)
9791016{
9801017 CMasternodePing ping;
9811018 const int64_t offsetTimeBy45BlocksInSeconds = 60 * 45 ;
0 commit comments