}
// Scan given coins set for kernel solution
-bool ScanForStakeKernelHash(MetaMap &mapMeta, KernelSearchSettings &settings, CoinsSet::value_type &kernelcoin, uint32_t &nTimeTx, uint32_t &nBlockTime, uint64_t &nKernelsTried, uint64_t &nCoinDaysTried)
+bool ScanForStakeKernelHash(MetaMap &mapMeta, uint32_t nBits, uint32_t nTime, uint32_t nSearchInterval, CoinsSet::value_type &kernelcoin, uint32_t &nTimeTx, uint32_t &nBlockTime, uint64_t &nKernelsTried, uint64_t &nCoinDaysTried)
{
uint256 hashProofOfStake = 0;
// Get coin
CoinsSet::value_type pcoin = meta_item->second.first.second;
- static int nMaxStakeSearchInterval = 60;
+ static unsigned int nMaxStakeSearchInterval = 60;
// only count coins meeting min age requirement
- if (nStakeMinAge + block.nTime > settings.nTime - nMaxStakeSearchInterval)
+ if (nStakeMinAge + block.nTime > nTime - nMaxStakeSearchInterval)
continue;
// Transaction offset inside block
uint32_t nTxOffset = txindex.pos.nTxPos - txindex.pos.nBlockPos;
// Current timestamp scanning interval
- unsigned int nCurrentSearchInterval = min((int64_t)settings.nSearchInterval, (int64_t)nMaxStakeSearchInterval);
+ unsigned int nCurrentSearchInterval = min(nSearchInterval, nMaxStakeSearchInterval);
nBlockTime = block.nTime;
CBigNum bnTargetPerCoinDay;
- bnTargetPerCoinDay.SetCompact(settings.nBits);
+ bnTargetPerCoinDay.SetCompact(nBits);
int64_t nValueIn = pcoin.first->vout[pcoin.second].nValue;
// Search backward in time from the given timestamp
// Stopping search in case of shutting down or cache invalidation
for (unsigned int n=0; n<nCurrentSearchInterval && fCoinsDataActual && !fShutdown; n++)
{
- nTimeTx = settings.nTime - n;
+ nTimeTx = nTime - n;
CBigNum bnCoinDayWeight = CBigNum(nValueIn) * GetWeight((int64_t)pcoin.first->nTime, (int64_t)nTimeTx) / COIN / (24 * 60 * 60);
CBigNum bnTargetProofOfStake = bnCoinDayWeight * bnTargetPerCoinDay;
// Sets hashProofOfStake on success return
bool CheckStakeKernelHash(unsigned int nBits, const CBlock& blockFrom, uint32_t nTxPrevOffset, const CTransaction& txPrev, const COutPoint& prevout, uint32_t nTimeTx, uint256& hashProofOfStake, uint256& targetProofOfStake, bool fPrintProofOfStake=false);
-// Coins scanning options
-typedef struct KernelSearchSettings {
- uint32_t nBits; // Packed difficulty
- uint32_t nTime; // Basic time
- uint32_t nOffset; // Offset inside CoinsSet (isn't used yet)
- uint32_t nLimit; // Coins to scan (isn't used yet)
- uint32_t nSearchInterval; // Number of seconds allowed to go into the past
-} KernelSearchSettings;
-
-typedef std::set<std::pair<const CWalletTx*,unsigned int> > CoinsSet;
-
-// Preloaded coins metadata
-// txid => ((txindex, (tx, vout.n)), (block, modifier))
-typedef std::map<std::pair<uint256, unsigned int>, std::pair<std::pair<CTxIndex, std::pair<const CWalletTx*,unsigned int> >, std::pair<CBlock, uint64_t> > > MetaMap;
-
// Scan given coins set for kernel solution
-bool ScanForStakeKernelHash(MetaMap &mapMeta, KernelSearchSettings &settings, CoinsSet::value_type &kernelcoin, uint32_t &nTimeTx, uint32_t &nBlockTime, uint64_t &nKernelsTried, uint64_t &nCoinDaysTried);
+bool ScanForStakeKernelHash(MetaMap &mapMeta, uint32_t nBits, uint32_t nTime, uint32_t nSearchInterval, CoinsSet::value_type &kernelcoin, uint32_t &nTimeTx, uint32_t &nBlockTime, uint64_t &nKernelsTried, uint64_t &nCoinDaysTried);
// Check kernel hash target and coinstake signature
// Sets hashProofOfStake on success return
if (IsProofOfStake())
return true;
- static int64_t nLastCoinStakeSearchTime = GetAdjustedTime(); // startup timestamp
+ static uint32_t nLastCoinStakeSearchTime = GetAdjustedTime(); // startup timestamp
CKey key;
CTransaction txCoinStake;
- int64_t nSearchTime = txCoinStake.nTime; // search to current time
+ uint32_t nSearchTime = txCoinStake.nTime; // search to current time
if (nSearchTime > nLastCoinStakeSearchTime)
{
extern unsigned int nTransactionsUpdated;
extern uint64_t nLastBlockTx;
extern uint64_t nLastBlockSize;
-extern int64_t nLastCoinStakeSearchInterval;
+extern uint32_t nLastCoinStakeSearchInterval;
extern const std::string strMessageMagic;
extern int64_t nTimeBestReceived;
extern CCriticalSection cs_setpwalletRegistered;
uint64_t nLastBlockTx = 0;
uint64_t nLastBlockSize = 0;
-int64_t nLastCoinStakeSearchInterval = 0;
+uint32_t nLastCoinStakeSearchInterval = 0;
// We want to sort transactions by priority and fee, so:
typedef boost::tuple<double, double, CTransaction*> TxPriority;
}
-bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int64_t nSearchInterval, CTransaction& txNew, CKey& key)
+bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, uint32_t nSearchInterval, CTransaction& txNew, CKey& key)
{
// The following combine threshold is important to security
// Should not be adjusted if you don't understand the consequences
int64_t nCredit = 0;
CScript scriptPubKeyKernel;
- KernelSearchSettings settings;
- settings.nBits = nBits;
- settings.nTime = txNew.nTime;
- settings.nOffset = 0;
- settings.nLimit = mapMeta.size();
- settings.nSearchInterval = nSearchInterval;
-
unsigned int nTimeTx, nBlockTime;
COutPoint prevoutStake;
CoinsSet::value_type kernelcoin;
- if (ScanForStakeKernelHash(mapMeta, settings, kernelcoin, nTimeTx, nBlockTime, nKernelsTried, nCoinDaysTried))
+ if (ScanForStakeKernelHash(mapMeta, nBits, txNew.nTime, nSearchInterval, kernelcoin, nTimeTx, nBlockTime, nKernelsTried, nCoinDaysTried))
{
// Found a kernel
if (fDebug && GetBoolArg("-printcoinstake"))
class COutput;
class CCoinControl;
+// Set of selected transactions
+typedef std::set<std::pair<const CWalletTx*,unsigned int> > CoinsSet;
+
+// Preloaded coins metadata
+// (txid, vout.n) => ((txindex, (tx, vout.n)), (block, modifier))
+typedef std::map<std::pair<uint256, unsigned int>, std::pair<std::pair<CTxIndex, std::pair<const CWalletTx*,unsigned int> >, std::pair<CBlock, uint64_t> > > MetaMap;
+
+
/** (client) version numbers for particular wallet features */
enum WalletFeature
{
void GetStakeStats(float &nKernelsRate, float &nCoinDaysRate);
void GetStakeWeightFromValue(const int64_t& nTime, const int64_t& nValue, uint64_t& nWeight);
- bool CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int64_t nSearchInterval, CTransaction& txNew, CKey& key);
+ bool CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, uint32_t nSearchInterval, CTransaction& txNew, CKey& key);
bool MergeCoins(const int64_t& nAmount, const int64_t& nMinValue, const int64_t& nMaxValue, std::list<uint256>& listMerged);
std::string SendMoney(CScript scriptPubKey, int64_t nValue, CWalletTx& wtxNew, bool fAskFee=false);