9 #include "validation.h"
26 const std::vector<CTxBudgetPayment>& vecBudgetPaymentsIn,
33 nBlockStart(blockstart),
34 vecBudgetPayments(vecBudgetPaymentsIn),
35 nFeeTXHash(nfeetxhash),
48 }
catch (std::exception& e) {
49 return error(
"Unable to deserialize finalized budget broadcast: %s", e.what());
57 const int64_t voteTime = vote.
GetTime();
58 std::string strAction =
"New vote inserted:";
61 const int64_t oldTime =
mapVotes[mnId].GetTime();
62 if (oldTime > voteTime) {
67 if (voteTime - oldTime < BUDGET_VOTE_UPDATE_MIN) {
68 strError =
strprintf(
"time between votes is too soon - %s - %lli sec < %lli sec\n",
73 strAction =
"Existing vote updated:";
105 if (mapWinningProposals.empty()) {
122 for (
const auto& it: mapWinningProposals) {
129 const auto& it = mapWinningProposals.find(p.nProposalHash);
130 if (it == mapWinningProposals.end()) {
156 ret += vecBudgetPayment.nAmount;
164 std::vector<uint256> vHashes;
166 vHashes.push_back(budgetPayment.nProposalHash);
201 strInvalid =
"Invalid budget payments count (too many)";
212 strInvalid =
"Invalid Payout (more than max)";
234 strInvalid =
strprintf(
"(ends at block %ld) too old and obsolete (current %ld)", nBlockEnd, nCurrentHeight);
263 if (it.second.IsValid()) {
272 std::vector<uint256> vRet;
274 vRet.push_back(it.second.GetHash());
282 int nPaidBlockHeight = 0;
285 for(
auto it = mapPayment_History.begin(); it != mapPayment_History.end(); ) {
286 nPaidBlockHeight = (*it).second.second;
288 nOldProposalHash = (*it).first;
290 __func__, nOldProposalHash.
ToString().c_str(), nPaidBlockHeight);
291 it = mapPayment_History.erase(it);
298 if(mapPayment_History.count(nProposalHash) == 0) {
300 mapPayment_History.emplace(std::piecewise_construct,
301 std::forward_as_tuple(nProposalHash),
302 std::forward_as_tuple(nBlockHash, nBlockHeight));
304 __func__, nProposalHash.
ToString(), nBlockHeight, nBlockHash.
ToString(), mapPayment_History.size());
308 const uint256& nPaidBlockHash = mapPayment_History.at(nProposalHash).first;
312 if (nBlockHash != nPaidBlockHash) {
325 if (nBlockHeight > nBlockEnd) {
334 const int nCurrentBudgetPayment = nBlockHeight -
nBlockStart;
343 LogPrint(
BCLog::MNBUDGET,
"%s: Double Budget Payment of %d for proposal %d detected. Paying a masternode instead.\n",
354 for (
auto out = txNew.
vout.rbegin(); out != txNew.
vout.rend(); ++out) {
355 LogPrint(
BCLog::MNBUDGET,
"%s: nCurrentBudgetPayment=%d, payee=%s == out.scriptPubKey=%s, amount=%ld == out.nValue=%ld\n",
356 __func__, nCurrentBudgetPayment,
HexStr(scriptExpected),
HexStr(out->scriptPubKey), amountExpected, out->nValue);
357 if (scriptExpected == out->scriptPubKey && amountExpected == out->nValue) {
360 __func__, amountExpected,
vecBudgetPayments[nCurrentBudgetPayment].nProposalHash.GetHex());
376 if (i < 0)
return false;
385 if (i < 0)
return false;
412 return count > otherCount;
int64_t CAmount
Amount in PIV (Can be negative)
arith_uint256 UintToArith256(const uint256 &a)
const CChainParams & Params()
Return the currently selected parameters.
std::string ToStringShort() const
void reserve(size_type n)
The block chain is a tree shaped structure starting with the genesis block at the root,...
CAmount GetAmount() const
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
bool GetPayeeAndAmount(int64_t nBlockHeight, CScript &payee, CAmount &nAmount) const
static constexpr unsigned int MAX_PROPOSALS_PER_CYCLE
bool GetBudgetPaymentByBlock(int64_t nBlockHeight, CTxBudgetPayment &payment) const
bool UpdateValid(int nHeight)
std::vector< CTxBudgetPayment > vecBudgetPayments
void SetSynced(bool synced)
const uint256 & GetFeeTXHash() const
bool IsPaidAlready(const uint256 &nProposalHash, const uint256 &nBlockHash, int nBlockHeight) const
bool CheckAmount(const CAmount &nTotalBudget)
bool updateExpired(int nCurrentHeight)
bool AddOrUpdateVote(const CFinalizedBudgetVote &vote, std::string &strError)
TrxValidationStatus IsTransactionValid(const CTransaction &txNew, const uint256 &nBlockHash, int nBlockHeight) const
bool ParseBroadcast(CDataStream &broadcast)
void SyncVotes(CNode *pfrom, bool fPartial, int &nInvCount) const
bool CheckProposals(const std::map< uint256, CBudgetProposal > &mapWinningProposals) const
std::map< COutPoint, CFinalizedBudgetVote > mapVotes
bool operator>(const CFinalizedBudget &other) const
bool IsWellFormed(const CAmount &nTotalBudget)
std::vector< uint256 > GetVotesHashes() const
std::string strBudgetName
CDataStream GetBroadcast() const
CAmount GetTotalPayout() const
std::vector< uint256 > GetProposalsHashes() const
UniValue GetVotesObject() const
int GetBlockStart() const
void SetSynced(bool _fSynced)
Information about a peer.
void PushInventory(const CInv &inv)
An outpoint - a combination of a transaction hash and an index n into its vout.
Serialized script, used inside transaction inputs and outputs.
The basic transaction that is broadcasted on the network and contained in blocks.
std::vector< CTxOut > vout
bool pushKV(const std::string &key, const UniValue &val)
std::string ToString() const
@ Valid
Transaction verification failed.
@ DoublePayment
Transaction successfully verified.
std::unique_ptr< CConnman > g_connman
#define LogPrint(category,...)
std::string EncodeDestination(const CWDestination &address, const CChainParams::Base58Type addrType)
RecursiveMutex cs_main
Global state.
@ MSG_BUDGET_FINALIZED_VOTE
#define LIMITED_STRING(obj, n)
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet, bool fColdStake)
Parse a standard scriptPubKey for the destination address.
boost::variant< CNoDestination, CKeyID, CScriptID, CExchangeKeyID > CTxDestination
A txout script template with a specific destination.
bool error(const char *fmt, const Args &... args)
const uint256 UINT256_ZERO
constant uint256 instances
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
CBlockIndex * LookupBlockIndex(const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)