From 8ea8ef9850607f353cf82233de223b63134e9e4b Mon Sep 17 00:00:00 2001 From: Eirik Ogilvie-Wigley Date: Wed, 1 Aug 2018 10:41:36 -0600 Subject: [PATCH] Rename Witnesses to include sprout or sapling --- src/gtest/test_joinsplit.cpp | 6 ++-- src/test/rpc_wallet_tests.cpp | 4 +-- src/transaction_builder.cpp | 4 +-- src/transaction_builder.h | 6 ++-- .../asyncrpcoperation_mergetoaddress.cpp | 16 ++++----- src/wallet/asyncrpcoperation_mergetoaddress.h | 6 ++-- src/wallet/asyncrpcoperation_sendmany.cpp | 16 ++++----- src/wallet/asyncrpcoperation_sendmany.h | 6 ++-- src/wallet/gtest/test_wallet.cpp | 36 +++++++++---------- src/wallet/rpcwallet.cpp | 4 +-- src/wallet/wallet.cpp | 10 +++--- src/wallet/wallet.h | 10 +++--- src/zcash/IncrementalMerkleTree.hpp | 4 +-- src/zcash/JoinSplit.hpp | 4 +-- 14 files changed, 66 insertions(+), 66 deletions(-) diff --git a/src/gtest/test_joinsplit.cpp b/src/gtest/test_joinsplit.cpp index e5a2bbf9f..4de2fc471 100644 --- a/src/gtest/test_joinsplit.cpp +++ b/src/gtest/test_joinsplit.cpp @@ -327,12 +327,12 @@ for test_input in TEST_VECTORS: void increment_note_witnesses( const uint256& element, - std::vector& witnesses, + std::vector& witnesses, SproutMerkleTree& tree ) { tree.append(element); - for (ZCIncrementalWitness& w : witnesses) { + for (SproutWitness& w : witnesses) { w.append(element); } witnesses.push_back(tree.witness()); @@ -341,7 +341,7 @@ void increment_note_witnesses( TEST(joinsplit, full_api_test) { { - std::vector witnesses; + std::vector witnesses; SproutMerkleTree tree; increment_note_witnesses(uint256(), witnesses, tree); SproutSpendingKey sk = SproutSpendingKey::random(); diff --git a/src/test/rpc_wallet_tests.cpp b/src/test/rpc_wallet_tests.cpp index 5064526ba..9e9b707e6 100644 --- a/src/test/rpc_wallet_tests.cpp +++ b/src/test/rpc_wallet_tests.cpp @@ -1200,7 +1200,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_internals) static_cast(operation.get())->testmode = true; AsyncJoinSplitInfo info; - std::vector> witnesses; + std::vector> witnesses; uint256 anchor; try { proxy.perform_joinsplit(info, witnesses, anchor); @@ -1736,7 +1736,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_mergetoaddress_internals) static_cast(operation.get())->testmode = true; MergeToAddressJSInfo info; - std::vector> witnesses; + std::vector> witnesses; uint256 anchor; try { proxy.perform_joinsplit(info, witnesses, anchor); diff --git a/src/transaction_builder.cpp b/src/transaction_builder.cpp index f2b915c5a..ed8d8c25b 100644 --- a/src/transaction_builder.cpp +++ b/src/transaction_builder.cpp @@ -15,7 +15,7 @@ SpendDescriptionInfo::SpendDescriptionInfo( libzcash::SaplingExpandedSpendingKey expsk, libzcash::SaplingNote note, uint256 anchor, - ZCSaplingIncrementalWitness witness) : expsk(expsk), note(note), anchor(anchor), witness(witness) + SaplingWitness witness) : expsk(expsk), note(note), anchor(anchor), witness(witness) { librustzcash_sapling_generate_r(alpha.begin()); } @@ -32,7 +32,7 @@ bool TransactionBuilder::AddSaplingSpend( libzcash::SaplingExpandedSpendingKey expsk, libzcash::SaplingNote note, uint256 anchor, - ZCSaplingIncrementalWitness witness) + SaplingWitness witness) { // Consistency check: all anchors must equal the first one if (!spends.empty()) { diff --git a/src/transaction_builder.h b/src/transaction_builder.h index 6c159e7aa..0291c7ad1 100644 --- a/src/transaction_builder.h +++ b/src/transaction_builder.h @@ -23,13 +23,13 @@ struct SpendDescriptionInfo { libzcash::SaplingNote note; uint256 alpha; uint256 anchor; - ZCSaplingIncrementalWitness witness; + SaplingWitness witness; SpendDescriptionInfo( libzcash::SaplingExpandedSpendingKey expsk, libzcash::SaplingNote note, uint256 anchor, - ZCSaplingIncrementalWitness witness); + SaplingWitness witness); }; struct OutputDescriptionInfo { @@ -79,7 +79,7 @@ public: libzcash::SaplingExpandedSpendingKey expsk, libzcash::SaplingNote note, uint256 anchor, - ZCSaplingIncrementalWitness witness); + SaplingWitness witness); void AddSaplingOutput( libzcash::SaplingFullViewingKey from, diff --git a/src/wallet/asyncrpcoperation_mergetoaddress.cpp b/src/wallet/asyncrpcoperation_mergetoaddress.cpp index 2647a6c60..6a16dd4fa 100644 --- a/src/wallet/asyncrpcoperation_mergetoaddress.cpp +++ b/src/wallet/asyncrpcoperation_mergetoaddress.cpp @@ -342,7 +342,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() JSOutPoint jso = std::get<0>(t); std::vector vOutPoints = {jso}; uint256 inputAnchor; - std::vector> vInputWitnesses; + std::vector> vInputWitnesses; pwalletMain->GetSproutNoteWitnesses(vOutPoints, vInputWitnesses, inputAnchor); jsopWitnessAnchorMap[jso.ToString()] = MergeToAddressWitnessAnchorData{vInputWitnesses[0], inputAnchor}; } @@ -406,7 +406,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() CAmount jsInputValue = 0; uint256 jsAnchor; - std::vector> witnesses; + std::vector> witnesses; JSDescription prevJoinSplit; @@ -437,7 +437,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() } assert(changeOutputIndex != -1); - boost::optional changeWitness; + boost::optional changeWitness; int n = 0; for (const uint256& commitment : prevJoinSplit.commitments) { tree.append(commitment); @@ -487,7 +487,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() std::vector vInputNotes; std::vector vInputZKeys; std::vector vOutPoints; - std::vector> vInputWitnesses; + std::vector> vInputWitnesses; uint256 inputAnchor; int numInputsNeeded = (jsChange > 0) ? 1 : 0; while (numInputsNeeded++ < ZC_NUM_JS_INPUTS && zInputsDeque.size() > 0) { @@ -544,7 +544,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() if (!optionalWitness) { throw JSONRPCError(RPC_WALLET_ERROR, "Witness for note commitment is null"); } - ZCIncrementalWitness w = *optionalWitness; // could use .get(); + SproutWitness w = *optionalWitness; // could use .get(); if (jsChange > 0) { for (const uint256& commitment : previousCommitments) { w.append(commitment); @@ -695,7 +695,7 @@ void AsyncRPCOperation_mergetoaddress::sign_send_raw_transaction(UniValue obj) UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(MergeToAddressJSInfo& info) { - std::vector> witnesses; + std::vector> witnesses; uint256 anchor; { LOCK(cs_main); @@ -707,7 +707,7 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(MergeToAddressJSInf UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(MergeToAddressJSInfo& info, std::vector& outPoints) { - std::vector> witnesses; + std::vector> witnesses; uint256 anchor; { LOCK(cs_main); @@ -718,7 +718,7 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(MergeToAddressJSInf UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit( MergeToAddressJSInfo& info, - std::vector> witnesses, + std::vector> witnesses, uint256 anchor) { if (anchor.IsNull()) { diff --git a/src/wallet/asyncrpcoperation_mergetoaddress.h b/src/wallet/asyncrpcoperation_mergetoaddress.h index 0bbd5f82d..ef59ba67b 100644 --- a/src/wallet/asyncrpcoperation_mergetoaddress.h +++ b/src/wallet/asyncrpcoperation_mergetoaddress.h @@ -45,7 +45,7 @@ struct MergeToAddressJSInfo { // A struct to help us track the witness and anchor for a given JSOutPoint struct MergeToAddressWitnessAnchorData { - boost::optional witness; + boost::optional witness; uint256 anchor; }; @@ -112,7 +112,7 @@ private: // JoinSplit where you have the witnesses and anchor UniValue perform_joinsplit( MergeToAddressJSInfo& info, - std::vector> witnesses, + std::vector> witnesses, uint256 anchor); void sign_send_raw_transaction(UniValue obj); // throws exception if there was an error @@ -172,7 +172,7 @@ public: UniValue perform_joinsplit( MergeToAddressJSInfo& info, - std::vector> witnesses, + std::vector> witnesses, uint256 anchor) { return delegate->perform_joinsplit(info, witnesses, anchor); diff --git a/src/wallet/asyncrpcoperation_sendmany.cpp b/src/wallet/asyncrpcoperation_sendmany.cpp index 0c4b6e9c8..50c4ebde2 100644 --- a/src/wallet/asyncrpcoperation_sendmany.cpp +++ b/src/wallet/asyncrpcoperation_sendmany.cpp @@ -419,7 +419,7 @@ bool AsyncRPCOperation_sendmany::main_impl() { JSOutPoint jso = std::get<0>(t); std::vector vOutPoints = { jso }; uint256 inputAnchor; - std::vector> vInputWitnesses; + std::vector> vInputWitnesses; pwalletMain->GetSproutNoteWitnesses(vOutPoints, vInputWitnesses, inputAnchor); jsopWitnessAnchorMap[ jso.ToString() ] = WitnessAnchorData{ vInputWitnesses[0], inputAnchor }; } @@ -526,7 +526,7 @@ bool AsyncRPCOperation_sendmany::main_impl() { CAmount jsInputValue = 0; uint256 jsAnchor; - std::vector> witnesses; + std::vector> witnesses; JSDescription prevJoinSplit; @@ -557,7 +557,7 @@ bool AsyncRPCOperation_sendmany::main_impl() { } assert(changeOutputIndex != -1); - boost::optional changeWitness; + boost::optional changeWitness; int n = 0; for (const uint256& commitment : prevJoinSplit.commitments) { tree.append(commitment); @@ -606,7 +606,7 @@ bool AsyncRPCOperation_sendmany::main_impl() { // std::vector vInputNotes; std::vector vOutPoints; - std::vector> vInputWitnesses; + std::vector> vInputWitnesses; uint256 inputAnchor; int numInputsNeeded = (jsChange>0) ? 1 : 0; while (numInputsNeeded++ < ZC_NUM_JS_INPUTS && zInputsDeque.size() > 0) { @@ -663,7 +663,7 @@ bool AsyncRPCOperation_sendmany::main_impl() { if (!optionalWitness) { throw JSONRPCError(RPC_WALLET_ERROR, "Witness for note commitment is null"); } - ZCIncrementalWitness w = *optionalWitness; // could use .get(); + SproutWitness w = *optionalWitness; // could use .get(); if (jsChange > 0) { for (const uint256& commitment : previousCommitments) { w.append(commitment); @@ -920,7 +920,7 @@ bool AsyncRPCOperation_sendmany::find_unspent_notes() { } UniValue AsyncRPCOperation_sendmany::perform_joinsplit(AsyncJoinSplitInfo & info) { - std::vector> witnesses; + std::vector> witnesses; uint256 anchor; { LOCK(cs_main); @@ -931,7 +931,7 @@ UniValue AsyncRPCOperation_sendmany::perform_joinsplit(AsyncJoinSplitInfo & info UniValue AsyncRPCOperation_sendmany::perform_joinsplit(AsyncJoinSplitInfo & info, std::vector & outPoints) { - std::vector> witnesses; + std::vector> witnesses; uint256 anchor; { LOCK(cs_main); @@ -942,7 +942,7 @@ UniValue AsyncRPCOperation_sendmany::perform_joinsplit(AsyncJoinSplitInfo & info UniValue AsyncRPCOperation_sendmany::perform_joinsplit( AsyncJoinSplitInfo & info, - std::vector> witnesses, + std::vector> witnesses, uint256 anchor) { if (anchor.IsNull()) { diff --git a/src/wallet/asyncrpcoperation_sendmany.h b/src/wallet/asyncrpcoperation_sendmany.h index 24f174574..d3729804a 100644 --- a/src/wallet/asyncrpcoperation_sendmany.h +++ b/src/wallet/asyncrpcoperation_sendmany.h @@ -45,7 +45,7 @@ struct AsyncJoinSplitInfo // A struct to help us track the witness and anchor for a given JSOutPoint struct WitnessAnchorData { - boost::optional witness; + boost::optional witness; uint256 anchor; }; @@ -112,7 +112,7 @@ private: // JoinSplit where you have the witnesses and anchor UniValue perform_joinsplit( AsyncJoinSplitInfo & info, - std::vector> witnesses, + std::vector> witnesses, uint256 anchor); void sign_send_raw_transaction(UniValue obj); // throws exception if there was an error @@ -173,7 +173,7 @@ public: UniValue perform_joinsplit( AsyncJoinSplitInfo & info, - std::vector> witnesses, + std::vector> witnesses, uint256 anchor) { return delegate->perform_joinsplit(info, witnesses, anchor); diff --git a/src/wallet/gtest/test_wallet.cpp b/src/wallet/gtest/test_wallet.cpp index 154ccd973..5bacb6ff5 100644 --- a/src/wallet/gtest/test_wallet.cpp +++ b/src/wallet/gtest/test_wallet.cpp @@ -120,8 +120,8 @@ std::pair CreateValidBlock(TestWallet& wallet, std::pair GetWitnessesAndAnchors(TestWallet& wallet, std::vector& sproutNotes, std::vector& saplingNotes, - std::vector>& sproutWitnesses, - std::vector>& saplingWitnesses) { + std::vector>& sproutWitnesses, + std::vector>& saplingWitnesses) { sproutWitnesses.clear(); saplingWitnesses.clear(); uint256 sproutAnchor; @@ -585,8 +585,8 @@ TEST(wallet_tests, cached_witnesses_empty_chain) { std::vector sproutNotes {jsoutpt, jsoutpt2}; std::vector saplingNotes = SetSaplingNoteData(wtx); - std::vector> sproutWitnesses; - std::vector> saplingWitnesses; + std::vector> sproutWitnesses; + std::vector> saplingWitnesses; ::GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses); @@ -639,8 +639,8 @@ TEST(wallet_tests, cached_witnesses_chain_tip) { // Called to fetch anchor std::vector sproutNotes {outpts.first}; std::vector saplingNotes {outpts.second}; - std::vector> sproutWitnesses; - std::vector> saplingWitnesses; + std::vector> sproutWitnesses; + std::vector> saplingWitnesses; anchors1 = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses); EXPECT_NE(anchors1.first, anchors1.second); @@ -661,8 +661,8 @@ TEST(wallet_tests, cached_witnesses_chain_tip) { wallet.AddToWallet(wtx, true, NULL); std::vector sproutNotes {jsoutpt}; - std::vector> sproutWitnesses; - std::vector> saplingWitnesses; + std::vector> sproutWitnesses; + std::vector> saplingWitnesses; GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses); @@ -709,8 +709,8 @@ TEST(wallet_tests, cached_witnesses_chain_tip) { // Incrementing with the same block again should not change the cache wallet.IncrementNoteWitnesses(&index2, &block2, sproutTree, saplingTree); - std::vector> sproutWitnesses5; - std::vector> saplingWitnesses5; + std::vector> sproutWitnesses5; + std::vector> saplingWitnesses5; auto anchors5 = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses5, saplingWitnesses5); EXPECT_NE(anchors5.first, anchors5.second); @@ -750,8 +750,8 @@ TEST(wallet_tests, CachedWitnessesDecrementFirst) { // Called to fetch anchor std::vector sproutNotes {outpts.first}; std::vector saplingNotes {outpts.second}; - std::vector> sproutWitnesses; - std::vector> saplingWitnesses; + std::vector> sproutWitnesses; + std::vector> saplingWitnesses; anchors2 = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses); } @@ -770,8 +770,8 @@ TEST(wallet_tests, CachedWitnessesDecrementFirst) { wallet.AddToWallet(wtx, true, NULL); std::vector sproutNotes {jsoutpt}; - std::vector> sproutWitnesses; - std::vector> saplingWitnesses; + std::vector> sproutWitnesses; + std::vector> saplingWitnesses; auto anchors3 = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses); @@ -814,8 +814,8 @@ TEST(wallet_tests, CachedWitnessesCleanIndex) { SproutMerkleTree sproutRiTree = sproutTree; SaplingMerkleTree saplingTree; SaplingMerkleTree saplingRiTree = saplingTree; - std::vector> sproutWitnesses; - std::vector> saplingWitnesses; + std::vector> sproutWitnesses; + std::vector> saplingWitnesses; auto sk = libzcash::SproutSpendingKey::random(); wallet.AddSpendingKey(sk); @@ -922,8 +922,8 @@ TEST(wallet_tests, ClearNoteWitnessCache) { wallet.AddToWallet(wtx, true, NULL); std::vector sproutNotes {jsoutpt, jsoutpt2}; - std::vector> sproutWitnesses; - std::vector> saplingWitnesses; + std::vector> sproutWitnesses; + std::vector> saplingWitnesses; // Before clearing, we should have a witness for one note GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 466cb55cf..515140d6a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2843,7 +2843,7 @@ UniValue zc_raw_receive(const UniValue& params, bool fHelp) SproutNote decrypted_note = npt.note(payment_addr); assert(pwalletMain != NULL); - std::vector> witnesses; + std::vector> witnesses; uint256 anchor; uint256 commitment = decrypted_note.cm(); pwalletMain->WitnessNoteCommitment( @@ -2944,7 +2944,7 @@ UniValue zc_raw_joinsplit(const UniValue& params, bool fHelp) } uint256 anchor; - std::vector> witnesses; + std::vector> witnesses; pwalletMain->WitnessNoteCommitment(commitments, witnesses, anchor); assert(witnesses.size() == notes.size()); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 8be401e06..7905c2368 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1470,7 +1470,7 @@ bool CWallet::IsFromMe(const uint256& nullifier) const } void CWallet::GetSproutNoteWitnesses(std::vector notes, - std::vector>& witnesses, + std::vector>& witnesses, uint256 &final_anchor) { LOCK(cs_wallet); @@ -1497,7 +1497,7 @@ void CWallet::GetSproutNoteWitnesses(std::vector notes, } void CWallet::GetSaplingNoteWitnesses(std::vector notes, - std::vector>& witnesses, + std::vector>& witnesses, uint256 &final_anchor) { LOCK(cs_wallet); @@ -1888,7 +1888,7 @@ bool CWalletTx::WriteToDisk(CWalletDB *pwalletdb) } void CWallet::WitnessNoteCommitment(std::vector commitments, - std::vector>& witnesses, + std::vector>& witnesses, uint256 &final_anchor) { witnesses.resize(commitments.size()); @@ -1907,7 +1907,7 @@ void CWallet::WitnessNoteCommitment(std::vector commitments, { tree.append(note_commitment); - BOOST_FOREACH(boost::optional& wit, witnesses) { + BOOST_FOREACH(boost::optional& wit, witnesses) { if (wit) { wit->append(note_commitment); } @@ -1937,7 +1937,7 @@ void CWallet::WitnessNoteCommitment(std::vector commitments, // TODO: #93; Select a root via some heuristic. final_anchor = tree.root(); - BOOST_FOREACH(boost::optional& wit, witnesses) { + BOOST_FOREACH(boost::optional& wit, witnesses) { if (wit) { assert(final_anchor == wit->root()); } diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 559792e4c..d395d0dbb 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -220,7 +220,7 @@ public: * Cached incremental witnesses for spendable Notes. * Beginning of the list is the most recent witness. */ - std::list witnesses; + std::list witnesses; /** * Block height corresponding to the most current witness. @@ -272,7 +272,7 @@ public: */ SaplingNoteData() : witnessHeight {-1} { } - std::list witnesses; + std::list witnesses; int witnessHeight; }; @@ -1033,7 +1033,7 @@ public: void EraseFromWallet(const uint256 &hash); void WitnessNoteCommitment( std::vector commitments, - std::vector>& witnesses, + std::vector>& witnesses, uint256 &final_anchor); int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false); void ReacceptWalletTransactions(); @@ -1077,11 +1077,11 @@ public: bool IsFromMe(const uint256& nullifier) const; void GetSproutNoteWitnesses( std::vector notes, - std::vector>& witnesses, + std::vector>& witnesses, uint256 &final_anchor); void GetSaplingNoteWitnesses( std::vector notes, - std::vector>& witnesses, + std::vector>& witnesses, uint256 &final_anchor); isminetype IsMine(const CTxIn& txin) const; diff --git a/src/zcash/IncrementalMerkleTree.hpp b/src/zcash/IncrementalMerkleTree.hpp index 8f56fa4a2..ec29b0a2c 100644 --- a/src/zcash/IncrementalMerkleTree.hpp +++ b/src/zcash/IncrementalMerkleTree.hpp @@ -251,13 +251,13 @@ EmptyMerkleRoots IncrementalMerkleTree::emptyroots; typedef libzcash::IncrementalMerkleTree SproutMerkleTree; typedef libzcash::IncrementalMerkleTree ZCTestingIncrementalMerkleTree; -typedef libzcash::IncrementalWitness ZCIncrementalWitness; +typedef libzcash::IncrementalWitness SproutWitness; typedef libzcash::IncrementalWitness ZCTestingIncrementalWitness; typedef libzcash::IncrementalMerkleTree SaplingMerkleTree; typedef libzcash::IncrementalMerkleTree ZCSaplingTestingIncrementalMerkleTree; -typedef libzcash::IncrementalWitness ZCSaplingIncrementalWitness; +typedef libzcash::IncrementalWitness SaplingWitness; typedef libzcash::IncrementalWitness ZCSaplingTestingIncrementalWitness; #endif /* ZC_INCREMENTALMERKLETREE_H_ */ diff --git a/src/zcash/JoinSplit.hpp b/src/zcash/JoinSplit.hpp index 2e1c79335..c37926ede 100644 --- a/src/zcash/JoinSplit.hpp +++ b/src/zcash/JoinSplit.hpp @@ -25,12 +25,12 @@ typedef boost::variant SproutProof; class JSInput { public: - ZCIncrementalWitness witness; + SproutWitness witness; SproutNote note; SproutSpendingKey key; JSInput(); - JSInput(ZCIncrementalWitness witness, + JSInput(SproutWitness witness, SproutNote note, SproutSpendingKey key) : witness(witness), note(note), key(key) { }