From 879527c9516e78bb51f2efe2ab9758f38bd40dae Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 15 Jun 2013 20:24:16 +0400 Subject: [PATCH] Add stakepower into getmininginfo output (EXPERIMENTAL) --- src/rpcmining.cpp | 1 + src/wallet.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/wallet.h | 3 +++ 3 files changed, 50 insertions(+), 0 deletions(-) diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 3b22686..c5ccea2 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -25,6 +25,7 @@ Value getmininginfo(const Array& params, bool fHelp) obj.push_back(Pair("difficulty", (double)GetDifficulty())); obj.push_back(Pair("errors", GetWarnings("statusbar"))); obj.push_back(Pair("pooledtx", (uint64_t)mempool.size())); + obj.push_back(Pair("stakepower", (uint64_t)pwalletMain->GetStakeMintPower(*pwalletMain))); obj.push_back(Pair("testnet", fTestNet)); return obj; } diff --git a/src/wallet.cpp b/src/wallet.cpp index 580edf5..613edc2 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1338,6 +1338,52 @@ 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) +{ + LOCK2(cs_main, cs_wallet); + + // Choose coins to use + int64 nBalance = GetBalance(); + int64 nReserveBalance = 0; + uint64 nCoinAge = 0; + + if (mapArgs.count("-reservebalance") && !ParseMoney(mapArgs["-reservebalance"], nReserveBalance)) + { + error("CreateCoinStake : invalid reserve balance amount"); + return 0; + } + + if (nBalance <= nReserveBalance) + return 0; + + set > setCoins; + vector vwtxPrev; + int64 nValueIn = 0; + if (!SelectCoins(nBalance - nReserveBalance, GetTime(), setCoins, nValueIn)) + return 0; + if (setCoins.empty()) + return 0; + + BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins) + { + CTxDB txdb("r"); + CTxIndex txindex; + if (!txdb.ReadTxIndex(pcoin.first->GetHash(), txindex)) + continue; + + // Do not count input that is still too young + if (pcoin.first->nTime + nStakeMaxAge > GetTime()) + continue; + + uint64 unCoinAge; + pcoin.first->GetCoinAge(txdb, unCoinAge); + nCoinAge += unCoinAge; + } + + return nCoinAge; +} + // ppcoin: create coin stake transaction bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int64 nSearchInterval, CTransaction& txNew) { diff --git a/src/wallet.h b/src/wallet.h index 7f848f6..ca43104 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -177,7 +177,10 @@ public: bool CreateTransaction(const std::vector >& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet); bool CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet); bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey); + + uint64 GetStakeMintPower(const CKeyStore& keystore); bool CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int64 nSearchInterval, CTransaction& txNew); + std::string SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false); std::string SendMoneyToDestination(const CTxDestination &address, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false); -- 1.7.1