From e4e9712d088c766dca737f98d5df1eb2941da442 Mon Sep 17 00:00:00 2001 From: furszy Date: Sat, 31 Oct 2020 22:43:54 -0300 Subject: [PATCH] wallet:AvailableCoins fOnlySpendable filtering flag implemented + connected to sendmany async operation. --- src/wallet/asyncrpcoperation_sendmany.cpp | 7 ++----- src/wallet/wallet.cpp | 15 +++++++++++---- src/wallet/wallet.h | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/wallet/asyncrpcoperation_sendmany.cpp b/src/wallet/asyncrpcoperation_sendmany.cpp index 924dab219..4fdf39e53 100644 --- a/src/wallet/asyncrpcoperation_sendmany.cpp +++ b/src/wallet/asyncrpcoperation_sendmany.cpp @@ -900,12 +900,9 @@ bool AsyncRPCOperation_sendmany::find_utxos(bool fAcceptCoinbase=false) { LOCK2(cs_main, pwalletMain->cs_wallet); - pwalletMain->AvailableCoins(vecOutputs, false, NULL, true, fAcceptCoinbase); + pwalletMain->AvailableCoins(vecOutputs, false, NULL, true, fAcceptCoinbase, true); - BOOST_FOREACH(const COutput& out, vecOutputs) { - if (!out.fSpendable) { - continue; - } + for (const COutput& out : vecOutputs) { if (out.nDepth < mindepth_) { continue; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 5298b2ab7..efa882412 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3209,7 +3209,7 @@ CAmount CWallet::GetImmatureWatchOnlyBalance() const return nTotal; } -void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const CCoinControl *coinControl, bool fIncludeZeroValue, bool fIncludeCoinBase) const +void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const CCoinControl *coinControl, bool fIncludeZeroValue, bool fIncludeCoinBase, bool fOnlySpendable) const { vCoins.clear(); @@ -3237,13 +3237,20 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const continue; for (unsigned int i = 0; i < pcoin->vout.size(); i++) { + const auto& output = pcoin->vout[i]; + isminetype mine = IsMine(output); + + bool isSpendable = ((mine & ISMINE_SPENDABLE) != ISMINE_NO) || + (coinControl && coinControl->fAllowWatchOnly && (mine & ISMINE_WATCH_SOLVABLE) != ISMINE_NO); + + if (fOnlySpendable && !isSpendable) + continue; + isminetype mine = IsMine(pcoin->vout[i]); if (!(IsSpent(wtxid, i)) && mine != ISMINE_NO && !IsLockedCoin((*it).first, i) && (pcoin->vout[i].nValue > 0 || fIncludeZeroValue) && (!coinControl || !coinControl->HasSelected() || coinControl->fAllowOtherInputs || coinControl->IsSelected((*it).first, i))) - vCoins.push_back(COutput(pcoin, i, nDepth, - ((mine & ISMINE_SPENDABLE) != ISMINE_NO) || - (coinControl && coinControl->fAllowWatchOnly && (mine & ISMINE_WATCH_SOLVABLE) != ISMINE_NO))); + vCoins.push_back(COutput(pcoin, i, nDepth, isSpendable)); } } } diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index d65e94e6b..c5b253698 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1010,7 +1010,7 @@ public: /** * populate vCoins with vector of available COutputs. */ - void AvailableCoins(std::vector& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl = NULL, bool fIncludeZeroValue=false, bool fIncludeCoinBase=true) const; + void AvailableCoins(std::vector& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl = NULL, bool fIncludeZeroValue=false, bool fIncludeCoinBase=true, bool fOnlySpendable=false) const; /** * Shuffle and select coins until nTargetValue is reached while avoiding