diff --git a/src/wallet/asyncrpcoperation_mergetoaddress.cpp b/src/wallet/asyncrpcoperation_mergetoaddress.cpp index 846d0d674..cc4551f6f 100644 --- a/src/wallet/asyncrpcoperation_mergetoaddress.cpp +++ b/src/wallet/asyncrpcoperation_mergetoaddress.cpp @@ -343,7 +343,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() std::vector vOutPoints = {jso}; uint256 inputAnchor; std::vector> vInputWitnesses; - pwalletMain->GetNoteWitnesses(vOutPoints, vInputWitnesses, inputAnchor); + pwalletMain->GetSproutNoteWitnesses(vOutPoints, vInputWitnesses, inputAnchor); jsopWitnessAnchorMap[jso.ToString()] = MergeToAddressWitnessAnchorData{vInputWitnesses[0], inputAnchor}; } } @@ -711,7 +711,7 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(MergeToAddressJSInf uint256 anchor; { LOCK(cs_main); - pwalletMain->GetNoteWitnesses(outPoints, witnesses, anchor); + pwalletMain->GetSproutNoteWitnesses(outPoints, witnesses, anchor); } return perform_joinsplit(info, witnesses, anchor); } diff --git a/src/wallet/asyncrpcoperation_sendmany.cpp b/src/wallet/asyncrpcoperation_sendmany.cpp index 197f21bf8..f5da139eb 100644 --- a/src/wallet/asyncrpcoperation_sendmany.cpp +++ b/src/wallet/asyncrpcoperation_sendmany.cpp @@ -420,7 +420,7 @@ bool AsyncRPCOperation_sendmany::main_impl() { std::vector vOutPoints = { jso }; uint256 inputAnchor; std::vector> vInputWitnesses; - pwalletMain->GetNoteWitnesses(vOutPoints, vInputWitnesses, inputAnchor); + pwalletMain->GetSproutNoteWitnesses(vOutPoints, vInputWitnesses, inputAnchor); jsopWitnessAnchorMap[ jso.ToString() ] = WitnessAnchorData{ vInputWitnesses[0], inputAnchor }; } } @@ -935,7 +935,7 @@ UniValue AsyncRPCOperation_sendmany::perform_joinsplit(AsyncJoinSplitInfo & info uint256 anchor; { LOCK(cs_main); - pwalletMain->GetNoteWitnesses(outPoints, witnesses, anchor); + pwalletMain->GetSproutNoteWitnesses(outPoints, witnesses, anchor); } return perform_joinsplit(info, witnesses, anchor); } diff --git a/src/wallet/gtest/test_wallet.cpp b/src/wallet/gtest/test_wallet.cpp index 85f47b790..d74a50fd4 100644 --- a/src/wallet/gtest/test_wallet.cpp +++ b/src/wallet/gtest/test_wallet.cpp @@ -97,7 +97,7 @@ JSOutPoint CreateValidBlock(TestWallet& wallet, JSOutPoint jsoutpt {wtx.GetHash(), 0, 1}; SproutNoteData nd {sk.address(), nullifier}; noteData[jsoutpt] = nd; - wtx.SetNoteData(noteData); + wtx.SetSproutNoteData(noteData); wallet.AddToWallet(wtx, true, NULL); block.vtx.push_back(wtx); @@ -152,7 +152,7 @@ TEST(wallet_tests, find_unspent_notes) { SproutNoteData nd {sk.address(), nullifier}; noteData[jsoutpt] = nd; - wtx.SetNoteData(noteData); + wtx.SetSproutNoteData(noteData); wallet.AddToWallet(wtx, true, NULL); EXPECT_FALSE(wallet.IsSpent(nullifier)); @@ -247,7 +247,7 @@ TEST(wallet_tests, find_unspent_notes) { SproutNoteData nd {sk.address(), nullifier}; noteData[jsoutpt] = nd; - wtx.SetNoteData(noteData); + wtx.SetSproutNoteData(noteData); wallet.AddToWallet(wtx, true, NULL); EXPECT_FALSE(wallet.IsSpent(nullifier)); @@ -308,7 +308,7 @@ TEST(wallet_tests, set_note_addrs_in_cwallettx) { SproutNoteData nd {sk.address(), nullifier}; noteData[jsoutpt] = nd; - wtx.SetNoteData(noteData); + wtx.SetSproutNoteData(noteData); EXPECT_EQ(noteData, wtx.mapSproutNoteData); } @@ -322,7 +322,7 @@ TEST(wallet_tests, set_invalid_note_addrs_in_cwallettx) { SproutNoteData nd {sk.address(), uint256()}; noteData[jsoutpt] = nd; - EXPECT_THROW(wtx.SetNoteData(noteData), std::logic_error); + EXPECT_THROW(wtx.SetSproutNoteData(noteData), std::logic_error); } TEST(wallet_tests, GetNoteNullifier) { @@ -497,7 +497,7 @@ TEST(wallet_tests, navigate_from_nullifier_to_note) { SproutNoteData nd {sk.address(), nullifier}; noteData[jsoutpt] = nd; - wtx.SetNoteData(noteData); + wtx.SetSproutNoteData(noteData); EXPECT_EQ(0, wallet.mapNullifiersToNotes.count(nullifier)); @@ -527,7 +527,7 @@ TEST(wallet_tests, spent_note_is_from_me) { SproutNoteData nd {sk.address(), nullifier}; noteData[jsoutpt] = nd; - wtx.SetNoteData(noteData); + wtx.SetSproutNoteData(noteData); EXPECT_FALSE(wallet.IsFromMe(wtx)); EXPECT_FALSE(wallet.IsFromMe(wtx2)); @@ -555,19 +555,19 @@ TEST(wallet_tests, cached_witnesses_empty_chain) { SproutNoteData nd2 {sk.address(), nullifier2}; noteData[jsoutpt] = nd; noteData[jsoutpt2] = nd2; - wtx.SetNoteData(noteData); + wtx.SetSproutNoteData(noteData); std::vector notes {jsoutpt, jsoutpt2}; std::vector> witnesses; uint256 anchor; - wallet.GetNoteWitnesses(notes, witnesses, anchor); + wallet.GetSproutNoteWitnesses(notes, witnesses, anchor); EXPECT_FALSE((bool) witnesses[0]); EXPECT_FALSE((bool) witnesses[1]); wallet.AddToWallet(wtx, true, NULL); witnesses.clear(); - wallet.GetNoteWitnesses(notes, witnesses, anchor); + wallet.GetSproutNoteWitnesses(notes, witnesses, anchor); EXPECT_FALSE((bool) witnesses[0]); EXPECT_FALSE((bool) witnesses[1]); @@ -578,7 +578,7 @@ TEST(wallet_tests, cached_witnesses_empty_chain) { ZCSaplingIncrementalMerkleTree saplingTree; wallet.IncrementNoteWitnesses(&index, &block, sproutTree, saplingTree); witnesses.clear(); - wallet.GetNoteWitnesses(notes, witnesses, anchor); + wallet.GetSproutNoteWitnesses(notes, witnesses, anchor); EXPECT_TRUE((bool) witnesses[0]); EXPECT_TRUE((bool) witnesses[1]); @@ -606,7 +606,7 @@ TEST(wallet_tests, cached_witnesses_chain_tip) { // Called to fetch anchor std::vector notes {jsoutpt}; std::vector> witnesses; - wallet.GetNoteWitnesses(notes, witnesses, anchor1); + wallet.GetSproutNoteWitnesses(notes, witnesses, anchor1); } { @@ -619,14 +619,14 @@ TEST(wallet_tests, cached_witnesses_chain_tip) { JSOutPoint jsoutpt {wtx.GetHash(), 0, 1}; SproutNoteData nd {sk.address(), nullifier}; noteData[jsoutpt] = nd; - wtx.SetNoteData(noteData); + wtx.SetSproutNoteData(noteData); wallet.AddToWallet(wtx, true, NULL); std::vector notes {jsoutpt}; std::vector> witnesses; uint256 anchor2; - wallet.GetNoteWitnesses(notes, witnesses, anchor2); + wallet.GetSproutNoteWitnesses(notes, witnesses, anchor2); EXPECT_FALSE((bool) witnesses[0]); // Second block @@ -639,7 +639,7 @@ TEST(wallet_tests, cached_witnesses_chain_tip) { ZCSaplingIncrementalMerkleTree saplingTree2 {saplingTree}; wallet.IncrementNoteWitnesses(&index2, &block2, sproutTree2, saplingTree2); witnesses.clear(); - wallet.GetNoteWitnesses(notes, witnesses, anchor2); + wallet.GetSproutNoteWitnesses(notes, witnesses, anchor2); EXPECT_TRUE((bool) witnesses[0]); EXPECT_NE(anchor1, anchor2); @@ -647,7 +647,7 @@ TEST(wallet_tests, cached_witnesses_chain_tip) { uint256 anchor3; wallet.DecrementNoteWitnesses(&index2); witnesses.clear(); - wallet.GetNoteWitnesses(notes, witnesses, anchor3); + wallet.GetSproutNoteWitnesses(notes, witnesses, anchor3); EXPECT_FALSE((bool) witnesses[0]); // Should not equal first anchor because none of these notes had witnesses EXPECT_NE(anchor1, anchor3); @@ -656,7 +656,7 @@ TEST(wallet_tests, cached_witnesses_chain_tip) { uint256 anchor4; wallet.IncrementNoteWitnesses(&index2, &block2, sproutTree, saplingTree); witnesses.clear(); - wallet.GetNoteWitnesses(notes, witnesses, anchor4); + wallet.GetSproutNoteWitnesses(notes, witnesses, anchor4); EXPECT_TRUE((bool) witnesses[0]); EXPECT_EQ(anchor2, anchor4); @@ -664,7 +664,7 @@ TEST(wallet_tests, cached_witnesses_chain_tip) { uint256 anchor5; wallet.IncrementNoteWitnesses(&index2, &block2, sproutTree, saplingTree); std::vector> witnesses5; - wallet.GetNoteWitnesses(notes, witnesses5, anchor5); + wallet.GetSproutNoteWitnesses(notes, witnesses5, anchor5); EXPECT_EQ(witnesses, witnesses5); EXPECT_EQ(anchor4, anchor5); } @@ -697,7 +697,7 @@ TEST(wallet_tests, CachedWitnessesDecrementFirst) { // Called to fetch anchor std::vector notes {jsoutpt}; std::vector> witnesses; - wallet.GetNoteWitnesses(notes, witnesses, anchor2); + wallet.GetSproutNoteWitnesses(notes, witnesses, anchor2); } { @@ -710,14 +710,14 @@ TEST(wallet_tests, CachedWitnessesDecrementFirst) { JSOutPoint jsoutpt {wtx.GetHash(), 0, 1}; SproutNoteData nd {sk.address(), nullifier}; noteData[jsoutpt] = nd; - wtx.SetNoteData(noteData); + wtx.SetSproutNoteData(noteData); wallet.AddToWallet(wtx, true, NULL); std::vector notes {jsoutpt}; std::vector> witnesses; uint256 anchor3; - wallet.GetNoteWitnesses(notes, witnesses, anchor3); + wallet.GetSproutNoteWitnesses(notes, witnesses, anchor3); EXPECT_FALSE((bool) witnesses[0]); // Decrementing (before the transaction has ever seen an increment) @@ -725,7 +725,7 @@ TEST(wallet_tests, CachedWitnessesDecrementFirst) { uint256 anchor4; wallet.DecrementNoteWitnesses(&index2); witnesses.clear(); - wallet.GetNoteWitnesses(notes, witnesses, anchor4); + wallet.GetSproutNoteWitnesses(notes, witnesses, anchor4); EXPECT_FALSE((bool) witnesses[0]); // Should not equal second anchor because none of these notes had witnesses EXPECT_NE(anchor2, anchor4); @@ -734,7 +734,7 @@ TEST(wallet_tests, CachedWitnessesDecrementFirst) { uint256 anchor5; wallet.IncrementNoteWitnesses(&index2, &block2, sproutTree, saplingTree); witnesses.clear(); - wallet.GetNoteWitnesses(notes, witnesses, anchor5); + wallet.GetSproutNoteWitnesses(notes, witnesses, anchor5); EXPECT_FALSE((bool) witnesses[0]); EXPECT_EQ(anchor3, anchor5); } @@ -768,7 +768,7 @@ TEST(wallet_tests, CachedWitnessesCleanIndex) { witnesses.clear(); uint256 anchor; - wallet.GetNoteWitnesses(notes, witnesses, anchor); + wallet.GetSproutNoteWitnesses(notes, witnesses, anchor); for (size_t j = 0; j <= i; j++) { EXPECT_TRUE((bool) witnesses[j]); } @@ -783,7 +783,7 @@ TEST(wallet_tests, CachedWitnessesCleanIndex) { wallet.IncrementNoteWitnesses(&(indices[i]), &(blocks[i]), sproutRiTree, saplingRiTree); witnesses.clear(); uint256 anchor; - wallet.GetNoteWitnesses(notes, witnesses, anchor); + wallet.GetSproutNoteWitnesses(notes, witnesses, anchor); for (size_t j = 0; j < numBlocks; j++) { EXPECT_TRUE((bool) witnesses[j]); } @@ -796,7 +796,7 @@ TEST(wallet_tests, CachedWitnessesCleanIndex) { wallet.DecrementNoteWitnesses(&(indices[i])); witnesses.clear(); uint256 anchor; - wallet.GetNoteWitnesses(notes, witnesses, anchor); + wallet.GetSproutNoteWitnesses(notes, witnesses, anchor); for (size_t j = 0; j < numBlocks; j++) { EXPECT_TRUE((bool) witnesses[j]); } @@ -808,7 +808,7 @@ TEST(wallet_tests, CachedWitnessesCleanIndex) { wallet.IncrementNoteWitnesses(&(indices[i]), &(blocks[i]), sproutRiPrevTree, saplingRiPrevTree); witnesses.clear(); uint256 anchor; - wallet.GetNoteWitnesses(notes, witnesses, anchor); + wallet.GetSproutNoteWitnesses(notes, witnesses, anchor); for (size_t j = 0; j < numBlocks; j++) { EXPECT_TRUE((bool) witnesses[j]); } @@ -835,7 +835,7 @@ TEST(wallet_tests, ClearNoteWitnessCache) { JSOutPoint jsoutpt2 {wtx.GetHash(), 0, 1}; SproutNoteData nd {sk.address(), nullifier}; noteData[jsoutpt] = nd; - wtx.SetNoteData(noteData); + wtx.SetSproutNoteData(noteData); // Pretend we mined the tx by adding a fake witness ZCIncrementalMerkleTree tree; @@ -850,7 +850,7 @@ TEST(wallet_tests, ClearNoteWitnessCache) { uint256 anchor2; // Before clearing, we should have a witness for one note - wallet.GetNoteWitnesses(notes, witnesses, anchor2); + wallet.GetSproutNoteWitnesses(notes, witnesses, anchor2); EXPECT_TRUE((bool) witnesses[0]); EXPECT_FALSE((bool) witnesses[1]); EXPECT_EQ(1, wallet.mapWallet[hash].mapSproutNoteData[jsoutpt].witnessHeight); @@ -859,7 +859,7 @@ TEST(wallet_tests, ClearNoteWitnessCache) { // After clearing, we should not have a witness for either note wallet.ClearNoteWitnessCache(); witnesses.clear(); - wallet.GetNoteWitnesses(notes, witnesses, anchor2); + wallet.GetSproutNoteWitnesses(notes, witnesses, anchor2); EXPECT_FALSE((bool) witnesses[0]); EXPECT_FALSE((bool) witnesses[1]); EXPECT_EQ(-1, wallet.mapWallet[hash].mapSproutNoteData[jsoutpt].witnessHeight); @@ -962,7 +962,7 @@ TEST(wallet_tests, UpdateNullifierNoteMap) { JSOutPoint jsoutpt {wtx.GetHash(), 0, 1}; SproutNoteData nd {sk.address()}; noteData[jsoutpt] = nd; - wtx.SetNoteData(noteData); + wtx.SetSproutNoteData(noteData); wallet.AddToWallet(wtx, true, NULL); EXPECT_EQ(0, wallet.mapNullifiersToNotes.count(nullifier)); @@ -997,7 +997,7 @@ TEST(wallet_tests, UpdatedNoteData) { JSOutPoint jsoutpt {wtx.GetHash(), 0, 0}; SproutNoteData nd {sk.address(), nullifier}; noteData[jsoutpt] = nd; - wtx.SetNoteData(noteData); + wtx.SetSproutNoteData(noteData); // Pretend we mined the tx by adding a fake witness ZCIncrementalMerkleTree tree; @@ -1010,7 +1010,7 @@ TEST(wallet_tests, UpdatedNoteData) { JSOutPoint jsoutpt2 {wtx2.GetHash(), 0, 1}; SproutNoteData nd2 {sk.address(), nullifier2}; noteData[jsoutpt2] = nd2; - wtx2.SetNoteData(noteData); + wtx2.SetSproutNoteData(noteData); // The txs should initially be different EXPECT_NE(wtx.mapSproutNoteData, wtx2.mapSproutNoteData); @@ -1042,7 +1042,7 @@ TEST(wallet_tests, MarkAffectedTransactionsDirty) { SproutNoteData nd {sk.address(), nullifier}; noteData[jsoutpt] = nd; - wtx.SetNoteData(noteData); + wtx.SetSproutNoteData(noteData); wallet.AddToWallet(wtx, true, NULL); wallet.MarkAffectedTransactionsDirty(wtx); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 9218c1ace..be2110e65 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1322,8 +1322,9 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl CWalletTx wtx(this,tx); if (noteData.size() > 0) { - wtx.SetNoteData(noteData); + wtx.SetSproutNoteData(noteData); } + // TODO: Sapling note data // Get merkle branch if transaction was found in a block if (pblock) @@ -1468,9 +1469,9 @@ bool CWallet::IsFromMe(const uint256& nullifier) const return false; } -void CWallet::GetNoteWitnesses(std::vector notes, - std::vector>& witnesses, - uint256 &final_anchor) +void CWallet::GetSproutNoteWitnesses(std::vector notes, + std::vector>& witnesses, + uint256 &final_anchor) { { LOCK(cs_wallet); @@ -1628,7 +1629,7 @@ CAmount CWallet::GetChange(const CTransaction& tx) const return nChange; } -void CWalletTx::SetNoteData(mapSproutNoteData_t ¬eData) +void CWalletTx::SetSproutNoteData(mapSproutNoteData_t ¬eData) { mapSproutNoteData.clear(); for (const std::pair nd : noteData) { @@ -1639,7 +1640,7 @@ void CWalletTx::SetNoteData(mapSproutNoteData_t ¬eData) } else { // If FindMyNotes() was used to obtain noteData, // this should never happen - throw std::logic_error("CWalletTx::SetNoteData(): Invalid note"); + throw std::logic_error("CWalletTx::SetSproutNoteData(): Invalid note"); } } } diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 25c5704ce..6ae83b5cb 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -513,7 +513,7 @@ public: MarkDirty(); } - void SetNoteData(mapSproutNoteData_t ¬eData); + void SetSproutNoteData(mapSproutNoteData_t ¬eData); //! filter decides which addresses will count towards the debit CAmount GetDebit(const isminefilter& filter) const; @@ -1074,7 +1074,7 @@ public: uint8_t n) const; mapSproutNoteData_t FindMyNotes(const CTransaction& tx) const; bool IsFromMe(const uint256& nullifier) const; - void GetNoteWitnesses( + void GetSproutNoteWitnesses( std::vector notes, std::vector>& witnesses, uint256 &final_anchor); diff --git a/src/zcbenchmarks.cpp b/src/zcbenchmarks.cpp index aa6fac763..fea10000f 100644 --- a/src/zcbenchmarks.cpp +++ b/src/zcbenchmarks.cpp @@ -316,7 +316,7 @@ double benchmark_increment_note_witnesses(size_t nTxs) SproutNoteData nd {sk.address(), nullifier}; noteData[jsoutpt] = nd; - wtx.SetNoteData(noteData); + wtx.SetSproutNoteData(noteData); wallet.AddToWallet(wtx, true, NULL); block1.vtx.push_back(wtx); } @@ -339,7 +339,7 @@ double benchmark_increment_note_witnesses(size_t nTxs) SproutNoteData nd {sk.address(), nullifier}; noteData[jsoutpt] = nd; - wtx.SetNoteData(noteData); + wtx.SetSproutNoteData(noteData); wallet.AddToWallet(wtx, true, NULL); block2.vtx.push_back(wtx); }