Extend CWallet::GetFilteredNotes to enable filtering on a set of addresses

This commit is contained in:
Jack Grigg
2017-12-11 16:31:12 +00:00
parent 8487be8360
commit bdbe8e8591
2 changed files with 27 additions and 6 deletions

View File

@@ -3658,13 +3658,26 @@ bool CMerkleTx::AcceptToMemoryPool(bool fLimitFree, bool fRejectAbsurdFee)
*/ */
void CWallet::GetFilteredNotes(std::vector<CNotePlaintextEntry> & outEntries, std::string address, int minDepth, bool ignoreSpent, bool ignoreUnspendable) void CWallet::GetFilteredNotes(std::vector<CNotePlaintextEntry> & outEntries, std::string address, int minDepth, bool ignoreSpent, bool ignoreUnspendable)
{ {
bool fFilterAddress = false; std::set<PaymentAddress> filterAddresses;
libzcash::PaymentAddress filterPaymentAddress;
if (address.length() > 0) { if (address.length() > 0) {
filterPaymentAddress = CZCPaymentAddress(address).Get(); filterAddresses.insert(CZCPaymentAddress(address).Get());
fFilterAddress = true;
} }
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<CNotePlaintextEntry>& outEntries,
std::set<PaymentAddress>& filterAddresses,
int minDepth,
bool ignoreSpent,
bool ignoreUnspendable)
{
LOCK2(cs_main, cs_wallet); LOCK2(cs_main, cs_wallet);
for (auto & p : mapWallet) { for (auto & p : mapWallet) {
@@ -3685,7 +3698,7 @@ void CWallet::GetFilteredNotes(std::vector<CNotePlaintextEntry> & outEntries, st
PaymentAddress pa = nd.address; PaymentAddress pa = nd.address;
// skip notes which belong to a different payment address in the wallet // skip notes which belong to a different payment address in the wallet
if (fFilterAddress && !(pa == filterPaymentAddress)) { if (!(filterAddresses.empty() || filterAddresses.count(pa))) {
continue; continue;
} }
@@ -3719,7 +3732,7 @@ void CWallet::GetFilteredNotes(std::vector<CNotePlaintextEntry> & outEntries, st
hSig, hSig,
(unsigned char) j); (unsigned char) j);
outEntries.push_back(CNotePlaintextEntry{jsop, plaintext}); outEntries.push_back(CNotePlaintextEntry{jsop, pa, plaintext});
} catch (const note_decryption_failed &err) { } catch (const note_decryption_failed &err) {
// Couldn't decrypt with this spending key // Couldn't decrypt with this spending key

View File

@@ -267,6 +267,7 @@ typedef std::map<JSOutPoint, CNoteData> mapNoteData_t;
struct CNotePlaintextEntry struct CNotePlaintextEntry
{ {
JSOutPoint jsop; JSOutPoint jsop;
libzcash::PaymentAddress address;
libzcash::NotePlaintext plaintext; libzcash::NotePlaintext plaintext;
}; };
@@ -1127,6 +1128,13 @@ public:
bool ignoreSpent=true, bool ignoreSpent=true,
bool ignoreUnspendable=true); bool ignoreUnspendable=true);
/* Find notes filtered by payment addresses, min depth, ability to spend */
void GetFilteredNotes(std::vector<CNotePlaintextEntry>& outEntries,
std::set<libzcash::PaymentAddress>& filterAddresses,
int minDepth=1,
bool ignoreSpent=true,
bool ignoreUnspendable=true);
}; };
/** A key allocated from the key pool. */ /** A key allocated from the key pool. */