diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 232ed49cbd98d..ce681222beaef 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -1044,19 +1044,16 @@ void WalletModel::listCoins(std::map>& void WalletModel::listAvailableNotes(std::map>& mapCoins) const { - std::vector notes; - Optional dummy = nullopt; - wallet->GetSaplingScriptPubKeyMan()->GetFilteredNotes(notes, dummy); - for (const auto& note : notes) { - ListCoinsKey key{QString::fromStdString(KeyIO::EncodePaymentAddress(note.address)), false, nullopt}; - ListCoinsValue value{ - note.op.hash, - (int)note.op.n, - (CAmount)note.note.value(), - 0, - note.confirmations - }; - mapCoins[key].emplace_back(value); + for (const auto& it: wallet->ListNotes()) { + const ListCoinsKey key{QString::fromStdString(KeyIO::EncodePaymentAddress(it.first)), false, nullopt}; + + for (const SaplingNoteEntry& note : it.second) { + mapCoins[key].emplace_back(note.op.hash, + (int)note.op.n, + (CAmount)note.note.value(), + 0, + note.confirmations); + } } } diff --git a/src/sapling/saplingscriptpubkeyman.cpp b/src/sapling/saplingscriptpubkeyman.cpp index 769cbd5f8bf63..0965c701de87f 100644 --- a/src/sapling/saplingscriptpubkeyman.cpp +++ b/src/sapling/saplingscriptpubkeyman.cpp @@ -511,6 +511,20 @@ void SaplingScriptPubKeyMan::GetFilteredNotes( } } +/* Return list of available notes grouped by sapling address. */ +std::map> SaplingScriptPubKeyMan::ListNotes() const +{ + std::vector notes; + Optional dummy = nullopt; + GetFilteredNotes(notes, dummy); + + std::map> result; + for (const auto& note : notes) { + result[note.address].emplace_back(std::move(note)); + } + return result; +} + Optional SaplingScriptPubKeyMan::GetAddressFromInputIfPossible(const uint256& txHash, int index) const { diff --git a/src/sapling/saplingscriptpubkeyman.h b/src/sapling/saplingscriptpubkeyman.h index 33d06f78ed2fc..600c8652a6ce6 100644 --- a/src/sapling/saplingscriptpubkeyman.h +++ b/src/sapling/saplingscriptpubkeyman.h @@ -297,6 +297,8 @@ class SaplingScriptPubKeyMan { bool requireSpendingKey=true, bool ignoreLocked=true) const; + /* Return list of available notes grouped by sapling address. */ + std::map> ListNotes() const; //! Return the address from where the shielded spend is taking the funds from (if possible) Optional GetAddressFromInputIfPossible(const CWalletTx* wtx, int index) const; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 65464565990d8..019bd3b66b8c5 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2999,6 +2999,11 @@ std::map>, std::vector> CWallet::ListNotes() const +{ + return m_sspk_man->ListNotes(); +} + bool CWallet::CreateBudgetFeeTX(CTransactionRef& tx, const uint256& hash, CReserveKey& keyChange, bool fFinalization) { CScript scriptChange; diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 80b5d0bc6244a..6ec22b45eeaa3 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -98,6 +98,7 @@ class CScheduler; class ScriptPubKeyMan; class SaplingScriptPubKeyMan; class SaplingNoteData; +struct SaplingNoteEntry; class CDeterministicMNList; /** (client) version numbers for particular wallet features */ @@ -816,6 +817,10 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface * is reserved for the staker address in case of P2CS. */ std::map>, std::vector> ListCoins() const; + /** + * Return list of available shield notes grouped by sapling address. + */ + std::map> ListNotes() const; /// Get 10000 PIV output and keys which can be used for the Masternode bool GetMasternodeVinAndKeys(CTxIn& txinRet, CPubKey& pubKeyRet,