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 (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 double KernelRecord::getProbToMintStake(double difficulty, int timeOffset) const
80 //double maxTarget = pow(static_cast<double>(2), 224);
81 //double target = maxTarget / difficulty;
82 //int dayWeight = (min((GetAdjustedTime() - nTime) + timeOffset, (int64)(nStakeMinAge+nStakeMaxAge)) - nStakeMinAge) / 86400;
83 //uint64 coinAge = max(nValue * dayWeight / COIN, (int64)0);
84 //return target * coinAge / pow(static_cast<double>(2), 256);
85 int Weight = (min((GetAdjustedTime() - nTime) + timeOffset, (int64)(nStakeMinAge+nStakeMaxAge)) - nStakeMinAge);
86 uint64 coinAge = max(nValue * Weight / (COIN * 86400), (int64)0);
87 return coinAge / (pow(static_cast<double>(2),32) * difficulty);
90 double KernelRecord::getProbToMintWithinNMinutes(double difficulty, int minutes)
92 if(difficulty != prevDifficulty || minutes != prevMinutes)
96 int d = minutes / (60 * 24); // Number of full days
97 int m = minutes % (60 * 24); // Number of minutes in the last day
100 // Probabilities for the first d days
101 for(i = 0; i < d; i++)
103 timeOffset = i * 86400;
104 p = pow(1 - getProbToMintStake(difficulty, timeOffset), 86400);
108 // Probability for the m minutes of the last day
109 timeOffset = d * 86400;
110 p = pow(1 - getProbToMintStake(difficulty, timeOffset), 60 * m);
114 prevProbability = prob;
115 prevDifficulty = difficulty;
116 prevMinutes = minutes;
118 return prevProbability;