X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=blobdiff_plain;f=src%2Fkernel.cpp;h=c4283edbbc23022fb36e9492cee335452105adf2;hp=18db341bc1b2a4fd92c429a8893a3d5b56388149;hb=ca78b9e6a859e32fbe36e7afb12c9c9403e8a5b0;hpb=f5875a9a87b3341857381e847703cc4ae4890737 diff --git a/src/kernel.cpp b/src/kernel.cpp index 18db341..c4283ed 100644 --- a/src/kernel.cpp +++ b/src/kernel.cpp @@ -390,27 +390,22 @@ bool CheckStakeKernelHash(unsigned int nBits, const CBlock& blockFrom, unsigned } // Scan given coins set for kernel solution -bool ScanForStakeKernelHash(CoinsSet &setCoins, MetaMap &mapMeta, KernelSearchSettings &settings, CoinsSet::value_type &kernelcoin, unsigned int &nTimeTx, unsigned int &nBlockTime) +bool ScanForStakeKernelHash(MetaMap &mapMeta, KernelSearchSettings &settings, CoinsSet::value_type &kernelcoin, unsigned int &nTimeTx, unsigned int &nBlockTime) { uint256 hashProofOfStake = 0; - for(CoinsSet::const_iterator pcoin = setCoins.begin(); pcoin != setCoins.end(); pcoin++) + // txid => ((txindex, (tx, vout.n)), (block, modifier)) + for(MetaMap::const_iterator meta_item = mapMeta.begin(); meta_item != mapMeta.end(); meta_item++) { if (!fCoinsDataActual) break; - MetaMap::const_iterator mi = mapMeta.find(pcoin->first->GetHash()); - if (mi == mapMeta.end()) - { - if (fDebug) - printf("Unable to find %s in mapMeta, stopping\n", pcoin->first->GetHash().GetHex().c_str()); - fCoinsDataActual = false; - break; - } + CTxIndex txindex = (*meta_item).second.first.first; + CBlock block = (*meta_item).second.second.first; + uint64 nStakeModifier = (*meta_item).second.second.second; - CTxIndex txindex = (*mi).second.first; - CBlock block = (*mi).second.second.first; - uint64 nStakeModifier = (*mi).second.second.second; + // Get coin + CoinsSet::value_type pcoin = meta_item->second.first.second; static int nMaxStakeSearchInterval = 60; @@ -427,7 +422,7 @@ bool ScanForStakeKernelHash(CoinsSet &setCoins, MetaMap &mapMeta, KernelSearchSe nBlockTime = block.nTime; CBigNum bnTargetPerCoinDay; bnTargetPerCoinDay.SetCompact(settings.nBits); - int64 nValueIn = pcoin->first->vout[pcoin->second].nValue; + int64 nValueIn = pcoin.first->vout[pcoin.second].nValue; // Search backward in time from the given timestamp // Search nSearchInterval seconds back up to nMaxStakeSearchInterval @@ -435,13 +430,13 @@ bool ScanForStakeKernelHash(CoinsSet &setCoins, MetaMap &mapMeta, KernelSearchSe for (unsigned int n=0; nfirst->nTime, (int64)nTimeTx) / COIN / (24 * 60 * 60); + CBigNum bnCoinDayWeight = CBigNum(nValueIn) * GetWeight((int64)pcoin.first->nTime, (int64)nTimeTx) / COIN / (24 * 60 * 60); CBigNum bnTargetProofOfStake = bnCoinDayWeight * bnTargetPerCoinDay; // Build kernel CDataStream ss(SER_GETHASH, 0); ss << nStakeModifier; - ss << nBlockTime << nTxOffset << pcoin->first->nTime << pcoin->second << nTimeTx; + ss << nBlockTime << nTxOffset << pcoin.first->nTime << pcoin.second << nTimeTx; // Calculate kernel hash hashProofOfStake = Hash(ss.begin(), ss.end()); @@ -450,15 +445,15 @@ bool ScanForStakeKernelHash(CoinsSet &setCoins, MetaMap &mapMeta, KernelSearchSe { if (fDebug) printf("nStakeModifier=0x%016"PRI64x", nBlockTime=%u nTxOffset=%u nTxPrevTime=%u nVout=%u nTimeTx=%u hashProofOfStake=%s Success=true\n", - nStakeModifier, nBlockTime, nTxOffset, pcoin->first->nTime, pcoin->second, nTimeTx, hashProofOfStake.GetHex().c_str()); + nStakeModifier, nBlockTime, nTxOffset, pcoin.first->nTime, pcoin.second, nTimeTx, hashProofOfStake.GetHex().c_str()); - kernelcoin = *pcoin; + kernelcoin = pcoin; return true; } if (fDebug) printf("nStakeModifier=0x%016"PRI64x", nBlockTime=%u nTxOffset=%u nTxPrevTime=%u nTxNumber=%u nTimeTx=%u hashProofOfStake=%s Success=false\n", - nStakeModifier, nBlockTime, nTxOffset, pcoin->first->nTime, pcoin->second, nTimeTx, hashProofOfStake.GetHex().c_str()); + nStakeModifier, nBlockTime, nTxOffset, pcoin.first->nTime, pcoin.second, nTimeTx, hashProofOfStake.GetHex().c_str()); } }