X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=blobdiff_plain;f=src%2Fwallet.cpp;h=e49c2150e6265664992eca6de199d399f69bd45d;hp=998857777fdd5be2ec9cc1f5374f2121bd6f1a13;hb=16163ca1b076ee1e6e2c99cc67695e6e654a3293;hpb=5d2c41f9d678971c9b6fff9de6348a56d925720a diff --git a/src/wallet.cpp b/src/wallet.cpp index 9988577..e49c215 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -9,6 +9,7 @@ #include "ui_interface.h" #include "base58.h" #include "kernel.h" +#include using namespace std; extern int nStakeMaxAge; @@ -501,6 +502,16 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn) // Notify UI of new or updated transaction NotifyTransactionChanged(this, hash, fInsertedNew ? CT_NEW : CT_UPDATED); + + // notify an external script when a wallet transaction comes in or is updated + std::string strCmd = GetArg("-walletnotify", ""); + + if ( !strCmd.empty()) + { + boost::replace_all(strCmd, "%s", wtxIn.GetHash().GetHex()); + boost::thread t(runCommand, strCmd); // thread runs free + } + } return true; } @@ -1357,8 +1368,8 @@ bool CWallet::CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& w return CreateTransaction(vecSend, wtxNew, reservekey, nFeeRet); } -// NovaCoin: get current stake generation power -uint64 CWallet::GetStakeMintPower(const CKeyStore& keystore, enum StakeWeightMode mode) +// NovaCoin: get current stake weight +uint64 CWallet::GetStakeWeight(const CKeyStore& keystore, enum StakeWeightMode mode) { LOCK2(cs_main, cs_wallet); @@ -1369,7 +1380,7 @@ uint64 CWallet::GetStakeMintPower(const CKeyStore& keystore, enum StakeWeightMod if (mapArgs.count("-reservebalance") && !ParseMoney(mapArgs["-reservebalance"], nReserveBalance)) { - error("CreateCoinStake : invalid reserve balance amount"); + error("GetStakeWeight : invalid reserve balance amount"); return 0; } @@ -1391,41 +1402,53 @@ uint64 CWallet::GetStakeMintPower(const CKeyStore& keystore, enum StakeWeightMod if (!txdb.ReadTxIndex(pcoin.first->GetHash(), txindex)) continue; + unsigned int nTime = pcoin.first->nTime; + switch(mode) { case STAKE_NORMAL: // Do not count input that is still less than 30 days old - if (pcoin.first->nTime + nStakeMinAge > GetTime()) + if (nTime + nStakeMinAge > GetTime()) continue; break; case STAKE_MAXWEIGHT: // Do not count input that is still less than 90 days old - if (pcoin.first->nTime + nStakeMaxAge > GetTime()) + if (nTime + nStakeMaxAge > GetTime()) continue; break; case STAKE_MINWEIGHT: // Count only inputs with suitable age (from 30 to 90 days old) - if (pcoin.first->nTime + nStakeMaxAge < GetTime()) + if (nTime + nStakeMaxAge < GetTime()) continue; - if (pcoin.first->nTime + nStakeMinAge > GetTime()) - continue; - break; - case STAKE_BELOWMIN: - // Count only inputs with suitable age (less than 30 days old) - if (pcoin.first->nTime + nStakeMinAge < GetTime()) + if (nTime + nStakeMinAge > GetTime()) continue; break; } - CBigNum bnCentSecond = CBigNum(pcoin.first->vout[pcoin.second].nValue) * (GetTime()-pcoin.first->nTime) / CENT; - CBigNum bnCoinDay = bnCentSecond * CENT / COIN / (24 * 60 * 60); + int64 nTimeWeight; + // Kernel hash weight starts from 0 at the 30-day min age + // this change increases active coins participating the hash and helps + // to secure the network when proof-of-stake difficulty is low + // + if(fTestNet || (STAKEWEIGHT_SWITCH_TIME < nTime)) + { + // New rule since 01 Jan 2014: Maximum TimeWeight is 90 days. + nTimeWeight = min((int64)GetTime() - nTime - nStakeMinAge, (int64)nStakeMaxAge); + } + else + { + // Current rule: Maximum TimeWeight is 60 days. + nTimeWeight = min((int64)GetTime() - nTime, (int64)nStakeMaxAge) - nStakeMinAge; + } + + CBigNum bnCoinDayWeight = CBigNum(pcoin.first->vout[pcoin.second].nValue) * nTimeWeight / COIN / (24 * 60 * 60); - nCoinAge += bnCoinDay.getuint64(); + nCoinAge += bnCoinDayWeight.getuint64(); } if (fDebug && GetBoolArg("-printcoinage")) - printf("StakePower bnCoinDay=%"PRI64d"\n", nCoinAge); + printf("StakeWeight bnCoinDay=%"PRI64d"\n", nCoinAge); return nCoinAge; } @@ -1857,7 +1880,7 @@ bool CWallet::NewKeyPool() return true; } -bool CWallet::TopUpKeyPool() +bool CWallet::TopUpKeyPool(unsigned int nSize) { { LOCK(cs_wallet); @@ -1868,7 +1891,12 @@ bool CWallet::TopUpKeyPool() CWalletDB walletdb(strWalletFile); // Top up key pool - unsigned int nTargetSize = max(GetArg("-keypool", 100), 0LL); + unsigned int nTargetSize; + if (nSize > 0) + nTargetSize = nSize; + else + nTargetSize = max(GetArg("-keypool", 100), 0LL); + while (setKeyPool.size() < (nTargetSize + 1)) { int64 nEnd = 1;