2015-04-22 16:33:44 +02:00
|
|
|
// Copyright (c) 2014-2015 The Dash developers
|
2015-05-30 19:27:51 +02:00
|
|
|
|
2015-04-22 16:33:44 +02:00
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#ifndef MASTERNODE_BUDGET_H
|
|
|
|
#define MASTERNODE_BUDGET_H
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
#include "sync.h"
|
|
|
|
#include "net.h"
|
|
|
|
#include "key.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "base58.h"
|
|
|
|
#include "masternode.h"
|
|
|
|
//#include "timedata.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
class CBudgetManager;
|
2015-05-04 17:04:09 +02:00
|
|
|
class CFinalizedBudgetBroadcast;
|
|
|
|
class CFinalizedBudget;
|
|
|
|
class CFinalizedBudgetVote;
|
2015-04-22 16:33:44 +02:00
|
|
|
class CBudgetProposal;
|
2015-05-04 17:04:09 +02:00
|
|
|
class CBudgetProposalBroadcast;
|
2015-04-22 16:33:44 +02:00
|
|
|
class CBudgetVote;
|
2015-05-30 22:12:12 +02:00
|
|
|
class CTxBudgetPayment;
|
2015-04-22 16:33:44 +02:00
|
|
|
|
|
|
|
#define VOTE_ABSTAIN 0
|
|
|
|
#define VOTE_YES 1
|
|
|
|
#define VOTE_NO 2
|
2015-07-04 16:49:49 +02:00
|
|
|
#define VOTE_PROP_INC 15 //how many "votes" to count for a new proposal
|
2015-04-22 16:33:44 +02:00
|
|
|
|
2015-05-27 18:28:55 +02:00
|
|
|
extern std::map<uint256, CBudgetProposalBroadcast> mapSeenMasternodeBudgetProposals;
|
|
|
|
extern std::map<uint256, CBudgetVote> mapSeenMasternodeBudgetVotes;
|
|
|
|
extern std::map<uint256, CFinalizedBudgetBroadcast> mapSeenFinalizedBudgets;
|
|
|
|
extern std::map<uint256, CFinalizedBudgetVote> mapSeenFinalizedBudgetVotes;
|
2015-05-04 17:04:09 +02:00
|
|
|
|
2015-04-22 16:33:44 +02:00
|
|
|
extern CBudgetManager budget;
|
|
|
|
void DumpBudgets();
|
|
|
|
|
2015-05-26 16:56:51 +02:00
|
|
|
//Amount of blocks in a months period of time (using 2.6 minutes per)
|
|
|
|
int GetBudgetPaymentCycleBlocks();
|
2015-06-01 21:06:03 +02:00
|
|
|
void SubmitFinalBudget();
|
2015-05-26 16:56:51 +02:00
|
|
|
|
2015-04-22 16:33:44 +02:00
|
|
|
/** Save Budget Manager (budget.dat)
|
|
|
|
*/
|
|
|
|
class CBudgetDB
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
boost::filesystem::path pathDB;
|
|
|
|
std::string strMagicMessage;
|
|
|
|
public:
|
|
|
|
enum ReadResult {
|
|
|
|
Ok,
|
|
|
|
FileError,
|
|
|
|
HashReadError,
|
|
|
|
IncorrectHash,
|
|
|
|
IncorrectMagicMessage,
|
|
|
|
IncorrectMagicNumber,
|
|
|
|
IncorrectFormat
|
|
|
|
};
|
|
|
|
|
|
|
|
CBudgetDB();
|
2015-06-23 18:38:28 +02:00
|
|
|
bool Write(const CBudgetManager &objToSave);
|
|
|
|
ReadResult Read(CBudgetManager& objToLoad);
|
2015-04-22 16:33:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Budget Manager : Contains all proposals for the budget
|
|
|
|
//
|
|
|
|
class CBudgetManager
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
// critical section to protect the inner data structures
|
|
|
|
mutable CCriticalSection cs;
|
|
|
|
|
|
|
|
public:
|
|
|
|
// keep track of the scanning errors I've seen
|
|
|
|
map<uint256, CBudgetProposal> mapProposals;
|
2015-05-04 17:04:09 +02:00
|
|
|
map<uint256, CFinalizedBudget> mapFinalizedBudgets;
|
2015-06-24 01:44:31 +02:00
|
|
|
|
2015-04-22 16:33:44 +02:00
|
|
|
CBudgetManager() {
|
|
|
|
mapProposals.clear();
|
2015-05-04 17:04:09 +02:00
|
|
|
mapFinalizedBudgets.clear();
|
2015-04-22 16:33:44 +02:00
|
|
|
}
|
|
|
|
|
2015-07-02 01:46:03 +02:00
|
|
|
int sizeFinalized() {return (int)mapFinalizedBudgets.size();}
|
|
|
|
int sizeProposals() {return (int)mapProposals.size();}
|
|
|
|
|
2015-07-02 18:41:33 +02:00
|
|
|
void Sync(CNode* node, uint256 nProp);
|
2015-04-22 16:33:44 +02:00
|
|
|
|
|
|
|
void Calculate();
|
|
|
|
void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
|
2015-05-04 12:05:08 +02:00
|
|
|
void NewBlock();
|
2015-05-30 19:27:51 +02:00
|
|
|
CBudgetProposal *FindProposal(const std::string &strProposalName);
|
|
|
|
CBudgetProposal *FindProposal(uint256 nHash);
|
|
|
|
CFinalizedBudget *FindFinalizedBudget(uint256 nHash);
|
2015-04-22 16:33:44 +02:00
|
|
|
std::pair<std::string, std::string> GetVotes(std::string strProposalName);
|
2015-05-26 16:56:51 +02:00
|
|
|
|
2015-04-22 16:33:44 +02:00
|
|
|
void CleanUp();
|
|
|
|
|
2015-06-10 04:46:24 +02:00
|
|
|
int64_t GetTotalBudget(int nHeight);
|
2015-04-22 16:33:44 +02:00
|
|
|
std::vector<CBudgetProposal*> GetBudget();
|
2015-07-03 19:54:10 +02:00
|
|
|
std::vector<CBudgetProposal*> GetAllProposals();
|
2015-05-04 17:04:09 +02:00
|
|
|
std::vector<CFinalizedBudget*> GetFinalizedBudgets();
|
2015-05-26 16:56:51 +02:00
|
|
|
bool IsBudgetPaymentBlock(int nBlockHeight);
|
2015-05-04 17:04:09 +02:00
|
|
|
void AddProposal(CBudgetProposal& prop);
|
|
|
|
void AddFinalizedBudget(CFinalizedBudget& prop);
|
2015-07-02 18:41:33 +02:00
|
|
|
|
|
|
|
bool UpdateProposal(CBudgetVote& vote, CNode* pfrom);
|
|
|
|
bool UpdateFinalizedBudget(CFinalizedBudgetVote& vote, CNode* pfrom);
|
2015-05-04 17:04:09 +02:00
|
|
|
bool PropExists(uint256 nHash);
|
|
|
|
bool IsTransactionValid(const CTransaction& txNew, int nBlockHeight);
|
2015-05-26 16:56:51 +02:00
|
|
|
std::string GetRequiredPaymentsString(int64_t nBlockHeight);
|
2015-05-30 19:27:51 +02:00
|
|
|
void FillBlockPayee(CMutableTransaction& txNew, int64_t nFees);
|
2015-04-22 16:33:44 +02:00
|
|
|
|
2015-07-04 16:49:49 +02:00
|
|
|
//Have masternodes resign proposals with masternodes that have went inactive
|
|
|
|
void ResignInvalidProposals();
|
|
|
|
void CheckSignatureValidity();
|
|
|
|
|
2015-04-22 16:33:44 +02:00
|
|
|
void Clear(){
|
2015-06-01 21:06:03 +02:00
|
|
|
LogPrintf("Budget object cleared\n");
|
|
|
|
mapProposals.clear();
|
|
|
|
mapFinalizedBudgets.clear();
|
2015-04-22 16:33:44 +02:00
|
|
|
}
|
2015-06-01 21:06:03 +02:00
|
|
|
void CheckAndRemove();
|
2015-04-22 16:33:44 +02:00
|
|
|
std::string ToString() {return "not implemented";}
|
|
|
|
|
|
|
|
|
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
2015-05-27 18:28:55 +02:00
|
|
|
READWRITE(mapSeenMasternodeBudgetProposals);
|
|
|
|
READWRITE(mapSeenMasternodeBudgetVotes);
|
|
|
|
READWRITE(mapSeenFinalizedBudgets);
|
|
|
|
READWRITE(mapSeenFinalizedBudgetVotes);
|
2015-05-04 17:04:09 +02:00
|
|
|
|
2015-04-22 16:33:44 +02:00
|
|
|
READWRITE(mapProposals);
|
2015-05-04 17:04:09 +02:00
|
|
|
READWRITE(mapFinalizedBudgets);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-05-30 22:12:12 +02:00
|
|
|
|
|
|
|
class CTxBudgetPayment
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
uint256 nProposalHash;
|
|
|
|
CScript payee;
|
|
|
|
int64_t nAmount;
|
|
|
|
|
|
|
|
CTxBudgetPayment() {
|
|
|
|
payee = CScript();
|
|
|
|
nAmount = 0;
|
|
|
|
nProposalHash = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
//for saving to the serialized db
|
|
|
|
template <typename Stream, typename Operation>
|
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
|
|
|
READWRITE(payee);
|
|
|
|
READWRITE(nAmount);
|
|
|
|
READWRITE(nProposalHash);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-05-04 17:04:09 +02:00
|
|
|
//
|
|
|
|
// Finalized Budget : Contains the suggested proposals to pay on a given block
|
|
|
|
//
|
|
|
|
|
|
|
|
class CFinalizedBudget
|
|
|
|
{
|
|
|
|
|
|
|
|
private:
|
|
|
|
// critical section to protect the inner data structures
|
|
|
|
mutable CCriticalSection cs;
|
2015-06-01 21:06:03 +02:00
|
|
|
bool fAutoChecked; //If it matches what we see, we'll auto vote for it (masternode only)
|
2015-05-04 17:04:09 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
std::string strBudgetName;
|
2015-06-01 21:06:03 +02:00
|
|
|
CTxIn vin;
|
2015-05-04 17:04:09 +02:00
|
|
|
int nBlockStart;
|
2015-05-30 22:12:12 +02:00
|
|
|
std::vector<CTxBudgetPayment> vecProposals;
|
2015-05-04 17:04:09 +02:00
|
|
|
map<uint256, CFinalizedBudgetVote> mapVotes;
|
|
|
|
|
2015-06-24 01:44:31 +02:00
|
|
|
CFinalizedBudget();
|
2015-05-04 17:04:09 +02:00
|
|
|
CFinalizedBudget(const CFinalizedBudget& other);
|
|
|
|
|
2015-07-04 16:49:49 +02:00
|
|
|
void CleanAndRemove();
|
2015-05-04 17:04:09 +02:00
|
|
|
void AddOrUpdateVote(CFinalizedBudgetVote& vote);
|
|
|
|
double GetScore();
|
|
|
|
bool HasMinimumRequiredSupport();
|
|
|
|
|
|
|
|
bool IsValid();
|
|
|
|
|
|
|
|
std::string GetName() {return strBudgetName; }
|
|
|
|
std::string GetProposals();
|
|
|
|
int GetBlockStart() {return nBlockStart;}
|
|
|
|
int GetBlockEnd() {return nBlockStart + (int)(vecProposals.size()-1);}
|
|
|
|
std::string GetSubmittedBy() {return vin.prevout.ToStringShort();}
|
|
|
|
int GetVoteCount() {return (int)mapVotes.size();}
|
|
|
|
bool IsTransactionValid(const CTransaction& txNew, int nBlockHeight);
|
2015-05-30 22:12:12 +02:00
|
|
|
bool GetProposalByBlock(int64_t nBlockHeight, CTxBudgetPayment& payment)
|
2015-05-26 16:56:51 +02:00
|
|
|
{
|
|
|
|
int i = nBlockHeight - GetBlockStart();
|
2015-05-30 22:12:12 +02:00
|
|
|
if(i < 0) return false;
|
|
|
|
if(i > (int)vecProposals.size()-1) return false;
|
|
|
|
payment = vecProposals[i];
|
|
|
|
return true;
|
2015-05-26 16:56:51 +02:00
|
|
|
}
|
2015-05-30 22:12:12 +02:00
|
|
|
bool GetPayeeAndAmount(int64_t nBlockHeight, CScript& payee, int64_t& nAmount)
|
|
|
|
{
|
|
|
|
int i = nBlockHeight - GetBlockStart();
|
|
|
|
if(i < 0) return false;
|
|
|
|
if(i > (int)vecProposals.size()-1) return false;
|
|
|
|
payee = vecProposals[i].payee;
|
|
|
|
nAmount = vecProposals[i].nAmount;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-01 21:06:03 +02:00
|
|
|
//check to see if we should vote on this
|
|
|
|
void AutoCheck();
|
2015-06-10 04:46:24 +02:00
|
|
|
//total dash paid out by this budget
|
|
|
|
int64_t GetTotalPayout();
|
2015-06-01 21:06:03 +02:00
|
|
|
//vote on this finalized budget as a masternode
|
|
|
|
void SubmitVote();
|
|
|
|
|
2015-05-30 22:12:12 +02:00
|
|
|
//checks the hashes to make sure we know about them
|
|
|
|
string GetStatus();
|
2015-05-04 17:04:09 +02:00
|
|
|
|
|
|
|
uint256 GetHash(){
|
2015-06-24 01:44:31 +02:00
|
|
|
/*
|
2015-05-04 17:04:09 +02:00
|
|
|
vin is not included on purpose
|
2015-06-24 01:44:31 +02:00
|
|
|
- Any masternode can make a proposal and the hashes should match regardless of who made it.
|
|
|
|
- Someone could hyjack a new proposal by changing the vin and the signature check will fail.
|
|
|
|
However, the network will still propagate the correct version and the incorrect one will be rejected.
|
2015-05-04 17:04:09 +02:00
|
|
|
*/
|
2015-06-24 01:44:31 +02:00
|
|
|
|
2015-05-04 17:04:09 +02:00
|
|
|
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
|
|
|
|
ss << strBudgetName;
|
|
|
|
ss << nBlockStart;
|
|
|
|
ss << vecProposals;
|
|
|
|
|
2015-06-24 01:44:31 +02:00
|
|
|
uint256 h1 = ss.GetHash();
|
2015-05-04 17:04:09 +02:00
|
|
|
return h1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
//for saving to the serialized db
|
|
|
|
template <typename Stream, typename Operation>
|
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
|
|
|
READWRITE(LIMITED_STRING(strBudgetName, 20));
|
|
|
|
READWRITE(vin);
|
|
|
|
READWRITE(nBlockStart);
|
|
|
|
READWRITE(vecProposals);
|
|
|
|
|
|
|
|
READWRITE(mapVotes);
|
2015-04-22 16:33:44 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-05-04 17:04:09 +02:00
|
|
|
// FinalizedBudget are cast then sent to peers with this object, which leaves the votes out
|
|
|
|
class CFinalizedBudgetBroadcast : public CFinalizedBudget
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
std::vector<unsigned char> vchSig;
|
2015-06-24 01:44:31 +02:00
|
|
|
|
2015-05-04 17:04:09 +02:00
|
|
|
public:
|
2015-07-04 16:49:49 +02:00
|
|
|
bool fInvalid;
|
2015-05-04 17:04:09 +02:00
|
|
|
CFinalizedBudgetBroadcast();
|
|
|
|
CFinalizedBudgetBroadcast(const CFinalizedBudget& other);
|
2015-05-30 22:12:12 +02:00
|
|
|
CFinalizedBudgetBroadcast(CTxIn& vinIn, std::string strBudgetNameIn, int nBlockStartIn, std::vector<CTxBudgetPayment> vecProposalsIn);
|
2015-05-04 17:04:09 +02:00
|
|
|
|
|
|
|
bool Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode);
|
|
|
|
bool SignatureValid();
|
|
|
|
void Relay();
|
|
|
|
|
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
//for propagating messages
|
|
|
|
template <typename Stream, typename Operation>
|
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
|
|
|
//for syncing with other clients
|
|
|
|
READWRITE(LIMITED_STRING(strBudgetName, 20));
|
|
|
|
READWRITE(vin);
|
|
|
|
READWRITE(nBlockStart);
|
|
|
|
READWRITE(vecProposals);
|
|
|
|
READWRITE(vchSig);
|
2015-06-24 01:44:31 +02:00
|
|
|
}
|
2015-05-04 17:04:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// CFinalizedBudgetVote - Allow a masternode node to vote and broadcast throughout the network
|
|
|
|
//
|
|
|
|
|
|
|
|
class CFinalizedBudgetVote
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CTxIn vin;
|
|
|
|
uint256 nBudgetHash;
|
|
|
|
int64_t nTime;
|
|
|
|
std::vector<unsigned char> vchSig;
|
|
|
|
|
|
|
|
CFinalizedBudgetVote();
|
|
|
|
CFinalizedBudgetVote(CTxIn vinIn, uint256 nBudgetHashIn);
|
|
|
|
|
|
|
|
bool Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode);
|
|
|
|
bool SignatureValid();
|
|
|
|
void Relay();
|
|
|
|
|
|
|
|
uint256 GetHash(){
|
2015-06-09 18:37:58 +02:00
|
|
|
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
|
|
|
|
ss << vin;
|
|
|
|
ss << nBudgetHash;
|
|
|
|
ss << nTime;
|
|
|
|
return ss.GetHash();
|
2015-05-04 17:04:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
|
|
|
READWRITE(vin);
|
|
|
|
READWRITE(nBudgetHash);
|
|
|
|
READWRITE(nTime);
|
|
|
|
READWRITE(vchSig);
|
|
|
|
}
|
2015-07-04 07:05:10 +02:00
|
|
|
|
2015-05-04 17:04:09 +02:00
|
|
|
};
|
2015-04-22 16:33:44 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Budget Proposal : Contains the masternode votes for each budget
|
|
|
|
//
|
|
|
|
|
|
|
|
class CBudgetProposal
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
// critical section to protect the inner data structures
|
2015-04-30 19:11:34 +02:00
|
|
|
mutable CCriticalSection cs;
|
2015-04-22 16:33:44 +02:00
|
|
|
int64_t nAlloted;
|
|
|
|
|
|
|
|
public:
|
|
|
|
std::string strProposalName;
|
2015-06-24 01:44:31 +02:00
|
|
|
|
|
|
|
/*
|
2015-05-04 17:04:09 +02:00
|
|
|
json object with name, short-description, long-description, pdf-url and any other info
|
|
|
|
This allows the proposal website to stay 100% decentralized
|
|
|
|
*/
|
2015-06-24 01:44:31 +02:00
|
|
|
std::string strURL;
|
2015-05-04 17:04:09 +02:00
|
|
|
CTxIn vin;
|
|
|
|
int nBlockStart;
|
|
|
|
int nBlockEnd;
|
|
|
|
int64_t nAmount;
|
|
|
|
CScript address;
|
2015-06-16 19:04:35 +02:00
|
|
|
int64_t nTime;
|
2015-04-22 16:33:44 +02:00
|
|
|
|
|
|
|
map<uint256, CBudgetVote> mapVotes;
|
|
|
|
//cache object
|
|
|
|
|
2015-06-24 01:44:31 +02:00
|
|
|
CBudgetProposal();
|
2015-04-30 19:11:34 +02:00
|
|
|
CBudgetProposal(const CBudgetProposal& other);
|
2015-05-04 17:04:09 +02:00
|
|
|
CBudgetProposal(CTxIn vinIn, std::string strProposalNameIn, std::string strURLIn, int nBlockStartIn, int nBlockEndIn, CScript addressIn, CAmount nAmountIn);
|
2015-04-22 16:33:44 +02:00
|
|
|
|
|
|
|
void Calculate();
|
|
|
|
void AddOrUpdateVote(CBudgetVote& vote);
|
|
|
|
bool HasMinimumRequiredSupport();
|
|
|
|
std::pair<std::string, std::string> GetVotes();
|
|
|
|
|
2015-06-16 19:04:35 +02:00
|
|
|
bool IsValid(std::string& strError);
|
2015-05-04 17:04:09 +02:00
|
|
|
|
|
|
|
std::string GetName() {return strProposalName; }
|
|
|
|
std::string GetURL() {return strURL; }
|
|
|
|
int GetBlockStart() {return nBlockStart;}
|
|
|
|
int GetBlockEnd() {return nBlockEnd;}
|
|
|
|
CScript GetPayee() {return address;}
|
2015-05-27 19:11:00 +02:00
|
|
|
int GetTotalPaymentCount();
|
|
|
|
int GetRemainingPaymentCount();
|
2015-05-04 17:04:09 +02:00
|
|
|
int GetBlockStartCycle();
|
|
|
|
int GetBlockCurrentCycle();
|
|
|
|
int GetBlockEndCycle();
|
2015-04-22 16:33:44 +02:00
|
|
|
double GetRatio();
|
|
|
|
int GetYeas();
|
|
|
|
int GetNays();
|
|
|
|
int GetAbstains();
|
2015-05-04 17:04:09 +02:00
|
|
|
int64_t GetAmount() {return nAmount;}
|
2015-04-22 16:33:44 +02:00
|
|
|
|
2015-04-30 21:54:34 +02:00
|
|
|
void SetAllotted(int64_t nAllotedIn) {nAlloted = nAllotedIn;}
|
|
|
|
int64_t GetAllotted() {return nAlloted;}
|
2015-04-22 16:33:44 +02:00
|
|
|
|
2015-07-04 16:49:49 +02:00
|
|
|
void CleanAndRemove();
|
|
|
|
|
2015-05-04 17:04:09 +02:00
|
|
|
uint256 GetHash(){
|
2015-06-24 01:44:31 +02:00
|
|
|
/*
|
2015-05-04 17:04:09 +02:00
|
|
|
vin is not included on purpose
|
2015-06-24 01:44:31 +02:00
|
|
|
- Any masternode can make a proposal and the hashes should match regardless of who made it.
|
|
|
|
- Someone could hyjack a new proposal by changing the vin and the signature check will fail.
|
|
|
|
However, the network will still propagate the correct version and the incorrect one will be rejected.
|
2015-05-04 17:04:09 +02:00
|
|
|
*/
|
2015-06-24 01:44:31 +02:00
|
|
|
|
2015-05-04 17:04:09 +02:00
|
|
|
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
|
|
|
|
ss << strProposalName;
|
|
|
|
ss << strURL;
|
|
|
|
ss << nBlockStart;
|
|
|
|
ss << nBlockEnd;
|
|
|
|
ss << nAmount;
|
|
|
|
ss << address;
|
|
|
|
uint256 h1 = ss.GetHash();
|
2015-06-24 01:44:31 +02:00
|
|
|
|
2015-05-04 17:04:09 +02:00
|
|
|
return h1;
|
|
|
|
}
|
|
|
|
|
2015-04-22 16:33:44 +02:00
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
2015-05-04 17:04:09 +02:00
|
|
|
//for syncing with other clients
|
|
|
|
READWRITE(LIMITED_STRING(strProposalName, 20));
|
|
|
|
READWRITE(LIMITED_STRING(strURL, 64));
|
|
|
|
READWRITE(vin);
|
|
|
|
READWRITE(nBlockStart);
|
|
|
|
READWRITE(nBlockEnd);
|
|
|
|
READWRITE(nAmount);
|
|
|
|
READWRITE(address);
|
2015-06-16 19:04:35 +02:00
|
|
|
READWRITE(nTime);
|
2015-05-04 17:04:09 +02:00
|
|
|
|
|
|
|
//for saving to the serialized db
|
2015-04-22 16:33:44 +02:00
|
|
|
READWRITE(mapVotes);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-05-04 17:04:09 +02:00
|
|
|
// Proposals are cast then sent to peers with this object, which leaves the votes out
|
|
|
|
class CBudgetProposalBroadcast : public CBudgetProposal
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
std::vector<unsigned char> vchSig;
|
2015-06-24 01:44:31 +02:00
|
|
|
|
2015-05-04 17:04:09 +02:00
|
|
|
public:
|
2015-07-04 16:49:49 +02:00
|
|
|
bool fInvalid;
|
2015-05-04 17:04:09 +02:00
|
|
|
CBudgetProposalBroadcast();
|
|
|
|
CBudgetProposalBroadcast(const CBudgetProposal& other);
|
|
|
|
CBudgetProposalBroadcast(CTxIn vinIn, std::string strProposalNameIn, std::string strURL, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nBlockStartIn);
|
|
|
|
|
|
|
|
bool Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode);
|
|
|
|
bool SignatureValid();
|
|
|
|
void Relay();
|
|
|
|
|
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
|
|
|
//for syncing with other clients
|
|
|
|
|
|
|
|
READWRITE(LIMITED_STRING(strProposalName, 20));
|
|
|
|
READWRITE(LIMITED_STRING(strURL, 64));
|
|
|
|
READWRITE(vin);
|
|
|
|
READWRITE(nBlockStart);
|
|
|
|
READWRITE(nBlockEnd);
|
|
|
|
READWRITE(nAmount);
|
|
|
|
READWRITE(address);
|
|
|
|
READWRITE(vchSig);
|
2015-06-24 01:44:31 +02:00
|
|
|
}
|
2015-05-04 17:04:09 +02:00
|
|
|
};
|
2015-04-22 16:33:44 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// CBudgetVote - Allow a masternode node to vote and broadcast throughout the network
|
|
|
|
//
|
|
|
|
|
|
|
|
class CBudgetVote
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CTxIn vin;
|
2015-05-04 17:04:09 +02:00
|
|
|
uint256 nProposalHash;
|
2015-04-22 16:33:44 +02:00
|
|
|
int nVote;
|
|
|
|
int64_t nTime;
|
|
|
|
std::vector<unsigned char> vchSig;
|
|
|
|
|
|
|
|
CBudgetVote();
|
2015-05-04 17:04:09 +02:00
|
|
|
CBudgetVote(CTxIn vin, uint256 nProposalHash, int nVoteIn);
|
2015-04-22 16:33:44 +02:00
|
|
|
|
2015-05-04 17:04:09 +02:00
|
|
|
bool Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode);
|
2015-04-22 16:33:44 +02:00
|
|
|
bool SignatureValid();
|
|
|
|
void Relay();
|
|
|
|
|
|
|
|
std::string GetVoteString() {
|
|
|
|
std::string ret = "ABSTAIN";
|
|
|
|
if(nVote == VOTE_YES) ret = "YES";
|
|
|
|
if(nVote == VOTE_NO) ret = "NO";
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint256 GetHash(){
|
2015-06-09 18:37:58 +02:00
|
|
|
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
|
|
|
|
ss << vin;
|
|
|
|
ss << nProposalHash;
|
|
|
|
ss << nVote;
|
|
|
|
ss << nTime;
|
|
|
|
return ss.GetHash();
|
2015-04-22 16:33:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
|
|
|
READWRITE(vin);
|
2015-05-04 17:04:09 +02:00
|
|
|
READWRITE(nProposalHash);
|
2015-04-22 16:33:44 +02:00
|
|
|
READWRITE(nVote);
|
|
|
|
READWRITE(nTime);
|
|
|
|
READWRITE(vchSig);
|
|
|
|
}
|
|
|
|
|
2015-06-24 01:44:31 +02:00
|
|
|
|
2015-04-22 16:33:44 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2015-06-03 17:42:37 +02:00
|
|
|
#endif
|