diff --git a/src/wallet/asyncrpcoperation_sendmany.cpp b/src/wallet/asyncrpcoperation_sendmany.cpp index bfec9263..12cf2112 100644 --- a/src/wallet/asyncrpcoperation_sendmany.cpp +++ b/src/wallet/asyncrpcoperation_sendmany.cpp @@ -739,7 +739,7 @@ bool AsyncRPCOperation_sendmany::find_unspent_notes() { std::vector entries; { LOCK2(cs_main, pwalletMain->cs_wallet); - pwalletMain->GetUnspentNotes(entries, fromaddress_, mindepth_); + pwalletMain->GetFilteredNotes(entries, fromaddress_, mindepth_); } for (CNotePlaintextEntry & entry : entries) { diff --git a/src/wallet/gtest/test_wallet.cpp b/src/wallet/gtest/test_wallet.cpp index 63c0e635..6ebaef97 100644 --- a/src/wallet/gtest/test_wallet.cpp +++ b/src/wallet/gtest/test_wallet.cpp @@ -199,7 +199,7 @@ TEST(wallet_tests, find_unspent_notes) { // two notes, one is spent but wallet doesn't see it as spent yet until mined std::vector entries; - wallet.GetUnspentNotes(entries, "", 0); + wallet.GetFilteredNotes(entries, "", 0); EXPECT_EQ(2, entries.size()); // Create new payment address, add new note, and filter @@ -215,10 +215,10 @@ TEST(wallet_tests, find_unspent_notes) { // 4 notes in wallet, 1 spent (not seen), 1 is the new payment address entries.clear(); - wallet.GetUnspentNotes(entries, "", 0); + wallet.GetFilteredNotes(entries, "", 0); EXPECT_EQ(4, entries.size()); entries.clear(); - wallet.GetUnspentNotes(entries, user2_payment_address, 0); + wallet.GetFilteredNotes(entries, user2_payment_address, 0); EXPECT_EQ(2, entries.size()); // Fake-mine the transaction @@ -240,11 +240,11 @@ TEST(wallet_tests, find_unspent_notes) { // 4 notes, 1 spent (now seen) entries.clear(); - wallet.GetUnspentNotes(entries, "", 0); + wallet.GetFilteredNotes(entries, "", 0); EXPECT_EQ(3, entries.size()); entries.clear(); // no change to user2 and their two notes. - wallet.GetUnspentNotes(entries, user2_payment_address, 0); + wallet.GetFilteredNotes(entries, user2_payment_address, 0); EXPECT_EQ(2, entries.size()); // Tear down diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 3ff206b4..26b2f129 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2878,7 +2878,7 @@ CAmount getBalanceZaddr(std::string address, size_t minDepth = 1) { CAmount balance = 0; std::vector entries; LOCK2(cs_main, pwalletMain->cs_wallet); - pwalletMain->GetUnspentNotes(entries, address, minDepth); + pwalletMain->GetFilteredNotes(entries, address, minDepth); for (auto & entry : entries) { balance += CAmount(entry.plaintext.value); } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 9e8e69d3..2e1449fc 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3187,7 +3187,7 @@ bool CMerkleTx::AcceptToMemoryPool(bool fLimitFree, bool fRejectAbsurdFee) return ::AcceptToMemoryPool(mempool, state, *this, fLimitFree, NULL, fRejectAbsurdFee); } -bool CWallet::GetUnspentNotes(std::vector & outEntries, std::string address, size_t minDepth = 1) +bool CWallet::GetFilteredNotes(std::vector & outEntries, std::string address, size_t minDepth = 1, bool ignoreSpent) { bool fFilterAddress = false; libzcash::PaymentAddress filterPaymentAddress; @@ -3223,7 +3223,7 @@ bool CWallet::GetUnspentNotes(std::vector & outEntries, std } // skip note which has been spent - if (IsSpent(nd.nullifier)) { + if (ignoreSpent && IsSpent(nd.nullifier)) { continue; } diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index d5f239d3..b15d0549 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -905,7 +905,7 @@ public: void SetBroadcastTransactions(bool broadcast) { fBroadcastTransactions = broadcast; } /* Find unspent notes, filter by payment address, min depth */ - bool GetUnspentNotes(std::vector & outEntries, std::string address, size_t minDepth); + bool GetFilteredNotes(std::vector & outEntries, std::string address, size_t minDepth, bool ignoreSpent=false); };