2015-04-16 21:58:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
// Copyright (c) 2014-2015 The Dash developers
|
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#ifndef MASTERNODE_PAYMENTS_H
|
|
|
|
#define MASTERNODE_PAYMENTS_H
|
|
|
|
|
|
|
|
#include "sync.h"
|
|
|
|
#include "net.h"
|
|
|
|
#include "key.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "base58.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "masternode.h"
|
|
|
|
#include "masternode-pos.h"
|
|
|
|
#include "timedata.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
class CMasternodePayments;
|
|
|
|
class CMasternodePaymentWinner;
|
|
|
|
|
|
|
|
extern CMasternodePayments masternodePayments;
|
|
|
|
extern map<uint256, CMasternodePaymentWinner> mapSeenMasternodeVotes;
|
|
|
|
|
|
|
|
void ProcessMessageMasternodePayments(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
|
|
|
|
|
|
|
|
|
|
|
|
// for storing the winning payments
|
|
|
|
class CMasternodePaymentWinner
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
int nBlockHeight;
|
|
|
|
CTxIn vin;
|
|
|
|
CScript payee;
|
|
|
|
std::vector<unsigned char> vchSig;
|
|
|
|
uint64_t score;
|
|
|
|
|
|
|
|
CMasternodePaymentWinner() {
|
|
|
|
nBlockHeight = 0;
|
|
|
|
score = 0;
|
|
|
|
vin = CTxIn();
|
|
|
|
payee = CScript();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint256 GetHash(){
|
|
|
|
uint256 n2 = HashX11(BEGIN(nBlockHeight), END(nBlockHeight));
|
|
|
|
uint256 n3 = vin.prevout.hash > n2 ? (vin.prevout.hash - n2) : (n2 - vin.prevout.hash);
|
|
|
|
|
|
|
|
return n3;
|
|
|
|
}
|
|
|
|
|
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
|
|
|
READWRITE(nBlockHeight);
|
|
|
|
READWRITE(payee);
|
|
|
|
READWRITE(vin);
|
|
|
|
READWRITE(score);
|
|
|
|
READWRITE(vchSig);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// Masternode Payments Class
|
|
|
|
// Keeps track of who should get paid for which blocks
|
|
|
|
//
|
|
|
|
|
|
|
|
class CMasternodePayments
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
std::vector<CMasternodePaymentWinner> vWinning;
|
|
|
|
int nSyncedFromPeer;
|
|
|
|
std::string strMasterPrivKey;
|
|
|
|
bool enabled;
|
|
|
|
int nLastBlockHeight;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
CMasternodePayments() {
|
|
|
|
enabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SetPrivKey(std::string strPrivKey);
|
|
|
|
bool CheckSignature(CMasternodePaymentWinner& winner);
|
|
|
|
bool Sign(CMasternodePaymentWinner& winner);
|
|
|
|
|
|
|
|
// Deterministically calculate a given "score" for a masternode depending on how close it's hash is
|
|
|
|
// to the blockHeight. The further away they are the better, the furthest will win the election
|
|
|
|
// and get paid this block
|
|
|
|
//
|
|
|
|
|
|
|
|
uint64_t CalculateScore(uint256 blockHash, CTxIn& vin);
|
|
|
|
bool GetWinningMasternode(int nBlockHeight, CTxIn& vinOut);
|
|
|
|
bool AddWinningMasternode(CMasternodePaymentWinner& winner);
|
|
|
|
bool ProcessBlock(int nBlockHeight);
|
|
|
|
void Relay(CMasternodePaymentWinner& winner);
|
|
|
|
void Sync(CNode* node);
|
|
|
|
void CleanPaymentList();
|
|
|
|
int LastPayment(CMasternode& mn);
|
|
|
|
|
2015-04-16 22:59:10 +02:00
|
|
|
bool GetBlockPayee(int nBlockHeight, CScript& payee, CTxIn& vin);
|
2015-04-16 21:58:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|