X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fwallet.cpp;h=613edc29e15fbc7c344be116b0a7ac7ab5bb51fb;hb=879527c9516e78bb51f2efe2ab9758f38bd40dae;hp=580edf519759e1939540421b46089064568c8ef8;hpb=726b753c71c1ec24fd0f55a7badef4ef5a00769a;p=novacoin.git 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) {