diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 17ff8684dc..8a2ba4256d 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -42,7 +42,7 @@ qint64 WalletModel::getBalance(const CCoinControl *coinControl) const { int64 nBalance = 0; std::vector vCoins; - wallet->AvailableCoins(vCoins, true, coinControl); + wallet->AvailableCoins(vCoins, true, coinControl, ALL_COINS); BOOST_FOREACH(const COutput& out, vCoins) nBalance += out.tx->vout[out.i].nValue; @@ -199,8 +199,10 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(const QListCreateTransaction(vecSend, wtx, keyChange, nFeeRequired, strFailReason, coinControl, isDarkSend); + fCreated = wallet->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired, strFailReason, coinControl, act); if(!fCreated) { @@ -423,8 +425,9 @@ void WalletModel::getOutputs(const std::vector& vOutpoints, std::vect // AvailableCoins + LockedCoins grouped by wallet address (put change in one group with wallet address) void WalletModel::listCoins(std::map >& mapCoins) const { + CCoinControl *coinControl=NULL; std::vector vCoins; - wallet->AvailableCoins(vCoins); + wallet->AvailableCoins(vCoins, true, coinControl, ALL_COINS); std::vector vLockedCoins; wallet->ListLockedCoins(vLockedCoins); diff --git a/src/wallet.cpp b/src/wallet.cpp index 4d3a23bb2c..8ec3a737a3 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -965,7 +965,7 @@ int64 CWallet::GetImmatureBalance() const } // populate vCoins with vector of spendable COutputs -void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const CCoinControl *coinControl, bool onlyDarksendInputs) const +void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const CCoinControl *coinControl, AvailableCoinsType coin_type) const { vCoins.clear(); @@ -986,19 +986,21 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const for (unsigned int i = 0; i < pcoin->vout.size(); i++) { bool found = false; - if(onlyDarksendInputs) { + if(coin_type == ONLY_DENOMINATED) { //should make this a vector COutput out = COutput(pcoin, i, pcoin->GetDepthInMainChain()); CTxIn vin = CTxIn(out.tx->GetHash(), out.i); int rounds = darkSendPool.GetInputDarksendRounds(vin); if(rounds >= nDarksendRounds) found = true; - } else { + } else if(coin_type == ONLY_NONDENOMINATED) { found = true; BOOST_FOREACH(int64 d, darkSendDenominations) if(pcoin->vout[i].nValue == d) found = false; + } else { + found = true; } if(!found) continue; @@ -1208,10 +1210,10 @@ bool CWallet::SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfThe return true; } -bool CWallet::SelectCoins(int64 nTargetValue, set >& setCoinsRet, int64& nValueRet, const CCoinControl* coinControl, bool onlyDarksendInputs) const +bool CWallet::SelectCoins(int64 nTargetValue, set >& setCoinsRet, int64& nValueRet, const CCoinControl* coinControl, AvailableCoinsType coin_type) const { vector vCoins; - AvailableCoins(vCoins, true, coinControl, onlyDarksendInputs); + AvailableCoins(vCoins, true, coinControl, coin_type); // coin control -> return all selected outputs (we want all selected to go into the transaction for sure) if (coinControl && coinControl->HasSelected()) @@ -1269,7 +1271,7 @@ bool CWallet::SelectCoinsWithoutDenomination(int64 nTargetValue, set vCoins; - AvailableCoins(vCoins, true, coinControl, true); + AvailableCoins(vCoins, true, coinControl, ONLY_NONDENOMINATED); BOOST_FOREACH(const COutput& out, vCoins) { @@ -1298,7 +1300,7 @@ bool CWallet::SelectCoinsMoreThanOutput(int64 nTargetValue, CTxIn& vin, int64& n } bool CWallet::CreateTransaction(std::vector >& vecSend, - CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, std::string& strFailReason, const CCoinControl* coinControl, bool onlyDarkSendInputs) + CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, std::string& strFailReason, const CCoinControl* coinControl, AvailableCoinsType coin_type) { int64 nValue = 0; BOOST_FOREACH (PAIRTYPE(CScript, int64)& s, vecSend) @@ -1349,9 +1351,9 @@ bool CWallet::CreateTransaction(std::vector >& vecSend, // Choose coins to use set > setCoins; int64 nValueIn = 0; - if (!SelectCoins(nTotalValue, setCoins, nValueIn, coinControl, onlyDarkSendInputs)) + if (!SelectCoins(nTotalValue, setCoins, nValueIn, coinControl, coin_type)) { - if(!onlyDarkSendInputs) + if(coin_type == ALL_COINS || coin_type == ONLY_NONDENOMINATED) strFailReason = _("Insufficient funds"); else strFailReason = _("Unable to locate enough Darksend denominated funds for this transaction"); diff --git a/src/wallet.h b/src/wallet.h index e40a44e84c..b409817b71 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -35,6 +35,13 @@ enum WalletFeature FEATURE_LATEST = 60000 }; +enum AvailableCoinsType +{ + ALL_COINS = 1, + ONLY_DENOMINATED = 2, + ONLY_NONDENOMINATED = 3 +}; + /** A key pool entry */ class CKeyPool @@ -79,7 +86,7 @@ private: int nWalletMaxVersion; public: - bool SelectCoins(int64 nTargetValue, std::set >& setCoinsRet, int64& nValueRet, const CCoinControl *coinControl=NULL, bool onlyDarksendInputs=false) const; + bool SelectCoins(int64 nTargetValue, std::set >& setCoinsRet, int64& nValueRet, const CCoinControl *coinControl=NULL, AvailableCoinsType coin_type=ALL_COINS) const; bool SelectCoinsDark(int64 nValueMin, int64 nValueMax, std::vector& setCoinsRet, int64& nValueRet, int nDarksendRoundsMin, int nDarksendRoundsMax) const; bool SelectCoinsDarkDenominated(int64 nTargetValue, std::vector& setCoinsRet, int64& nValueRet) const; bool SelectCoinsExactOutput(int64 nTargetValue, CTxIn& vin, int64& nValueRet, CScript& pubScript, bool confirmed) const; @@ -132,7 +139,7 @@ public: // check whether we are allowed to upgrade (or already support) to the named feature bool CanSupportFeature(enum WalletFeature wf) { return nWalletMaxVersion >= wf; } std::string Denominate(CWalletTx& wtxDenominate); - void AvailableCoins(std::vector& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl=NULL, bool onlyDarksendInputs=false) const; + void AvailableCoins(std::vector& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl=NULL, AvailableCoinsType coin_type=ALL_COINS) const; void AvailableCoins2(std::vector& vCoins, bool fOnlyConfirmed) const; bool SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfTheirs, std::vector vCoins, std::set >& setCoinsRet, int64& nValueRet) const; bool IsLockedCoin(uint256 hash, unsigned int n) const; @@ -188,7 +195,7 @@ public: int64 GetUnconfirmedBalance() const; int64 GetImmatureBalance() const; bool CreateTransaction(std::vector >& vecSend, - CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, std::string& strFailReason, const CCoinControl *coinControl=NULL, bool onlyDarksendInputs=false); + CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, std::string& strFailReason, const CCoinControl *coinControl=NULL, AvailableCoinsType coin_type=ALL_COINS); bool CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, std::string& strFailReason, const CCoinControl *coinControl=NULL); bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey);