From a59e3ae3d38be4ee1c196e6ca0766f3feff0da4d Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Tue, 3 Feb 2015 12:55:25 +0300 Subject: [PATCH 1/2] every ds related function should ignore ix depth and use blockchain depth instead --- src/wallet.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/wallet.cpp b/src/wallet.cpp index b66e75f73..3ebe3aa53 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1096,7 +1096,7 @@ int64_t CWallet::GetAnonymizedBalance() const if (pcoin->IsTrusted()){ for (unsigned int i = 0; i < pcoin->vout.size(); i++) { - COutput out = COutput(pcoin, i, pcoin->GetDepthInMainChain()); + COutput out = COutput(pcoin, i, pcoin->GetDepthInMainChain(false)); CTxIn vin = CTxIn(out.tx->GetHash(), out.i); if(IsSpent(out.tx->GetHash(), i) || !IsMine(pcoin->vout[i]) || !IsDenominated(vin)) continue; @@ -1126,7 +1126,7 @@ double CWallet::GetAverageAnonymizedRounds() const for (unsigned int i = 0; i < pcoin->vout.size(); i++) { - COutput out = COutput(pcoin, i, pcoin->GetDepthInMainChain()); + COutput out = COutput(pcoin, i, pcoin->GetDepthInMainChain(false)); CTxIn vin = CTxIn(out.tx->GetHash(), out.i); if(IsSpent(out.tx->GetHash(), i) || !IsMine(pcoin->vout[i]) || !IsDenominated(vin)) continue; @@ -1154,7 +1154,7 @@ int64_t CWallet::GetNormalizedAnonymizedBalance() const const CWalletTx* pcoin = &(*it).second; for (unsigned int i = 0; i < pcoin->vout.size(); i++) { - COutput out = COutput(pcoin, i, pcoin->GetDepthInMainChain()); + COutput out = COutput(pcoin, i, pcoin->GetDepthInMainChain(false)); CTxIn vin = CTxIn(out.tx->GetHash(), out.i); if(IsSpent(out.tx->GetHash(), i) || !IsMine(pcoin->vout[i]) || !IsDenominated(vin)) continue; @@ -1179,10 +1179,10 @@ int64_t CWallet::GetDenominatedBalance(bool onlyDenom, bool onlyUnconfirmed) con for (unsigned int i = 0; i < pcoin->vout.size(); i++) { - COutput out = COutput(pcoin, i, pcoin->GetDepthInMainChain()); + COutput out = COutput(pcoin, i, pcoin->GetDepthInMainChain(false)); CTxIn vin = CTxIn(out.tx->GetHash(), out.i); - bool unconfirmed = (!IsFinalTx(*pcoin) || (!pcoin->IsTrusted() && pcoin->GetDepthInMainChain() == 0)); + bool unconfirmed = (!IsFinalTx(*pcoin) || (!pcoin->IsTrusted() && pcoin->GetDepthInMainChain(false) == 0)); if(IsSpent(out.tx->GetHash(), i)) continue; if(!IsMine(pcoin->vout[i])) continue; From 0ca6b1c91c396fa25e224e259922283571605659 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Tue, 3 Feb 2015 23:25:00 +0300 Subject: [PATCH 2/2] do not use IX coins until we have at least 1 blockchain confirmation --- src/wallet.cpp | 14 +++++++------- src/wallet.h | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/wallet.cpp b/src/wallet.cpp index 3ebe3aa53..e10e467ae 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1229,7 +1229,7 @@ int64_t CWallet::GetImmatureBalance() const } // populate vCoins with vector of spendable COutputs -void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const CCoinControl *coinControl, AvailableCoinsType coin_type, int minimum_confirmations) const +void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const CCoinControl *coinControl, AvailableCoinsType coin_type, bool useIX) const { vCoins.clear(); @@ -1250,7 +1250,8 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const continue; int nDepth = pcoin->GetDepthInMainChain(false); - if (nDepth <= minimum_confirmations) + // do not use IX coins until we have at least 1 blockchain confirmation + if (useIX && nDepth < 1) continue; for (unsigned int i = 0; i < pcoin->vout.size(); i++) { @@ -1466,10 +1467,10 @@ bool CWallet::SelectCoinsMinConf(int64_t nTargetValue, int nConfMine, int nConfT return true; } -bool CWallet::SelectCoins(int64_t nTargetValue, set >& setCoinsRet, int64_t& nValueRet, const CCoinControl* coinControl, AvailableCoinsType coin_type, int minimum_confirmations) const +bool CWallet::SelectCoins(int64_t nTargetValue, set >& setCoinsRet, int64_t& nValueRet, const CCoinControl* coinControl, AvailableCoinsType coin_type, bool useIX) const { vector vCoins; - AvailableCoins(vCoins, true, coinControl, ALL_COINS, minimum_confirmations); + AvailableCoins(vCoins, true, coinControl, ALL_COINS, useIX); //if we're doing only denominated, we need to round up to the nearest .1DRK if(coin_type == ONLY_DENOMINATED){ @@ -1846,9 +1847,8 @@ bool CWallet::CreateTransaction(const vector >& vecSend, // Choose coins to use set > setCoins; int64_t nValueIn = 0; - int minconfirmations = 0; - if (useIX) minconfirmations = 5; - if (!SelectCoins(nTotalValue, setCoins, nValueIn, coinControl, coin_type, minconfirmations)) + + if (!SelectCoins(nTotalValue, setCoins, nValueIn, coinControl, coin_type, useIX)) { if(coin_type == ALL_COINS) strFailReason = _("Insufficient funds"); diff --git a/src/wallet.h b/src/wallet.h index 67670871c..3cb89e770 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -132,7 +132,7 @@ private: void SyncMetaData(std::pair); public: - bool SelectCoins(int64_t nTargetValue, std::set >& setCoinsRet, int64_t& nValueRet, const CCoinControl *coinControl = NULL, AvailableCoinsType coin_type=ALL_COINS, int minimum_confirmations=1) const; + bool SelectCoins(int64_t nTargetValue, std::set >& setCoinsRet, int64_t& nValueRet, const CCoinControl *coinControl = NULL, AvailableCoinsType coin_type=ALL_COINS, bool useIX = true) const; bool SelectCoinsDark(int64_t nValueMin, int64_t nValueMax, std::vector& setCoinsRet, int64_t& nValueRet, int nDarksendRoundsMin, int nDarksendRoundsMax) const; bool SelectCoinsByDenominations(int nDenom, int64_t nValueMin, int64_t nValueMax, std::vector& setCoinsRet, vector& vCoins, int64_t& nValueRet, int nDarksendRoundsMin, int nDarksendRoundsMax); bool SelectCoinsDarkDenominated(int64_t nTargetValue, std::vector& setCoinsRet, int64_t& nValueRet) const; @@ -206,7 +206,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 AvailableCoins(std::vector& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl = NULL, AvailableCoinsType coin_type=ALL_COINS, int minimum_confirmations=1) const; + void AvailableCoins(std::vector& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl = NULL, AvailableCoinsType coin_type=ALL_COINS, bool useIX = false) const; bool SelectCoinsMinConf(int64_t nTargetValue, int nConfMine, int nConfTheirs, std::vector vCoins, std::set >& setCoinsRet, int64_t& nValueRet) const; bool IsSpent(const uint256& hash, unsigned int n) const;