Commit 1cce0c22 authored by Pavel Vasin's avatar Pavel Vasin

wallet: remove pre protocol v3 code

parent b483606c
......@@ -1119,7 +1119,7 @@ void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed, const
}
}
void CWallet::AvailableCoinsForStaking(vector<COutput>& vCoins, unsigned int nSpendTime) const
void CWallet::AvailableCoinsForStaking(vector<COutput>& vCoins) const
{
vCoins.clear();
......@@ -1133,17 +1133,8 @@ void CWallet::AvailableCoinsForStaking(vector<COutput>& vCoins, unsigned int nSp
if (nDepth < 1)
continue;
if (IsProtocolV3(nSpendTime))
{
if (nDepth < nStakeMinConfirmations)
continue;
}
else
{
// Filtering by tx timestamp instead of block timestamp may give false positives but never false negatives
if (pcoin->nTime + nStakeMinAge > nSpendTime)
continue;
}
if (nDepth < nStakeMinConfirmations)
continue;
if (pcoin->GetBlocksToMaturity() > 0)
continue;
......@@ -1354,10 +1345,10 @@ bool CWallet::SelectCoins(int64_t nTargetValue, unsigned int nSpendTime, set<pai
}
// Select some coins without random shuffle or best subset approximation
bool CWallet::SelectCoinsForStaking(int64_t nTargetValue, unsigned int nSpendTime, set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet) const
bool CWallet::SelectCoinsForStaking(int64_t nTargetValue, set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet) const
{
vector<COutput> vCoins;
AvailableCoinsForStaking(vCoins, nSpendTime);
AvailableCoinsForStaking(vCoins);
setCoinsRet.clear();
nValueRet = 0;
......@@ -1552,7 +1543,7 @@ uint64_t CWallet::GetStakeWeight() const
set<pair<const CWalletTx*,unsigned int> > setCoins;
int64_t nValueIn = 0;
if (!SelectCoinsForStaking(nBalance - nReserveBalance, GetTime(), setCoins, nValueIn))
if (!SelectCoinsForStaking(nBalance - nReserveBalance, setCoins, nValueIn))
return 0;
if (setCoins.empty())
......@@ -1560,26 +1551,11 @@ uint64_t CWallet::GetStakeWeight() const
uint64_t nWeight = 0;
int64_t nCurrentTime = GetTime();
CTxDB txdb("r");
LOCK2(cs_main, cs_wallet);
BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins)
{
if (IsProtocolV3(nCurrentTime))
{
if (pcoin.first->GetDepthInMainChain() >= nStakeMinConfirmations)
nWeight += pcoin.first->vout[pcoin.second].nValue;
}
else
{
CTxIndex txindex;
if (!txdb.ReadTxIndex(pcoin.first->GetHash(), txindex))
continue;
if (nCurrentTime - pcoin.first->nTime > nStakeMinAge)
nWeight += pcoin.first->vout[pcoin.second].nValue;
}
if (pcoin.first->GetDepthInMainChain() >= nStakeMinConfirmations)
nWeight += pcoin.first->vout[pcoin.second].nValue;
}
return nWeight;
......@@ -1611,7 +1587,7 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
int64_t nValueIn = 0;
// Select coins with suitable depth
if (!SelectCoinsForStaking(nBalance - nReserveBalance, txNew.nTime, setCoins, nValueIn))
if (!SelectCoinsForStaking(nBalance - nReserveBalance, setCoins, nValueIn))
return false;
if (setCoins.empty())
......@@ -1704,8 +1680,6 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
if (txNew.vout.size() == 2 && ((pcoin.first->vout[pcoin.second].scriptPubKey == scriptPubKeyKernel || pcoin.first->vout[pcoin.second].scriptPubKey == txNew.vout[1].scriptPubKey))
&& pcoin.first->GetHash() != txNew.vin[0].prevout.hash)
{
int64_t nTimeWeight = GetWeight((int64_t)pcoin.first->nTime, (int64_t)txNew.nTime);
// Stop adding more inputs if already too many inputs
if (txNew.vin.size() >= 100)
break;
......@@ -1715,16 +1689,6 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
// Do not add additional significant input
if (pcoin.first->vout[pcoin.second].nValue >= GetStakeCombineThreshold())
continue;
// Do not add input that is still too young
if (IsProtocolV3(txNew.nTime))
{
// properly handled by selection function
}
else
{
if (nTimeWeight < nStakeMinAge)
continue;
}
txNew.vin.push_back(CTxIn(pcoin.first->GetHash(), pcoin.second));
nCredit += pcoin.first->vout[pcoin.second].nValue;
......@@ -1732,14 +1696,9 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
}
}
// Calculate coin age reward
// Calculate reward
{
uint64_t nCoinAge;
CTxDB txdb("r");
if (!txNew.GetCoinAge(txdb, pindexPrev, nCoinAge))
return error("CreateCoinStake : failed to calculate coin age");
int64_t nReward = GetProofOfStakeReward(pindexPrev, nCoinAge, nFees);
int64_t nReward = GetProofOfStakeReward(pindexPrev, 0, nFees);
if (nReward <= 0)
return false;
......
......@@ -78,7 +78,7 @@ public:
class CWallet : public CCryptoKeyStore, public CWalletInterface
{
private:
bool SelectCoinsForStaking(int64_t nTargetValue, unsigned int nSpendTime, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet) const;
bool SelectCoinsForStaking(int64_t nTargetValue, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet) const;
bool SelectCoins(int64_t nTargetValue, unsigned int nSpendTime, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet, const CCoinControl *coinControl=NULL) const;
CWalletDB *pwalletdbEncryption;
......@@ -142,7 +142,7 @@ public:
// check whether we are allowed to upgrade (or already support) to the named feature
bool CanSupportFeature(enum WalletFeature wf) { AssertLockHeld(cs_wallet); return nWalletMaxVersion >= wf; }
void AvailableCoinsForStaking(std::vector<COutput>& vCoins, unsigned int nSpendTime) const;
void AvailableCoinsForStaking(std::vector<COutput>& vCoins) const;
void AvailableCoins(std::vector<COutput>& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl=NULL) const;
bool SelectCoinsMinConf(int64_t nTargetValue, unsigned int nSpendTime, int nConfMine, int nConfTheirs, std::vector<COutput> vCoins, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet) const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment