1 #include "kernelrecord.h"
9 bool KernelRecord::showTransaction(const CWalletTx &wtx)
13 if (wtx.GetDepthInMainChain() < 2)
28 * Decompose CWallet transaction to model kernel records.
30 vector<KernelRecord> KernelRecord::decomposeOutput(const CWallet *wallet, const CWalletTx &wtx)
32 vector<KernelRecord> parts;
33 int64 nTime = wtx.GetTxTime();
34 uint256 hash = wtx.GetHash();
35 std::map<std::string, std::string> mapValue = wtx.mapValue;
36 int64 nDayWeight = (min((GetAdjustedTime() - nTime), (int64)(nStakeMaxAge+nStakeMinAge)) - nStakeMinAge); // DayWeight * 86400, чтобы был
37 // правильный расчёт CoinAge
38 if (showTransaction(wtx))
40 for (unsigned int nOut = 0; nOut < wtx.vout.size(); nOut++)
42 CTxOut txOut = wtx.vout[nOut];
43 if( wallet->IsMine(txOut) ) {
44 CTxDestination address;
47 uint64 coinAge = max( (txOut.nValue * nDayWeight) / (COIN * 86400), (int64)0);
49 if (ExtractDestination(txOut.scriptPubKey, address))
51 // Sent to Bitcoin Address
52 addrStr = CBitcoinAddress(address).ToString();
56 // Sent to IP, or other non-address transaction like OP_EVAL
57 addrStr = mapValue["to"];
60 parts.push_back(KernelRecord(hash, nTime, addrStr, txOut.nValue, wtx.IsSpent(nOut), coinAge));
68 std::string KernelRecord::getTxID()
70 return hash.ToString() + strprintf("-%03d", idx);
73 int64 KernelRecord::getAge() const
75 return (GetAdjustedTime() - nTime) / 86400;
78 uint64 KernelRecord::getCoinDay() const
80 int64 nWeight = GetAdjustedTime() - nTime - nStakeMinAge;
83 nWeight = min(nWeight, (int64)nStakeMaxAge);
84 uint64 coinAge = (nValue * nWeight ) / (COIN * 86400);
88 int64 KernelRecord::getPoSReward(int nBits, int minutes)
91 int64 nWeight = GetAdjustedTime() - nTime + minutes * 60;
92 if( nWeight < nStakeMinAge)
94 uint64 coinAge = (nValue * nWeight ) / (COIN * 86400);
95 PoSReward = GetProofOfStakeReward(coinAge, nBits, GetAdjustedTime() + minutes * 60);
99 double KernelRecord::getProbToMintStake(double difficulty, int timeOffset) const
101 //double maxTarget = pow(static_cast<double>(2), 224);
102 //double target = maxTarget / difficulty;
103 //int dayWeight = (min((GetAdjustedTime() - nTime) + timeOffset, (int64)(nStakeMinAge+nStakeMaxAge)) - nStakeMinAge) / 86400;
104 //uint64 coinAge = max(nValue * dayWeight / COIN, (int64)0);
105 //return target * coinAge / pow(static_cast<double>(2), 256);
106 int Weight = (min((GetAdjustedTime() - nTime) + timeOffset, (int64)(nStakeMinAge+nStakeMaxAge)) - nStakeMinAge);
107 uint64 coinAge = max(nValue * Weight / (COIN * 86400), (int64)0);
108 return coinAge / (pow(static_cast<double>(2),32) * difficulty);
111 double KernelRecord::getProbToMintWithinNMinutes(double difficulty, int minutes)
113 if(difficulty != prevDifficulty || minutes != prevMinutes)
117 int d = minutes / (60 * 24); // Number of full days
118 int m = minutes % (60 * 24); // Number of minutes in the last day
121 // Probabilities for the first d days
122 for(i = 0; i < d; i++)
124 timeOffset = i * 86400;
125 p = pow(1 - getProbToMintStake(difficulty, timeOffset), 86400);
129 // Probability for the m minutes of the last day
130 timeOffset = d * 86400;
131 p = pow(1 - getProbToMintStake(difficulty, timeOffset), 60 * m);
135 prevProbability = prob;
136 prevDifficulty = difficulty;
137 prevMinutes = minutes;
139 return prevProbability;