From: alexhz Date: Sat, 6 Jul 2013 16:20:55 +0000 (+0000) Subject: Improve getmininginfo X-Git-Tag: v0.4.4-pre~13 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=52c962024788db57a2fbd2c8d926cffec67e0c32 Improve getmininginfo --- diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 5ddb3e2..5a0d9ee 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -49,10 +49,13 @@ Value getmininginfo(const Array& params, bool fHelp) obj.push_back(Pair("difficulty", (double)GetDifficulty())); obj.push_back(Pair("blockvalue", (uint64_t)GetProofOfWorkReward(GetLastBlockIndex(pindexBest, false)->nBits))); obj.push_back(Pair("netmhashps", dNetworkMhps)); - obj.push_back(Pair("netstakeweight", nNetworkWeight)); + obj.push_back(Pair("netstakeweight", (uint64_t) nNetworkWeight)); obj.push_back(Pair("errors", GetWarnings("statusbar"))); obj.push_back(Pair("pooledtx", (uint64_t)mempool.size())); - obj.push_back(Pair("stakeweight", (uint64_t)pwalletMain->GetStakeMintPower(*pwalletMain))); + obj.push_back(Pair("stakeweight", (uint64_t)pwalletMain->GetStakeMintPower(*pwalletMain, STAKE_NORMAL))); + obj.push_back(Pair("minweight", (uint64_t)pwalletMain->GetStakeMintPower(*pwalletMain, STAKE_MINWEIGHT))); + obj.push_back(Pair("maxweight", (uint64_t)pwalletMain->GetStakeMintPower(*pwalletMain, STAKE_MAXWEIGHT))); + obj.push_back(Pair("passiveweight", (uint64_t)pwalletMain->GetStakeMintPower(*pwalletMain, STAKE_BELOWMIN))); obj.push_back(Pair("stakeinterest", (uint64_t)GetProofOfStakeReward(0, GetLastBlockIndex(pindexBest, true)->nBits, GetTime(), true))); obj.push_back(Pair("testnet", fTestNet)); return obj; diff --git a/src/wallet.cpp b/src/wallet.cpp index eb83806..2b5cfa2 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1339,7 +1339,7 @@ bool CWallet::CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& w } // NovaCoin: get current stake generation power -uint64 CWallet::GetStakeMintPower(const CKeyStore& keystore) +uint64 CWallet::GetStakeMintPower(const CKeyStore& keystore, enum StakeWeightMode mode) { LOCK2(cs_main, cs_wallet); @@ -1372,9 +1372,31 @@ uint64 CWallet::GetStakeMintPower(const CKeyStore& keystore) if (!txdb.ReadTxIndex(pcoin.first->GetHash(), txindex)) continue; - // Do not count input that is still too young - if (pcoin.first->nTime + nStakeMaxAge > GetTime()) - continue; + switch(mode) + { + case STAKE_NORMAL: + // Do not count input that is still less than 30 days old + if (pcoin.first->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()) + continue; + break; + case STAKE_MINWEIGHT: + // Count only inputs with suitable age (from 30 to 90 days old) + if (pcoin.first->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()) + continue; + break; + } CBigNum bnCentSecond = CBigNum(pcoin.first->vout[pcoin.second].nValue) * (GetTime()-pcoin.first->nTime) / CENT; CBigNum bnCoinDay = bnCentSecond * CENT / COIN / (24 * 60 * 60); diff --git a/src/wallet.h b/src/wallet.h index ca43104..17c54eb 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -35,6 +35,14 @@ enum WalletFeature FEATURE_LATEST = 60000 }; +/** Stake weight calculation mode */ +enum StakeWeightMode +{ + STAKE_NORMAL = 0, // all 30+ days old inputs + STAKE_MAXWEIGHT = 1, // only 90+ days old inputs + STAKE_MINWEIGHT = 3, // only [30-90] days old inputs + STAKE_BELOWMIN = 4 // only less than 30 days old inputs +}; /** A key pool entry */ class CKeyPool @@ -178,7 +186,7 @@ public: bool CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet); bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey); - uint64 GetStakeMintPower(const CKeyStore& keystore); + uint64 GetStakeMintPower(const CKeyStore& keystore, enum StakeWeightMode mode=STAKE_NORMAL); bool CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int64 nSearchInterval, CTransaction& txNew); std::string SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false);