From bdbe8e8591810ac84c266c0103a6302264d4cd32 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Mon, 11 Dec 2017 16:31:12 +0000 Subject: [PATCH] Extend CWallet::GetFilteredNotes to enable filtering on a set of addresses --- src/wallet/wallet.cpp | 25 +++++++++++++++++++------ src/wallet/wallet.h | 8 ++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 8dd52a0b0..ce86cbad0 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3658,13 +3658,26 @@ bool CMerkleTx::AcceptToMemoryPool(bool fLimitFree, bool fRejectAbsurdFee) */ void CWallet::GetFilteredNotes(std::vector & outEntries, std::string address, int minDepth, bool ignoreSpent, bool ignoreUnspendable) { - bool fFilterAddress = false; - libzcash::PaymentAddress filterPaymentAddress; + std::set filterAddresses; + if (address.length() > 0) { - filterPaymentAddress = CZCPaymentAddress(address).Get(); - fFilterAddress = true; + filterAddresses.insert(CZCPaymentAddress(address).Get()); } + GetFilteredNotes(outEntries, filterAddresses, minDepth, ignoreSpent, ignoreUnspendable); +} + +/** + * Find notes in the wallet filtered by payment addresses, min depth and ability to spend. + * These notes are decrypted and added to the output parameter vector, outEntries. + */ +void CWallet::GetFilteredNotes( + std::vector& outEntries, + std::set& filterAddresses, + int minDepth, + bool ignoreSpent, + bool ignoreUnspendable) +{ LOCK2(cs_main, cs_wallet); for (auto & p : mapWallet) { @@ -3685,7 +3698,7 @@ void CWallet::GetFilteredNotes(std::vector & outEntries, st PaymentAddress pa = nd.address; // skip notes which belong to a different payment address in the wallet - if (fFilterAddress && !(pa == filterPaymentAddress)) { + if (!(filterAddresses.empty() || filterAddresses.count(pa))) { continue; } @@ -3719,7 +3732,7 @@ void CWallet::GetFilteredNotes(std::vector & outEntries, st hSig, (unsigned char) j); - outEntries.push_back(CNotePlaintextEntry{jsop, plaintext}); + outEntries.push_back(CNotePlaintextEntry{jsop, pa, plaintext}); } catch (const note_decryption_failed &err) { // Couldn't decrypt with this spending key diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index eaaf6bbdf..e663cf075 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -267,6 +267,7 @@ typedef std::map mapNoteData_t; struct CNotePlaintextEntry { JSOutPoint jsop; + libzcash::PaymentAddress address; libzcash::NotePlaintext plaintext; }; @@ -1126,6 +1127,13 @@ public: int minDepth=1, bool ignoreSpent=true, bool ignoreUnspendable=true); + + /* Find notes filtered by payment addresses, min depth, ability to spend */ + void GetFilteredNotes(std::vector& outEntries, + std::set& filterAddresses, + int minDepth=1, + bool ignoreSpent=true, + bool ignoreUnspendable=true); };