 |
PRCYCoin
2.0.0.7rc1
P2P Digital Currency
|
Go to the documentation of this file.
51 return error(
"%s : Failed to open file %s", __func__,
pathDB.string());
56 }
catch (
const std::exception& e) {
57 return error(
"%s : Serialize or I/O error - %s", __func__, e.what());
73 error(
"%s : Failed to open file %s", __func__,
pathDB.string());
78 int fileSize = fs::file_size(
pathDB);
79 int dataSize = fileSize -
sizeof(
uint256);
83 std::vector<unsigned char> vchData;
84 vchData.resize(dataSize);
89 filein.
read((
char*)&vchData[0], dataSize);
91 }
catch (
const std::exception& e) {
92 error(
"%s : Deserialize or I/O error - %s", __func__, e.what());
101 if (hashIn != hashTmp) {
102 error(
"%s : Checksum mismatch, data corrupted", __func__);
106 unsigned char pchMsgTmp[4];
107 std::string strMagicMessageTmp;
110 ssObj >> strMagicMessageTmp;
114 error(
"%s : Invalid masternode payement cache magic message", __func__);
123 if (memcmp(pchMsgTmp,
Params().MessageStart(),
sizeof(pchMsgTmp))) {
124 error(
"%s : Invalid network magic number", __func__);
130 }
catch (
const std::exception& e) {
132 error(
"%s : Deserialize or I/O error - %s", __func__, e.what());
191 return nMinted <= nExpectedValue;
217 if (!pindexPrev)
return false;
230 if (!pindexPrev)
return false;
232 bool hasPayment =
true;
233 std::vector<unsigned char> payeeAddr;
235 CKey mnPaymentPrivTx;
245 std::string mnsa(payeeAddr.begin(), payeeAddr.end());
248 CPubKey pubViewKey, pubSpendKey, des;
252 throw std::runtime_error(
"Stealth address mal-formatted");
269 unsigned int i = txNew.
vout.size();
273 txNew.
vout.resize(i + 1);
274 txNew.
vout[i].scriptPubKey = payee;
275 txNew.
vout[i].nValue = masternodePayment;
276 txNew.
vout[i].masternodeStealthAddress = payeeAddr;
277 std::copy(mnPaymentPrivTx.
begin(), mnPaymentPrivTx.
end(), std::back_inserter(txNew.
vout[i].txPriv));
278 std::copy(mnPaymentPubTx.
begin(), mnPaymentPubTx.
end(), std::back_inserter(txNew.
vout[i].txPub));
280 txNew.
vout[i - 1].nValue -= masternodePayment;
282 txNew.
vout.resize(2);
283 txNew.
vout[1].scriptPubKey = payee;
284 txNew.
vout[1].nValue = masternodePayment;
285 txNew.
vout[0].nValue = posBlockReward - masternodePayment;
309 vRecv >> nCountNeeded;
313 LogPrintf(
"CMasternodePayments::ProcessMessageMasternodePayments() : mnget - peer already asked me for the list\n");
344 if (winner.nBlockHeight < nFirstBlock || winner.nBlockHeight > nHeight + 20) {
345 LogPrint(
BCLog::MASTERNODE,
"mnw - winner out of range - FirstBlock %d Height %d bestHeight %d\n", nFirstBlock, winner.nBlockHeight, nHeight);
349 std::string strError =
"";
350 if (!winner.IsValid(pfrom, strError)) {
358 if (!winner.SignatureValid()) {
360 LogPrintf(
"CMasternodePayments::ProcessMessageMasternodePayments() : mnw - invalid signature\n");
378 std::string strError =
"";
379 std::string strMasterNodeSignMessage;
381 std::string payeeString(
payee.begin(),
payee.end());
383 std::string strMessage =
HEX_STR(ser);
420 std::vector<unsigned char> mnpayee;
423 std::vector<unsigned char> payee;
424 for (int64_t h = nHeight; h <= nHeight + 8; h++) {
425 if (h == nNotBlockHeight)
continue;
428 if (mnpayee == payee) {
469 int nMaxSignatures = 0;
470 int nMasternode_Drift_Count = 0;
472 std::string strPayeesPossible =
"";
480 nMaxSignatures = payee.nVotes;
489 if (out.
nValue >= requiredMasternodePayment)
497 if (found)
return true;
499 std::string address2(payee.masternodeStealthAddress.begin(), payee.masternodeStealthAddress.end());
501 if (strPayeesPossible ==
"") {
502 strPayeesPossible += address2;
504 strPayeesPossible +=
"," + address2;
508 LogPrint(
BCLog::MASTERNODE,
"CMasternodePayments::IsTransactionValid - Missing required payment of %s to %s\n",
FormatMoney(requiredMasternodePayment).c_str(), strPayeesPossible.c_str());
516 std::string ret =
"Unknown";
520 std::string paymentAddress(payee.masternodeStealthAddress.begin(), payee.masternodeStealthAddress.end());
522 if (ret !=
"Unknown") {
523 ret +=
", " + paymentAddress +
":" + std::to_string(payee.nVotes);
525 ret = paymentAddress +
":" + std::to_string(payee.nVotes);
566 int nLimit = std::max(
int(
mnodeman.
size() * 1.25), 1000);
662 std::string errorMessage;
671 if (newWinner.
Sign(keyMasternode, pubKeyMasternode)) {
694 std::string strMessage =
HEX_STR(ser);
696 std::string strError =
"";
719 if (nCountNeeded > nCount) nCountNeeded = nCount;
736 std::ostringstream info;
748 int nOldestBlock = std::numeric_limits<int>::max();
752 if ((*it).first < nOldestBlock) {
753 nOldestBlock = (*it).first;
766 int nNewestBlock = 0;
770 if ((*it).first > nNewestBlock) {
771 nNewestBlock = (*it).first;
bool HasFulfilledRequest(std::string strRequest)
bool IsBlockValueValid(int nHeight, CAmount nExpectedValue, CAmount nMinted)
void AskForMN(CNode *pnode, CTxIn &vin)
Ask (source) node for mnb.
int CountEnabled(int protocolVersion=-1)
CAutoFile & read(char *pch, size_t nSize)
CActiveMasternode activeMasternode
Keep track of the active Masternode.
int GetMinMasternodePaymentsProto()
int GetMasternodeRank(const CTxIn &vin, int64_t nBlockHeight, int minProtocol=0, bool fOnlyActive=true)
bool CanVote(COutPoint outMasternode, int nBlockHeight)
bool Write(const CMasternodePayments &objToSave)
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
ReadResult Read(CMasternodePayments &objToLoad, bool fDryRun=false)
FILE * fopen(const fs::path &p, const char *mode)
void Sync(CNode *node, int nCountNeeded)
const_iterator begin() const
bool GetBlockPayee(int nBlockHeight, std::vector< unsigned char > &payee)
std::string GetRequiredPaymentsString(int nBlockHeight)
CChain chainActive
The currently-connected chain of blocks.
CScript GetScriptForDestination(const CTxDestination &dest)
bool IsBlockPayeeValid(const CBlock &block, int nBlockHeight)
base58-encoded PRCY addresses.
void DumpMasternodePayments()
CMasternode * Find(const CScript &payee)
Find an entry.
bool IsBlockchainSynced()
std::string strMagicMessage
int nHeight
height of the entry in the chain. The genesis block has height 0
bool IsValid(CNode *pnode, std::string &strError)
Information about a peer.
bool ProcessBlock(int nBlockHeight)
std::map< uint256, CMasternodePaymentWinner > mapMasternodePayeeVotes
void PushInventory(const CInv &inv)
int size()
Return the number of (unique) Masternodes.
void AddPayee(std::vector< unsigned char > payeeIn)
CMasternode * GetNextMasternodeInQueueForPayment(int nBlockHeight, bool fFilterSigTime, int &nCount)
Find an entry in the masternode list that is next to be paid.
std::vector< CMasternodePayee > vecPayments
Save Masternode Payment Data (mnpayments.dat)
#define TRY_LOCK(cs, name)
bool Sign(CKey &keyMasternode, CPubKey &pubKeyMasternode)
std::string FormatMoney(const CAmount &n, bool fPlus)
Money parsing/formatting utilities.
static bool VerifyMessage(const CPubKey &pubkey, const std::vector< unsigned char > &vchSig, const std::string &strMessage, std::string &strErrorRet)
Verify the message signature, returns true if succcessful.
std::string ToString() const
const char * MNWINNER
The mnwinner message is used to relay and distribute consensus for masternode payout ordering.
void PushMessage(const char *pszCommand)
std::vector< unsigned char > masternodeStealthAddress
The basic transaction that is broadcasted on the network and contained in blocks.
const unsigned char * end() const
static bool SignMessage(const std::string &strMessage, std::vector< unsigned char > &vchSigRet, const CKey &key)
Sign the message, returns true if successful.
CMasternodeSync masternodeSync
Non-refcounted RAII wrapper for FILE*.
std::string strMasterNodePrivKey
const unsigned char * begin() const
RecursiveMutex cs_main
Global state.
const unsigned char * begin() const
void FulfilledRequest(std::string strRequest)
int ActiveProtocol()
See whether the protocol update is enforced for connected nodes.
static bool ComputeStealthDestination(const CKey &secret, const CPubKey &pubViewKey, const CPubKey &pubSpendKey, CPubKey &des)
std::string GetRequiredPaymentsString(int nBlockHeight)
bool IsBudgetPaymentBlock(int nBlockHeight)
CMasternodeMan mnodeman
Masternode manager.
bool IsTransactionValid(const CTransaction &txNew)
An output of a transaction.
std::vector< unsigned char > payee
std::vector< CTxOut > vout
bool FillBlockPayee(CMutableTransaction &txNew, int64_t nFees, bool fProofOfStake)
bool GetBlockHash(uint256 &hash, int nBlockHeight)
const unsigned char * end() const
std::string GetRequiredPaymentsString()
int LAST_POW_BLOCK() const
const_iterator end() const
int64_t CAmount
Amount in PRCY (Can be negative)
const char * GETMNWINNERS
The getmnwinners message is used to request winning masternode data from connected peers.
CMasternodePayments masternodePayments
Object for who's going to get paid on which blocks.
void AddedMasternodeWinner(uint256 hash)
bool IsNull() const
Return true if the wrapped FILE* is NULL, false otherwise.
std::vector< unsigned char > masternodeStealthAddress
int64_t GetMasternodePayment(int nHeight, int64_t blockValue, int nMasternodeCount)
256-bit unsigned big integer.
#define HEX_DATA_STREAM_PROTOCOL(protocolVersion)
CPubKey GetPubKey() const
Compute the public key from a private key.
#define LogPrint(category,...)
CMasternode * GetCurrentMasterNode(int mod=1, int64_t nBlockHeight=0, int minProtocol=0)
Get the current winner for this block.
Serialized script, used inside transaction inputs and outputs.
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
#define MASTERNODE_SYNC_MNW
#define MNPAYMENTS_SIGNATURES_REQUIRED
std::map< int, CMasternodeBlockPayees > mapMasternodeBlocks
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
static bool GetKeysFromSecret(const std::string &strSecret, CKey &keyRet, CPubKey &pubkeyRet)
Set the private/public key values, returns true if successful.
std::vector< CTransaction > vtx
std::vector< CTxOut > vout
static bool DecodeStealthAddress(const std::string &stealth, CPubKey &pubViewKey, CPubKey &pubSpendKey, bool &hasPaymentID, uint64_t &paymentID)
An encapsulated public key.
std::string ToString() const
#define MNPAYMENTS_SIGNATURES_TOTAL
An encapsulated private key.
int GetBudgetPaymentCycleBlocks()
std::string ToString() const
const fs::path & GetDataDir(bool fNetSpecific)
const CChainParams & Params()
Return the currently selected parameters.
bool IsTransactionValid(const CTransaction &txNew, int nBlockHeight)
const char * SYNCSTATUSCOUNT
The syncstatuscount message is used to track the layer 2 syncing process.
CAmount GetBlockValue(int nHeight)
Double ended buffer combining vector and stream-like interfaces.
RecursiveMutex cs_mapMasternodePayeeVotes
RecursiveMutex cs_vecPayments
CBlockIndex * Tip(bool fProofOfStake=false) const
Returns the index entry for the tip of this chain, or NULL if none.
std::string Hash(std::string input)
Compute the 256-bit hash of a std::string.
A mutable version of CTransaction.
The block chain is a tree shaped structure starting with the genesis block at the root,...
bool IsScheduled(CMasternode &mn, int nNotBlockHeight)
RecursiveMutex cs_mapMasternodeBlocks
std::vector< unsigned char > vchSig
bool AddWinningMasternode(CMasternodePaymentWinner &winner)
CPubKey pubKeyCollateralAddress
bool FillBlockPayee(CMutableTransaction &txNew, CAmount nFees, bool fProofOfStake)
bool error(const char *fmt, const Args &... args)
std::string ToString() const
int MasternodeCountDrift() const
The masternode count that we will allow the see-saw reward payments to be off by.
std::map< uint256, int > mapSeenSyncMNW
std::string ToString() const
void Misbehaving(NodeId pnode, int howmuch) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Increase a node's misbehavior score.
void ProcessMessageMasternodePayments(CNode *pfrom, std::string &strCommand, CDataStream &vRecv)