diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 5b6d0f4cd..986d8366c 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2183,7 +2183,7 @@ CAmount CWallet::GetAvailableBalance(const CCoinControl* coinControl) const return balance; } -void CWallet::AvailableCoins(std::vector &vCoins, bool fOnlySafe, const CCoinControl *coinControl, const CAmount &nMinimumAmount, const CAmount &nMaximumAmount, const CAmount &nMinimumSumAmount, const uint64_t nMaximumCount, const int nMinDepth, const int nMaxDepth) const +void CWallet::AvailableCoins(std::vector &vCoins, bool fOnlySafe, const CCoinControl *coinControl, const CAmount &nMinimumAmount, const CAmount &nMaximumAmount, const CAmount &nMinimumSumAmount, const uint64_t nMaximumCount, const int nMinDepth, const int nMaxDepth, const std::string* kevaNamespace) const { vCoins.clear(); @@ -2272,12 +2272,23 @@ void CWallet::AvailableCoins(std::vector &vCoins, bool fOnlySafe, const } bool fSpendableIn = ((mine & ISMINE_SPENDABLE) != ISMINE_NO) || (coinControl && coinControl->fAllowWatchOnly && (mine & ISMINE_WATCH_SOLVABLE) != ISMINE_NO); - if (CKevaScript::isKevaScript(pcoin->tx->vout[i].scriptPubKey)) { - fSpendableIn = false; - } bool fSolvableIn = (mine & (ISMINE_SPENDABLE | ISMINE_WATCH_SOLVABLE)) != ISMINE_NO; - vCoins.push_back(COutput(pcoin, i, nDepth, fSpendableIn, fSolvableIn, safeTx)); + CKevaScript kevaOp(pcoin->tx->vout[i].scriptPubKey); + if (kevaOp.isKevaOp()) { + if (kevaNamespace) { + if (*kevaNamespace == EncodeBase58(kevaOp.getOpNamespace())) { + vCoins.push_back(COutput(pcoin, i, nDepth, fSpendableIn, fSolvableIn, safeTx)); + return; + } + } else { + fSpendableIn = false; + } + } + + if (!kevaNamespace) { + vCoins.push_back(COutput(pcoin, i, nDepth, fSpendableIn, fSolvableIn, safeTx)); + } // Checks the sum amount of all UTXO's. if (nMinimumSumAmount != MAX_MONEY) { @@ -2297,6 +2308,16 @@ void CWallet::AvailableCoins(std::vector &vCoins, bool fOnlySafe, const } } +bool CWallet::FindKevaCoin(COutput& vCoin, const std::string& kevaNamespace) { + std::vector vCoins; + AvailableCoins(vCoins, true, nullptr, 1, MAX_MONEY, MAX_MONEY, 0, 0, 9999999, &kevaNamespace); + if (vCoins.size() > 0) { + vCoin = vCoins[0]; + return true; + } + return false; +} + std::map> CWallet::ListCoins() const { // TODO: Add AssertLockHeld(cs_wallet) here. diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 814f38a39..a703356d5 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -543,6 +543,8 @@ public: */ bool fSafe; + COutput() : tx(nullptr) {} + COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn, bool fSolvableIn, bool fSafeIn) { tx = txIn; i = iIn; nDepth = nDepthIn; fSpendable = fSpendableIn; fSolvable = fSolvableIn; fSafe = fSafeIn; @@ -851,7 +853,12 @@ public: /** * populate vCoins with vector of available COutputs. */ - void AvailableCoins(std::vector& vCoins, bool fOnlySafe=true, const CCoinControl *coinControl = nullptr, const CAmount& nMinimumAmount = 1, const CAmount& nMaximumAmount = MAX_MONEY, const CAmount& nMinimumSumAmount = MAX_MONEY, const uint64_t nMaximumCount = 0, const int nMinDepth = 0, const int nMaxDepth = 9999999) const; + void AvailableCoins(std::vector& vCoins, bool fOnlySafe=true, const CCoinControl *coinControl = nullptr, const CAmount& nMinimumAmount = 1, const CAmount& nMaximumAmount = MAX_MONEY, const CAmount& nMinimumSumAmount = MAX_MONEY, const uint64_t nMaximumCount = 0, const int nMinDepth = 0, const int nMaxDepth = 9999999, const std::string* kevaNamespace = nullptr) const; + + /** + * Find a keva coin that has the given namespace. + */ + bool FindKevaCoin(COutput& vCoin, const std::string& kevaNamespace); /** * Return list of available coins and locked coins grouped by non-change output address.