/
masternode-devbudget.cpp
68 lines (52 loc) · 2.01 KB
/
masternode-devbudget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) 2018 The Zest Foundation developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <masternode-devbudget.h>
CDevBudget devbudget;
void CDevBudget::PrepareBudget() {
CBitcoinAddress address;
if (Params().NetworkID() == CBaseChainParams::MAIN)
address = CBitcoinAddress("ZHyGD8z6vPbdPJrrz6AoYdE3LdZJCqwiTb");
else
address = CBitcoinAddress("zAmjFKyYP6pSuncbYX9XprpVp6AQrzgK83");
// Parse ZEST address
payee = GetScriptForDestination(address.Get());
nPercentage = 0.05;
LogPrintf("CDevBudget::PrepareBudget(): %s\n", address.ToString());
LogPrintf("CDevBudget::PrepareBudget(): %f\n", nPercentage);
}
bool CDevBudget::IsTransactionValid(const CTransaction& txNew, int nBlockHeight)
{
PrepareBudget();
bool found = false;
int i = 0;
BOOST_FOREACH (CTxOut out, txNew.vout) {
if (i > 0 && payee == out.scriptPubKey) {
CAmount budgetPayment = txNew.vout[i - 1].nValue * nPercentage;
if (out.nValue >= budgetPayment) {
found = true;
LogPrint("masternode", "CDevBudget::IsTransactionValid - Found valid Dev Budget Payment of %d\n", out.nValue);
}
}
i++;
}
if (!found) {
LogPrint("masternode", "CDevBudget::IsTransactionValid - Missing required payment\n");
}
return found;
}
void CDevBudget::FillBlockPayee(CMutableTransaction& txNew, int64_t nFees, bool fProofOfStake)
{
CBlockIndex* pindexPrev = chainActive.Tip();
if (!pindexPrev) return;
PrepareBudget();
unsigned int i = txNew.vout.size();
if (txNew.vout[i - 1].nValue > 0) {
CAmount budgetPayment = txNew.vout[i - 1].nValue * nPercentage;
txNew.vout.resize(i + 1);
txNew.vout[i].scriptPubKey = payee;
txNew.vout[i].nValue = budgetPayment;
//subtract budget payment from mn reward
txNew.vout[i - 1].nValue -= budgetPayment;
}
}