Browse Source

Rename Witnesses to include sprout or sapling

metaverse
Eirik Ogilvie-Wigley 6 years ago
parent
commit
8ea8ef9850
  1. 6
      src/gtest/test_joinsplit.cpp
  2. 4
      src/test/rpc_wallet_tests.cpp
  3. 4
      src/transaction_builder.cpp
  4. 6
      src/transaction_builder.h
  5. 16
      src/wallet/asyncrpcoperation_mergetoaddress.cpp
  6. 6
      src/wallet/asyncrpcoperation_mergetoaddress.h
  7. 16
      src/wallet/asyncrpcoperation_sendmany.cpp
  8. 6
      src/wallet/asyncrpcoperation_sendmany.h
  9. 36
      src/wallet/gtest/test_wallet.cpp
  10. 4
      src/wallet/rpcwallet.cpp
  11. 10
      src/wallet/wallet.cpp
  12. 10
      src/wallet/wallet.h
  13. 4
      src/zcash/IncrementalMerkleTree.hpp
  14. 4
      src/zcash/JoinSplit.hpp

6
src/gtest/test_joinsplit.cpp

@ -327,12 +327,12 @@ for test_input in TEST_VECTORS:
void increment_note_witnesses( void increment_note_witnesses(
const uint256& element, const uint256& element,
std::vector<ZCIncrementalWitness>& witnesses, std::vector<SproutWitness>& witnesses,
SproutMerkleTree& tree SproutMerkleTree& tree
) )
{ {
tree.append(element); tree.append(element);
for (ZCIncrementalWitness& w : witnesses) { for (SproutWitness& w : witnesses) {
w.append(element); w.append(element);
} }
witnesses.push_back(tree.witness()); witnesses.push_back(tree.witness());
@ -341,7 +341,7 @@ void increment_note_witnesses(
TEST(joinsplit, full_api_test) TEST(joinsplit, full_api_test)
{ {
{ {
std::vector<ZCIncrementalWitness> witnesses; std::vector<SproutWitness> witnesses;
SproutMerkleTree tree; SproutMerkleTree tree;
increment_note_witnesses(uint256(), witnesses, tree); increment_note_witnesses(uint256(), witnesses, tree);
SproutSpendingKey sk = SproutSpendingKey::random(); SproutSpendingKey sk = SproutSpendingKey::random();

4
src/test/rpc_wallet_tests.cpp

@ -1200,7 +1200,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_internals)
static_cast<AsyncRPCOperation_sendmany *>(operation.get())->testmode = true; static_cast<AsyncRPCOperation_sendmany *>(operation.get())->testmode = true;
AsyncJoinSplitInfo info; AsyncJoinSplitInfo info;
std::vector<boost::optional < ZCIncrementalWitness>> witnesses; std::vector<boost::optional < SproutWitness>> witnesses;
uint256 anchor; uint256 anchor;
try { try {
proxy.perform_joinsplit(info, witnesses, anchor); proxy.perform_joinsplit(info, witnesses, anchor);
@ -1736,7 +1736,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_mergetoaddress_internals)
static_cast<AsyncRPCOperation_sendmany *>(operation.get())->testmode = true; static_cast<AsyncRPCOperation_sendmany *>(operation.get())->testmode = true;
MergeToAddressJSInfo info; MergeToAddressJSInfo info;
std::vector<boost::optional < ZCIncrementalWitness>> witnesses; std::vector<boost::optional < SproutWitness>> witnesses;
uint256 anchor; uint256 anchor;
try { try {
proxy.perform_joinsplit(info, witnesses, anchor); proxy.perform_joinsplit(info, witnesses, anchor);

4
src/transaction_builder.cpp

@ -15,7 +15,7 @@ SpendDescriptionInfo::SpendDescriptionInfo(
libzcash::SaplingExpandedSpendingKey expsk, libzcash::SaplingExpandedSpendingKey expsk,
libzcash::SaplingNote note, libzcash::SaplingNote note,
uint256 anchor, 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()); librustzcash_sapling_generate_r(alpha.begin());
} }
@ -32,7 +32,7 @@ bool TransactionBuilder::AddSaplingSpend(
libzcash::SaplingExpandedSpendingKey expsk, libzcash::SaplingExpandedSpendingKey expsk,
libzcash::SaplingNote note, libzcash::SaplingNote note,
uint256 anchor, uint256 anchor,
ZCSaplingIncrementalWitness witness) SaplingWitness witness)
{ {
// Consistency check: all anchors must equal the first one // Consistency check: all anchors must equal the first one
if (!spends.empty()) { if (!spends.empty()) {

6
src/transaction_builder.h

@ -23,13 +23,13 @@ struct SpendDescriptionInfo {
libzcash::SaplingNote note; libzcash::SaplingNote note;
uint256 alpha; uint256 alpha;
uint256 anchor; uint256 anchor;
ZCSaplingIncrementalWitness witness; SaplingWitness witness;
SpendDescriptionInfo( SpendDescriptionInfo(
libzcash::SaplingExpandedSpendingKey expsk, libzcash::SaplingExpandedSpendingKey expsk,
libzcash::SaplingNote note, libzcash::SaplingNote note,
uint256 anchor, uint256 anchor,
ZCSaplingIncrementalWitness witness); SaplingWitness witness);
}; };
struct OutputDescriptionInfo { struct OutputDescriptionInfo {
@ -79,7 +79,7 @@ public:
libzcash::SaplingExpandedSpendingKey expsk, libzcash::SaplingExpandedSpendingKey expsk,
libzcash::SaplingNote note, libzcash::SaplingNote note,
uint256 anchor, uint256 anchor,
ZCSaplingIncrementalWitness witness); SaplingWitness witness);
void AddSaplingOutput( void AddSaplingOutput(
libzcash::SaplingFullViewingKey from, libzcash::SaplingFullViewingKey from,

16
src/wallet/asyncrpcoperation_mergetoaddress.cpp

@ -342,7 +342,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
JSOutPoint jso = std::get<0>(t); JSOutPoint jso = std::get<0>(t);
std::vector<JSOutPoint> vOutPoints = {jso}; std::vector<JSOutPoint> vOutPoints = {jso};
uint256 inputAnchor; uint256 inputAnchor;
std::vector<boost::optional<ZCIncrementalWitness>> vInputWitnesses; std::vector<boost::optional<SproutWitness>> vInputWitnesses;
pwalletMain->GetSproutNoteWitnesses(vOutPoints, vInputWitnesses, inputAnchor); pwalletMain->GetSproutNoteWitnesses(vOutPoints, vInputWitnesses, inputAnchor);
jsopWitnessAnchorMap[jso.ToString()] = MergeToAddressWitnessAnchorData{vInputWitnesses[0], inputAnchor}; jsopWitnessAnchorMap[jso.ToString()] = MergeToAddressWitnessAnchorData{vInputWitnesses[0], inputAnchor};
} }
@ -406,7 +406,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
CAmount jsInputValue = 0; CAmount jsInputValue = 0;
uint256 jsAnchor; uint256 jsAnchor;
std::vector<boost::optional<ZCIncrementalWitness>> witnesses; std::vector<boost::optional<SproutWitness>> witnesses;
JSDescription prevJoinSplit; JSDescription prevJoinSplit;
@ -437,7 +437,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
} }
assert(changeOutputIndex != -1); assert(changeOutputIndex != -1);
boost::optional<ZCIncrementalWitness> changeWitness; boost::optional<SproutWitness> changeWitness;
int n = 0; int n = 0;
for (const uint256& commitment : prevJoinSplit.commitments) { for (const uint256& commitment : prevJoinSplit.commitments) {
tree.append(commitment); tree.append(commitment);
@ -487,7 +487,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
std::vector<SproutNote> vInputNotes; std::vector<SproutNote> vInputNotes;
std::vector<SproutSpendingKey> vInputZKeys; std::vector<SproutSpendingKey> vInputZKeys;
std::vector<JSOutPoint> vOutPoints; std::vector<JSOutPoint> vOutPoints;
std::vector<boost::optional<ZCIncrementalWitness>> vInputWitnesses; std::vector<boost::optional<SproutWitness>> vInputWitnesses;
uint256 inputAnchor; uint256 inputAnchor;
int numInputsNeeded = (jsChange > 0) ? 1 : 0; int numInputsNeeded = (jsChange > 0) ? 1 : 0;
while (numInputsNeeded++ < ZC_NUM_JS_INPUTS && zInputsDeque.size() > 0) { while (numInputsNeeded++ < ZC_NUM_JS_INPUTS && zInputsDeque.size() > 0) {
@ -544,7 +544,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
if (!optionalWitness) { if (!optionalWitness) {
throw JSONRPCError(RPC_WALLET_ERROR, "Witness for note commitment is null"); 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) { if (jsChange > 0) {
for (const uint256& commitment : previousCommitments) { for (const uint256& commitment : previousCommitments) {
w.append(commitment); w.append(commitment);
@ -695,7 +695,7 @@ void AsyncRPCOperation_mergetoaddress::sign_send_raw_transaction(UniValue obj)
UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(MergeToAddressJSInfo& info) UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(MergeToAddressJSInfo& info)
{ {
std::vector<boost::optional<ZCIncrementalWitness>> witnesses; std::vector<boost::optional<SproutWitness>> witnesses;
uint256 anchor; uint256 anchor;
{ {
LOCK(cs_main); LOCK(cs_main);
@ -707,7 +707,7 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(MergeToAddressJSInf
UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(MergeToAddressJSInfo& info, std::vector<JSOutPoint>& outPoints) UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(MergeToAddressJSInfo& info, std::vector<JSOutPoint>& outPoints)
{ {
std::vector<boost::optional<ZCIncrementalWitness>> witnesses; std::vector<boost::optional<SproutWitness>> witnesses;
uint256 anchor; uint256 anchor;
{ {
LOCK(cs_main); LOCK(cs_main);
@ -718,7 +718,7 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(MergeToAddressJSInf
UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit( UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(
MergeToAddressJSInfo& info, MergeToAddressJSInfo& info,
std::vector<boost::optional<ZCIncrementalWitness>> witnesses, std::vector<boost::optional<SproutWitness>> witnesses,
uint256 anchor) uint256 anchor)
{ {
if (anchor.IsNull()) { if (anchor.IsNull()) {

6
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 // A struct to help us track the witness and anchor for a given JSOutPoint
struct MergeToAddressWitnessAnchorData { struct MergeToAddressWitnessAnchorData {
boost::optional<ZCIncrementalWitness> witness; boost::optional<SproutWitness> witness;
uint256 anchor; uint256 anchor;
}; };
@ -112,7 +112,7 @@ private:
// JoinSplit where you have the witnesses and anchor // JoinSplit where you have the witnesses and anchor
UniValue perform_joinsplit( UniValue perform_joinsplit(
MergeToAddressJSInfo& info, MergeToAddressJSInfo& info,
std::vector<boost::optional<ZCIncrementalWitness>> witnesses, std::vector<boost::optional<SproutWitness>> witnesses,
uint256 anchor); uint256 anchor);
void sign_send_raw_transaction(UniValue obj); // throws exception if there was an error void sign_send_raw_transaction(UniValue obj); // throws exception if there was an error
@ -172,7 +172,7 @@ public:
UniValue perform_joinsplit( UniValue perform_joinsplit(
MergeToAddressJSInfo& info, MergeToAddressJSInfo& info,
std::vector<boost::optional<ZCIncrementalWitness>> witnesses, std::vector<boost::optional<SproutWitness>> witnesses,
uint256 anchor) uint256 anchor)
{ {
return delegate->perform_joinsplit(info, witnesses, anchor); return delegate->perform_joinsplit(info, witnesses, anchor);

16
src/wallet/asyncrpcoperation_sendmany.cpp

@ -419,7 +419,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
JSOutPoint jso = std::get<0>(t); JSOutPoint jso = std::get<0>(t);
std::vector<JSOutPoint> vOutPoints = { jso }; std::vector<JSOutPoint> vOutPoints = { jso };
uint256 inputAnchor; uint256 inputAnchor;
std::vector<boost::optional<ZCIncrementalWitness>> vInputWitnesses; std::vector<boost::optional<SproutWitness>> vInputWitnesses;
pwalletMain->GetSproutNoteWitnesses(vOutPoints, vInputWitnesses, inputAnchor); pwalletMain->GetSproutNoteWitnesses(vOutPoints, vInputWitnesses, inputAnchor);
jsopWitnessAnchorMap[ jso.ToString() ] = WitnessAnchorData{ vInputWitnesses[0], inputAnchor }; jsopWitnessAnchorMap[ jso.ToString() ] = WitnessAnchorData{ vInputWitnesses[0], inputAnchor };
} }
@ -526,7 +526,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
CAmount jsInputValue = 0; CAmount jsInputValue = 0;
uint256 jsAnchor; uint256 jsAnchor;
std::vector<boost::optional<ZCIncrementalWitness>> witnesses; std::vector<boost::optional<SproutWitness>> witnesses;
JSDescription prevJoinSplit; JSDescription prevJoinSplit;
@ -557,7 +557,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
} }
assert(changeOutputIndex != -1); assert(changeOutputIndex != -1);
boost::optional<ZCIncrementalWitness> changeWitness; boost::optional<SproutWitness> changeWitness;
int n = 0; int n = 0;
for (const uint256& commitment : prevJoinSplit.commitments) { for (const uint256& commitment : prevJoinSplit.commitments) {
tree.append(commitment); tree.append(commitment);
@ -606,7 +606,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
// //
std::vector<SproutNote> vInputNotes; std::vector<SproutNote> vInputNotes;
std::vector<JSOutPoint> vOutPoints; std::vector<JSOutPoint> vOutPoints;
std::vector<boost::optional<ZCIncrementalWitness>> vInputWitnesses; std::vector<boost::optional<SproutWitness>> vInputWitnesses;
uint256 inputAnchor; uint256 inputAnchor;
int numInputsNeeded = (jsChange>0) ? 1 : 0; int numInputsNeeded = (jsChange>0) ? 1 : 0;
while (numInputsNeeded++ < ZC_NUM_JS_INPUTS && zInputsDeque.size() > 0) { while (numInputsNeeded++ < ZC_NUM_JS_INPUTS && zInputsDeque.size() > 0) {
@ -663,7 +663,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
if (!optionalWitness) { if (!optionalWitness) {
throw JSONRPCError(RPC_WALLET_ERROR, "Witness for note commitment is null"); 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) { if (jsChange > 0) {
for (const uint256& commitment : previousCommitments) { for (const uint256& commitment : previousCommitments) {
w.append(commitment); w.append(commitment);
@ -920,7 +920,7 @@ bool AsyncRPCOperation_sendmany::find_unspent_notes() {
} }
UniValue AsyncRPCOperation_sendmany::perform_joinsplit(AsyncJoinSplitInfo & info) { UniValue AsyncRPCOperation_sendmany::perform_joinsplit(AsyncJoinSplitInfo & info) {
std::vector<boost::optional < ZCIncrementalWitness>> witnesses; std::vector<boost::optional < SproutWitness>> witnesses;
uint256 anchor; uint256 anchor;
{ {
LOCK(cs_main); LOCK(cs_main);
@ -931,7 +931,7 @@ UniValue AsyncRPCOperation_sendmany::perform_joinsplit(AsyncJoinSplitInfo & info
UniValue AsyncRPCOperation_sendmany::perform_joinsplit(AsyncJoinSplitInfo & info, std::vector<JSOutPoint> & outPoints) { UniValue AsyncRPCOperation_sendmany::perform_joinsplit(AsyncJoinSplitInfo & info, std::vector<JSOutPoint> & outPoints) {
std::vector<boost::optional < ZCIncrementalWitness>> witnesses; std::vector<boost::optional < SproutWitness>> witnesses;
uint256 anchor; uint256 anchor;
{ {
LOCK(cs_main); LOCK(cs_main);
@ -942,7 +942,7 @@ UniValue AsyncRPCOperation_sendmany::perform_joinsplit(AsyncJoinSplitInfo & info
UniValue AsyncRPCOperation_sendmany::perform_joinsplit( UniValue AsyncRPCOperation_sendmany::perform_joinsplit(
AsyncJoinSplitInfo & info, AsyncJoinSplitInfo & info,
std::vector<boost::optional < ZCIncrementalWitness>> witnesses, std::vector<boost::optional < SproutWitness>> witnesses,
uint256 anchor) uint256 anchor)
{ {
if (anchor.IsNull()) { if (anchor.IsNull()) {

6
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 // A struct to help us track the witness and anchor for a given JSOutPoint
struct WitnessAnchorData { struct WitnessAnchorData {
boost::optional<ZCIncrementalWitness> witness; boost::optional<SproutWitness> witness;
uint256 anchor; uint256 anchor;
}; };
@ -112,7 +112,7 @@ private:
// JoinSplit where you have the witnesses and anchor // JoinSplit where you have the witnesses and anchor
UniValue perform_joinsplit( UniValue perform_joinsplit(
AsyncJoinSplitInfo & info, AsyncJoinSplitInfo & info,
std::vector<boost::optional < ZCIncrementalWitness>> witnesses, std::vector<boost::optional < SproutWitness>> witnesses,
uint256 anchor); uint256 anchor);
void sign_send_raw_transaction(UniValue obj); // throws exception if there was an error void sign_send_raw_transaction(UniValue obj); // throws exception if there was an error
@ -173,7 +173,7 @@ public:
UniValue perform_joinsplit( UniValue perform_joinsplit(
AsyncJoinSplitInfo & info, AsyncJoinSplitInfo & info,
std::vector<boost::optional < ZCIncrementalWitness>> witnesses, std::vector<boost::optional < SproutWitness>> witnesses,
uint256 anchor) uint256 anchor)
{ {
return delegate->perform_joinsplit(info, witnesses, anchor); return delegate->perform_joinsplit(info, witnesses, anchor);

36
src/wallet/gtest/test_wallet.cpp

@ -120,8 +120,8 @@ std::pair<JSOutPoint, SaplingOutPoint> CreateValidBlock(TestWallet& wallet,
std::pair<uint256, uint256> GetWitnessesAndAnchors(TestWallet& wallet, std::pair<uint256, uint256> GetWitnessesAndAnchors(TestWallet& wallet,
std::vector<JSOutPoint>& sproutNotes, std::vector<JSOutPoint>& sproutNotes,
std::vector<SaplingOutPoint>& saplingNotes, std::vector<SaplingOutPoint>& saplingNotes,
std::vector<boost::optional<ZCIncrementalWitness>>& sproutWitnesses, std::vector<boost::optional<SproutWitness>>& sproutWitnesses,
std::vector<boost::optional<ZCSaplingIncrementalWitness>>& saplingWitnesses) { std::vector<boost::optional<SaplingWitness>>& saplingWitnesses) {
sproutWitnesses.clear(); sproutWitnesses.clear();
saplingWitnesses.clear(); saplingWitnesses.clear();
uint256 sproutAnchor; uint256 sproutAnchor;
@ -585,8 +585,8 @@ TEST(wallet_tests, cached_witnesses_empty_chain) {
std::vector<JSOutPoint> sproutNotes {jsoutpt, jsoutpt2}; std::vector<JSOutPoint> sproutNotes {jsoutpt, jsoutpt2};
std::vector<SaplingOutPoint> saplingNotes = SetSaplingNoteData(wtx); std::vector<SaplingOutPoint> saplingNotes = SetSaplingNoteData(wtx);
std::vector<boost::optional<ZCIncrementalWitness>> sproutWitnesses; std::vector<boost::optional<SproutWitness>> sproutWitnesses;
std::vector<boost::optional<ZCSaplingIncrementalWitness>> saplingWitnesses; std::vector<boost::optional<SaplingWitness>> saplingWitnesses;
::GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses); ::GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses);
@ -639,8 +639,8 @@ TEST(wallet_tests, cached_witnesses_chain_tip) {
// Called to fetch anchor // Called to fetch anchor
std::vector<JSOutPoint> sproutNotes {outpts.first}; std::vector<JSOutPoint> sproutNotes {outpts.first};
std::vector<SaplingOutPoint> saplingNotes {outpts.second}; std::vector<SaplingOutPoint> saplingNotes {outpts.second};
std::vector<boost::optional<ZCIncrementalWitness>> sproutWitnesses; std::vector<boost::optional<SproutWitness>> sproutWitnesses;
std::vector<boost::optional<ZCSaplingIncrementalWitness>> saplingWitnesses; std::vector<boost::optional<SaplingWitness>> saplingWitnesses;
anchors1 = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses); anchors1 = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses);
EXPECT_NE(anchors1.first, anchors1.second); EXPECT_NE(anchors1.first, anchors1.second);
@ -661,8 +661,8 @@ TEST(wallet_tests, cached_witnesses_chain_tip) {
wallet.AddToWallet(wtx, true, NULL); wallet.AddToWallet(wtx, true, NULL);
std::vector<JSOutPoint> sproutNotes {jsoutpt}; std::vector<JSOutPoint> sproutNotes {jsoutpt};
std::vector<boost::optional<ZCIncrementalWitness>> sproutWitnesses; std::vector<boost::optional<SproutWitness>> sproutWitnesses;
std::vector<boost::optional<ZCSaplingIncrementalWitness>> saplingWitnesses; std::vector<boost::optional<SaplingWitness>> saplingWitnesses;
GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, 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 // Incrementing with the same block again should not change the cache
wallet.IncrementNoteWitnesses(&index2, &block2, sproutTree, saplingTree); wallet.IncrementNoteWitnesses(&index2, &block2, sproutTree, saplingTree);
std::vector<boost::optional<ZCIncrementalWitness>> sproutWitnesses5; std::vector<boost::optional<SproutWitness>> sproutWitnesses5;
std::vector<boost::optional<ZCSaplingIncrementalWitness>> saplingWitnesses5; std::vector<boost::optional<SaplingWitness>> saplingWitnesses5;
auto anchors5 = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses5, saplingWitnesses5); auto anchors5 = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses5, saplingWitnesses5);
EXPECT_NE(anchors5.first, anchors5.second); EXPECT_NE(anchors5.first, anchors5.second);
@ -750,8 +750,8 @@ TEST(wallet_tests, CachedWitnessesDecrementFirst) {
// Called to fetch anchor // Called to fetch anchor
std::vector<JSOutPoint> sproutNotes {outpts.first}; std::vector<JSOutPoint> sproutNotes {outpts.first};
std::vector<SaplingOutPoint> saplingNotes {outpts.second}; std::vector<SaplingOutPoint> saplingNotes {outpts.second};
std::vector<boost::optional<ZCIncrementalWitness>> sproutWitnesses; std::vector<boost::optional<SproutWitness>> sproutWitnesses;
std::vector<boost::optional<ZCSaplingIncrementalWitness>> saplingWitnesses; std::vector<boost::optional<SaplingWitness>> saplingWitnesses;
anchors2 = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses); anchors2 = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses);
} }
@ -770,8 +770,8 @@ TEST(wallet_tests, CachedWitnessesDecrementFirst) {
wallet.AddToWallet(wtx, true, NULL); wallet.AddToWallet(wtx, true, NULL);
std::vector<JSOutPoint> sproutNotes {jsoutpt}; std::vector<JSOutPoint> sproutNotes {jsoutpt};
std::vector<boost::optional<ZCIncrementalWitness>> sproutWitnesses; std::vector<boost::optional<SproutWitness>> sproutWitnesses;
std::vector<boost::optional<ZCSaplingIncrementalWitness>> saplingWitnesses; std::vector<boost::optional<SaplingWitness>> saplingWitnesses;
auto anchors3 = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses); auto anchors3 = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses);
@ -814,8 +814,8 @@ TEST(wallet_tests, CachedWitnessesCleanIndex) {
SproutMerkleTree sproutRiTree = sproutTree; SproutMerkleTree sproutRiTree = sproutTree;
SaplingMerkleTree saplingTree; SaplingMerkleTree saplingTree;
SaplingMerkleTree saplingRiTree = saplingTree; SaplingMerkleTree saplingRiTree = saplingTree;
std::vector<boost::optional<ZCIncrementalWitness>> sproutWitnesses; std::vector<boost::optional<SproutWitness>> sproutWitnesses;
std::vector<boost::optional<ZCSaplingIncrementalWitness>> saplingWitnesses; std::vector<boost::optional<SaplingWitness>> saplingWitnesses;
auto sk = libzcash::SproutSpendingKey::random(); auto sk = libzcash::SproutSpendingKey::random();
wallet.AddSpendingKey(sk); wallet.AddSpendingKey(sk);
@ -922,8 +922,8 @@ TEST(wallet_tests, ClearNoteWitnessCache) {
wallet.AddToWallet(wtx, true, NULL); wallet.AddToWallet(wtx, true, NULL);
std::vector<JSOutPoint> sproutNotes {jsoutpt, jsoutpt2}; std::vector<JSOutPoint> sproutNotes {jsoutpt, jsoutpt2};
std::vector<boost::optional<ZCIncrementalWitness>> sproutWitnesses; std::vector<boost::optional<SproutWitness>> sproutWitnesses;
std::vector<boost::optional<ZCSaplingIncrementalWitness>> saplingWitnesses; std::vector<boost::optional<SaplingWitness>> saplingWitnesses;
// Before clearing, we should have a witness for one note // Before clearing, we should have a witness for one note
GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses); GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses);

4
src/wallet/rpcwallet.cpp

@ -2843,7 +2843,7 @@ UniValue zc_raw_receive(const UniValue& params, bool fHelp)
SproutNote decrypted_note = npt.note(payment_addr); SproutNote decrypted_note = npt.note(payment_addr);
assert(pwalletMain != NULL); assert(pwalletMain != NULL);
std::vector<boost::optional<ZCIncrementalWitness>> witnesses; std::vector<boost::optional<SproutWitness>> witnesses;
uint256 anchor; uint256 anchor;
uint256 commitment = decrypted_note.cm(); uint256 commitment = decrypted_note.cm();
pwalletMain->WitnessNoteCommitment( pwalletMain->WitnessNoteCommitment(
@ -2944,7 +2944,7 @@ UniValue zc_raw_joinsplit(const UniValue& params, bool fHelp)
} }
uint256 anchor; uint256 anchor;
std::vector<boost::optional<ZCIncrementalWitness>> witnesses; std::vector<boost::optional<SproutWitness>> witnesses;
pwalletMain->WitnessNoteCommitment(commitments, witnesses, anchor); pwalletMain->WitnessNoteCommitment(commitments, witnesses, anchor);
assert(witnesses.size() == notes.size()); assert(witnesses.size() == notes.size());

10
src/wallet/wallet.cpp

@ -1470,7 +1470,7 @@ bool CWallet::IsFromMe(const uint256& nullifier) const
} }
void CWallet::GetSproutNoteWitnesses(std::vector<JSOutPoint> notes, void CWallet::GetSproutNoteWitnesses(std::vector<JSOutPoint> notes,
std::vector<boost::optional<ZCIncrementalWitness>>& witnesses, std::vector<boost::optional<SproutWitness>>& witnesses,
uint256 &final_anchor) uint256 &final_anchor)
{ {
LOCK(cs_wallet); LOCK(cs_wallet);
@ -1497,7 +1497,7 @@ void CWallet::GetSproutNoteWitnesses(std::vector<JSOutPoint> notes,
} }
void CWallet::GetSaplingNoteWitnesses(std::vector<SaplingOutPoint> notes, void CWallet::GetSaplingNoteWitnesses(std::vector<SaplingOutPoint> notes,
std::vector<boost::optional<ZCSaplingIncrementalWitness>>& witnesses, std::vector<boost::optional<SaplingWitness>>& witnesses,
uint256 &final_anchor) uint256 &final_anchor)
{ {
LOCK(cs_wallet); LOCK(cs_wallet);
@ -1888,7 +1888,7 @@ bool CWalletTx::WriteToDisk(CWalletDB *pwalletdb)
} }
void CWallet::WitnessNoteCommitment(std::vector<uint256> commitments, void CWallet::WitnessNoteCommitment(std::vector<uint256> commitments,
std::vector<boost::optional<ZCIncrementalWitness>>& witnesses, std::vector<boost::optional<SproutWitness>>& witnesses,
uint256 &final_anchor) uint256 &final_anchor)
{ {
witnesses.resize(commitments.size()); witnesses.resize(commitments.size());
@ -1907,7 +1907,7 @@ void CWallet::WitnessNoteCommitment(std::vector<uint256> commitments,
{ {
tree.append(note_commitment); tree.append(note_commitment);
BOOST_FOREACH(boost::optional<ZCIncrementalWitness>& wit, witnesses) { BOOST_FOREACH(boost::optional<SproutWitness>& wit, witnesses) {
if (wit) { if (wit) {
wit->append(note_commitment); wit->append(note_commitment);
} }
@ -1937,7 +1937,7 @@ void CWallet::WitnessNoteCommitment(std::vector<uint256> commitments,
// TODO: #93; Select a root via some heuristic. // TODO: #93; Select a root via some heuristic.
final_anchor = tree.root(); final_anchor = tree.root();
BOOST_FOREACH(boost::optional<ZCIncrementalWitness>& wit, witnesses) { BOOST_FOREACH(boost::optional<SproutWitness>& wit, witnesses) {
if (wit) { if (wit) {
assert(final_anchor == wit->root()); assert(final_anchor == wit->root());
} }

10
src/wallet/wallet.h

@ -220,7 +220,7 @@ public:
* Cached incremental witnesses for spendable Notes. * Cached incremental witnesses for spendable Notes.
* Beginning of the list is the most recent witness. * Beginning of the list is the most recent witness.
*/ */
std::list<ZCIncrementalWitness> witnesses; std::list<SproutWitness> witnesses;
/** /**
* Block height corresponding to the most current witness. * Block height corresponding to the most current witness.
@ -272,7 +272,7 @@ public:
*/ */
SaplingNoteData() : witnessHeight {-1} { } SaplingNoteData() : witnessHeight {-1} { }
std::list<ZCSaplingIncrementalWitness> witnesses; std::list<SaplingWitness> witnesses;
int witnessHeight; int witnessHeight;
}; };
@ -1033,7 +1033,7 @@ public:
void EraseFromWallet(const uint256 &hash); void EraseFromWallet(const uint256 &hash);
void WitnessNoteCommitment( void WitnessNoteCommitment(
std::vector<uint256> commitments, std::vector<uint256> commitments,
std::vector<boost::optional<ZCIncrementalWitness>>& witnesses, std::vector<boost::optional<SproutWitness>>& witnesses,
uint256 &final_anchor); uint256 &final_anchor);
int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false); int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false);
void ReacceptWalletTransactions(); void ReacceptWalletTransactions();
@ -1077,11 +1077,11 @@ public:
bool IsFromMe(const uint256& nullifier) const; bool IsFromMe(const uint256& nullifier) const;
void GetSproutNoteWitnesses( void GetSproutNoteWitnesses(
std::vector<JSOutPoint> notes, std::vector<JSOutPoint> notes,
std::vector<boost::optional<ZCIncrementalWitness>>& witnesses, std::vector<boost::optional<SproutWitness>>& witnesses,
uint256 &final_anchor); uint256 &final_anchor);
void GetSaplingNoteWitnesses( void GetSaplingNoteWitnesses(
std::vector<SaplingOutPoint> notes, std::vector<SaplingOutPoint> notes,
std::vector<boost::optional<ZCSaplingIncrementalWitness>>& witnesses, std::vector<boost::optional<SaplingWitness>>& witnesses,
uint256 &final_anchor); uint256 &final_anchor);
isminetype IsMine(const CTxIn& txin) const; isminetype IsMine(const CTxIn& txin) const;

4
src/zcash/IncrementalMerkleTree.hpp

@ -251,13 +251,13 @@ EmptyMerkleRoots<Depth, Hash> IncrementalMerkleTree<Depth, Hash>::emptyroots;
typedef libzcash::IncrementalMerkleTree<INCREMENTAL_MERKLE_TREE_DEPTH, libzcash::SHA256Compress> SproutMerkleTree; typedef libzcash::IncrementalMerkleTree<INCREMENTAL_MERKLE_TREE_DEPTH, libzcash::SHA256Compress> SproutMerkleTree;
typedef libzcash::IncrementalMerkleTree<INCREMENTAL_MERKLE_TREE_DEPTH_TESTING, libzcash::SHA256Compress> ZCTestingIncrementalMerkleTree; typedef libzcash::IncrementalMerkleTree<INCREMENTAL_MERKLE_TREE_DEPTH_TESTING, libzcash::SHA256Compress> ZCTestingIncrementalMerkleTree;
typedef libzcash::IncrementalWitness<INCREMENTAL_MERKLE_TREE_DEPTH, libzcash::SHA256Compress> ZCIncrementalWitness; typedef libzcash::IncrementalWitness<INCREMENTAL_MERKLE_TREE_DEPTH, libzcash::SHA256Compress> SproutWitness;
typedef libzcash::IncrementalWitness<INCREMENTAL_MERKLE_TREE_DEPTH_TESTING, libzcash::SHA256Compress> ZCTestingIncrementalWitness; typedef libzcash::IncrementalWitness<INCREMENTAL_MERKLE_TREE_DEPTH_TESTING, libzcash::SHA256Compress> ZCTestingIncrementalWitness;
typedef libzcash::IncrementalMerkleTree<SAPLING_INCREMENTAL_MERKLE_TREE_DEPTH, libzcash::PedersenHash> SaplingMerkleTree; typedef libzcash::IncrementalMerkleTree<SAPLING_INCREMENTAL_MERKLE_TREE_DEPTH, libzcash::PedersenHash> SaplingMerkleTree;
typedef libzcash::IncrementalMerkleTree<INCREMENTAL_MERKLE_TREE_DEPTH_TESTING, libzcash::PedersenHash> ZCSaplingTestingIncrementalMerkleTree; typedef libzcash::IncrementalMerkleTree<INCREMENTAL_MERKLE_TREE_DEPTH_TESTING, libzcash::PedersenHash> ZCSaplingTestingIncrementalMerkleTree;
typedef libzcash::IncrementalWitness<SAPLING_INCREMENTAL_MERKLE_TREE_DEPTH, libzcash::PedersenHash> ZCSaplingIncrementalWitness; typedef libzcash::IncrementalWitness<SAPLING_INCREMENTAL_MERKLE_TREE_DEPTH, libzcash::PedersenHash> SaplingWitness;
typedef libzcash::IncrementalWitness<INCREMENTAL_MERKLE_TREE_DEPTH_TESTING, libzcash::PedersenHash> ZCSaplingTestingIncrementalWitness; typedef libzcash::IncrementalWitness<INCREMENTAL_MERKLE_TREE_DEPTH_TESTING, libzcash::PedersenHash> ZCSaplingTestingIncrementalWitness;
#endif /* ZC_INCREMENTALMERKLETREE_H_ */ #endif /* ZC_INCREMENTALMERKLETREE_H_ */

4
src/zcash/JoinSplit.hpp

@ -25,12 +25,12 @@ typedef boost::variant<PHGRProof, GrothProof> SproutProof;
class JSInput { class JSInput {
public: public:
ZCIncrementalWitness witness; SproutWitness witness;
SproutNote note; SproutNote note;
SproutSpendingKey key; SproutSpendingKey key;
JSInput(); JSInput();
JSInput(ZCIncrementalWitness witness, JSInput(SproutWitness witness,
SproutNote note, SproutNote note,
SproutSpendingKey key) : witness(witness), note(note), key(key) { } SproutSpendingKey key) : witness(witness), note(note), key(key) { }

Loading…
Cancel
Save