From b1d701275a7fca4742cfcefba9d56722e457838b Mon Sep 17 00:00:00 2001 From: Evan Duffield Date: Sun, 1 Feb 2015 09:30:58 -0700 Subject: [PATCH] only use inputs with 5 confirmations for IX --- src/qt/walletmodel.cpp | 2 +- src/wallet.cpp | 14 ++++++++------ src/wallet.h | 6 +++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 83c76616d..cb99dae28 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -274,7 +274,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact act = ALL_COINS; } - bool fCreated = wallet->CreateTransaction(vecSend, *newTx, *keyChange, nFeeRequired, strFailReason, coinControl, act); + bool fCreated = wallet->CreateTransaction(vecSend, *newTx, *keyChange, nFeeRequired, strFailReason, coinControl, act, recipients[0].useInstantX); transaction.setTransactionFee(nFeeRequired); if(!fCreated) diff --git a/src/wallet.cpp b/src/wallet.cpp index 77d6e83bd..ae48a4e56 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) const +void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const CCoinControl *coinControl, AvailableCoinsType coin_type, int minimum_confirmations) const { vCoins.clear(); @@ -1250,7 +1250,7 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const continue; int nDepth = pcoin->GetDepthInMainChain(); - if (nDepth < 0) + if (nDepth < minimum_confirmations) continue; for (unsigned int i = 0; i < pcoin->vout.size(); i++) { @@ -1466,10 +1466,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) const +bool CWallet::SelectCoins(int64_t nTargetValue, set >& setCoinsRet, int64_t& nValueRet, const CCoinControl* coinControl, AvailableCoinsType coin_type, int minimum_confirmations) const { vector vCoins; - AvailableCoins(vCoins, true, coinControl); + AvailableCoins(vCoins, true, coinControl, ALL_COINS, minimum_confirmations); //if we're doing only denominated, we need to round up to the nearest .1DRK if(coin_type == ONLY_DENOMINATED){ @@ -1799,7 +1799,7 @@ bool CWallet::ConvertList(std::vector vCoins, std::vector& vecAm } bool CWallet::CreateTransaction(const vector >& vecSend, - CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, std::string& strFailReason, const CCoinControl* coinControl, AvailableCoinsType coin_type) + CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, std::string& strFailReason, const CCoinControl* coinControl, AvailableCoinsType coin_type, bool useIX) { int64_t nValue = 0; BOOST_FOREACH (const PAIRTYPE(CScript, int64_t)& s, vecSend) @@ -1846,7 +1846,9 @@ bool CWallet::CreateTransaction(const vector >& vecSend, // Choose coins to use set > setCoins; int64_t nValueIn = 0; - if (!SelectCoins(nTotalValue, setCoins, nValueIn, coinControl, coin_type)) + int minconfirmations = 0; + if (useIX) minconfirmations = 5; + if (!SelectCoins(nTotalValue, setCoins, nValueIn, coinControl, coin_type, minconfirmations)) { if(coin_type == ALL_COINS) strFailReason = _("Insufficient funds"); diff --git a/src/wallet.h b/src/wallet.h index 0e488c110..263a46c99 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) const; + 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 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) const; + void AvailableCoins(std::vector& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl = NULL, AvailableCoinsType coin_type=ALL_COINS, int minimum_confirmations=1) 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; @@ -283,7 +283,7 @@ public: int64_t GetDenominatedBalance(bool onlyDenom=true, bool onlyUnconfirmed=false) const; bool CreateTransaction(const std::vector >& vecSend, - CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, std::string& strFailReason, const CCoinControl *coinControl = NULL, AvailableCoinsType coin_type=ALL_COINS); + CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, std::string& strFailReason, const CCoinControl *coinControl = NULL, AvailableCoinsType coin_type=ALL_COINS, bool useIX=false); bool CreateTransaction(CScript scriptPubKey, int64_t nValue, CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, std::string& strFailReason, const CCoinControl *coinControl = NULL);