| 813 | } |
| 814 | |
| 815 | bool CMasternodePayments::ProcessBlock(int nBlockHeight) { |
| 816 | LOCK(cs_masternodes); |
| 817 | if (!enabled) return false; |
| 818 | CMasternodePaymentWinner winner; |
| 819 | |
| 820 | std::vector <CTxIn> vecLastPayments; |
| 821 | int c = 0; |
| 822 | for (CMasternodePaymentWinner& winner : reverse_iterate(vWinning)) { |
| 823 | vecLastPayments.push_back(winner.vin); |
| 824 | //if we have one full payment cycle, break |
| 825 | if (++c > (int) vecMasternodes.size()) break; |
| 826 | } |
| 827 | |
| 828 | std::random_shuffle(vecMasternodes.begin(), vecMasternodes.end()); |
| 829 | for (CMasterNode& mn : vecMasternodes) { |
| 830 | bool found = false; |
| 831 | for (CTxIn & vin : vecLastPayments) |
| 832 | if (mn.vin == vin) found = true; |
| 833 | |
| 834 | if (found) continue; |
| 835 | |
| 836 | mn.Check(); |
| 837 | if (!mn.IsEnabled()) { |
| 838 | continue; |
| 839 | } |
| 840 | |
| 841 | winner.score = 0; |
| 842 | winner.nBlockHeight = nBlockHeight; |
| 843 | winner.vin = mn.vin; |
| 844 | winner.payee = GetScriptForDestination(mn.pubkey.GetID()); |
| 845 | |
| 846 | break; |
| 847 | } |
| 848 | |
| 849 | //if we can't find someone to get paid, pick randomly |
| 850 | if (winner.nBlockHeight == 0 && vecMasternodes.size() > 0) { |
| 851 | winner.score = 0; |
| 852 | winner.nBlockHeight = nBlockHeight; |
| 853 | winner.vin = vecMasternodes[0].vin; |
| 854 | winner.payee = GetScriptForDestination(vecMasternodes[0].pubkey.GetID()); |
| 855 | } |
| 856 | |
| 857 | if (Sign(winner)) { |
| 858 | if (AddWinningMasternode(winner)) { |
| 859 | Relay(winner); |
| 860 | return true; |
| 861 | } |
| 862 | } |
| 863 | |
| 864 | return false; |
| 865 | } |
| 866 | |
| 867 | void CMasternodePayments::Relay(CMasternodePaymentWinner& winner) { |
| 868 | CInv inv(MSG_MASTERNODE_WINNER, winner.GetHash()); |
no test coverage detected