@@ -308,8 +308,23 @@ std::string GetRequiredPaymentsString(int nBlockHeight)
308308bool CMasternodePayments::GetMasternodeTxOuts (const CBlockIndex* pindexPrev, std::vector<CTxOut>& voutMasternodePaymentsRet) const
309309{
310310 if (deterministicMNManager->LegacyMNObsolete (pindexPrev->nHeight + 1 )) {
311- // New payment logic (!TODO)
312- return false ;
311+ CAmount masternodeReward = GetMasternodePayment ();
312+ auto dmnPayee = deterministicMNManager->GetListForBlock (pindexPrev).GetMNPayee ();
313+ if (!dmnPayee) {
314+ return error (" %s: Failed to get payees for block at height %d" , __func__, pindexPrev->nHeight + 1 );
315+ }
316+ CAmount operatorReward = 0 ;
317+ if (dmnPayee->nOperatorReward != 0 && !dmnPayee->pdmnState ->scriptOperatorPayout .empty ()) {
318+ operatorReward = (masternodeReward * dmnPayee->nOperatorReward ) / 10000 ;
319+ masternodeReward -= operatorReward;
320+ }
321+ if (masternodeReward > 0 ) {
322+ voutMasternodePaymentsRet.emplace_back (masternodeReward, dmnPayee->pdmnState ->scriptPayout );
323+ }
324+ if (operatorReward > 0 ) {
325+ voutMasternodePaymentsRet.emplace_back (operatorReward, dmnPayee->pdmnState ->scriptOperatorPayout );
326+ }
327+ return true ;
313328 }
314329
315330 // Legacy payment logic. !TODO: remove when transition to DMN is complete
@@ -318,7 +333,6 @@ bool CMasternodePayments::GetMasternodeTxOuts(const CBlockIndex* pindexPrev, std
318333
319334bool CMasternodePayments::GetLegacyMasternodeTxOut (int nHeight, std::vector<CTxOut>& voutMasternodePaymentsRet) const
320335{
321- if (nHeight == 0 ) return false ;
322336 voutMasternodePaymentsRet.clear ();
323337
324338 CScript payee;
@@ -622,8 +636,24 @@ bool CMasternodePayments::IsTransactionValid(const CTransaction& txNew, const CB
622636{
623637 const int nBlockHeight = pindexPrev->nHeight + 1 ;
624638 if (deterministicMNManager->LegacyMNObsolete (nBlockHeight)) {
625- // !TODO
626- return false ;
639+ std::vector<CTxOut> vecMnOuts;
640+ if (!GetMasternodeTxOuts (pindexPrev, vecMnOuts)) {
641+ // No masternode scheduled to be paid.
642+ return true ;
643+ }
644+
645+ for (const CTxOut& o : vecMnOuts) {
646+ if (std::find (txNew.vout .begin (), txNew.vout .end (), o) == txNew.vout .end ()) {
647+ CTxDestination mnDest;
648+ const std::string& payee = ExtractDestination (o.scriptPubKey , mnDest) ? EncodeDestination (mnDest)
649+ : HexStr (o.scriptPubKey );
650+ LogPrint (BCLog::MASTERNODE, " %s: Failed to find expected payee %s in block at height %d (tx %s)" ,
651+ __func__, payee, pindexPrev->nHeight + 1 , txNew.GetHash ().ToString ());
652+ return false ;
653+ }
654+ }
655+ // all the expected payees have been found in txNew outputs
656+ return true ;
627657 }
628658
629659 // Legacy payment logic. !TODO: remove when transition to DMN is complete
0 commit comments