1 #include "kernelrecord.h"
8 bool KernelRecord::showTransaction(const CWalletTx &wtx)
12 if (wtx.GetDepthInMainChain() < 2)
27 * Decompose CWallet transaction to model kernel records.
29 vector<KernelRecord> KernelRecord::decomposeOutput(const CWallet *wallet, const CWalletTx &wtx)
31 vector<KernelRecord> parts;
32 int64_t nTime = wtx.GetTxTime();
33 uint256 hash = wtx.GetHash();
34 std::map<std::string, std::string> mapValue = wtx.mapValue;
35 if (showTransaction(wtx))
37 for (unsigned int nOut = 0; nOut < wtx.vout.size(); nOut++)
39 CTxOut txOut = wtx.vout[nOut];
40 if( wallet->IsMine(txOut) ) {
41 CTxDestination address;
44 if (ExtractDestination(txOut.scriptPubKey, address))
46 // Sent to Bitcoin Address
47 addrStr = CBitcoinAddress(address).ToString();
51 // Sent to IP, or other non-address transaction like OP_EVAL
52 addrStr = mapValue["to"];
55 parts.push_back(KernelRecord(hash, nTime, addrStr, txOut.nValue, wtx.IsSpent(nOut)));
63 std::string KernelRecord::getTxID()
65 return hash.ToString() + strprintf("-%03d", idx);
68 int64_t KernelRecord::getAge() const
70 return (GetAdjustedTime() - nTime) / nOneDay;
73 uint64_t KernelRecord::getCoinDay() const
75 int64_t nWeight = GetAdjustedTime() - nTime - nStakeMinAge;
78 nWeight = min(nWeight, (int64_t)nStakeMaxAge);
79 uint64_t coinAge = (nValue * nWeight ) / (COIN * nOneDay);
83 int64_t KernelRecord::getPoSReward(int nBits, int minutes)
86 int64_t nWeight = GetAdjustedTime() - nTime + minutes * 60;
87 if( nWeight < nStakeMinAge)
89 uint64_t coinAge = (nValue * nWeight ) / (COIN * nOneDay);
90 PoSReward = GetProofOfStakeReward(coinAge, nBits, GetAdjustedTime() + minutes * 60);
94 double KernelRecord::getProbToMintStake(double difficulty, int timeOffset) const
96 //double maxTarget = pow(static_cast<double>(2), 224);
97 //double target = maxTarget / difficulty;
98 //int dayWeight = (min((GetAdjustedTime() - nTime) + timeOffset, (int64_t)(nStakeMinAge+nStakeMaxAge)) - nStakeMinAge) / 86400;
99 //uint64_t coinAge = max(nValue * dayWeight / COIN, (int64_t)0);
100 //return target * coinAge / pow(static_cast<double>(2), 256);
101 int64_t Weight = (min((GetAdjustedTime() - nTime) + timeOffset, (int64_t)(nStakeMinAge+nStakeMaxAge)) - nStakeMinAge);
102 uint64_t coinAge = max(nValue * Weight / (COIN * nOneDay), (int64_t)0);
103 return coinAge / (pow(static_cast<double>(2),32) * difficulty);
106 double KernelRecord::getProbToMintWithinNMinutes(double difficulty, int minutes)
108 if(difficulty != prevDifficulty || minutes != prevMinutes)
112 int d = minutes / (60 * 24); // Number of full days
113 int m = minutes % (60 * 24); // Number of minutes in the last day
116 // Probabilities for the first d days
117 for(i = 0; i < d; i++)
119 timeOffset = i * nOneDay;
120 p = pow(1 - getProbToMintStake(difficulty, timeOffset), nOneDay);
124 // Probability for the m minutes of the last day
125 timeOffset = d * nOneDay;
126 p = pow(1 - getProbToMintStake(difficulty, timeOffset), 60 * m);
130 prevProbability = prob;
131 prevDifficulty = difficulty;
132 prevMinutes = minutes;
134 return prevProbability;