]> Git Repo - VerusCoin.git/commitdiff
Refactoring: SproutNote member variable value moved to BaseNote.
authorSimon <[email protected]>
Wed, 25 Apr 2018 20:32:13 +0000 (13:32 -0700)
committerSimon <[email protected]>
Thu, 26 Apr 2018 22:05:19 +0000 (15:05 -0700)
All notes have a value, so the member variable has been moved to the
base class, and direct member access has been replaced with a getter.

src/gtest/test_joinsplit.cpp
src/utiltest.cpp
src/wallet/asyncrpcoperation_mergetoaddress.cpp
src/wallet/asyncrpcoperation_sendmany.cpp
src/wallet/asyncrpcoperation_shieldcoinbase.cpp
src/wallet/rpcwallet.cpp
src/zcash/JoinSplit.cpp
src/zcash/Note.cpp
src/zcash/Note.hpp
src/zcash/circuit/gadget.tcc
src/zcash/circuit/note.tcc

index a9814e4ab9a14c58dd26676929f8f82b1958fadb..d238e4b94b9bacaf84b92d2c529463714f0c86c1 100644 (file)
@@ -101,7 +101,7 @@ void test_full_api(ZCJoinSplit* js)
 
     auto decrypted_note = note_pt.note(recipient_addr);
 
-    ASSERT_TRUE(decrypted_note.value == 10);
+    ASSERT_TRUE(decrypted_note.value() == 10);
 
     // Insert the commitments from the last tx into the tree
     tree.append(commitments[0]);
@@ -543,7 +543,7 @@ TEST(joinsplit, note_plaintexts)
     ASSERT_TRUE(decrypted_note.a_pk == note.a_pk);
     ASSERT_TRUE(decrypted_note.rho == note.rho);
     ASSERT_TRUE(decrypted_note.r == note.r);
-    ASSERT_TRUE(decrypted_note.value == note.value);
+    ASSERT_TRUE(decrypted_note.value() == note.value());
 
     ASSERT_TRUE(decrypted.memo == note_pt.memo);
 }
index 8245adf8e4eb156b0d5a278610181d0b713ffbfa..60af4f7dd30a61d2fe5e14bcef408fa6ca04e02f 100644 (file)
@@ -98,14 +98,14 @@ CWalletTx GetValidSpend(ZCJoinSplit& params,
     libzcash::JSInput dummyin;
 
     {
-        if (note.value > value) {
+        if (note.value() > value) {
             libzcash::SpendingKey dummykey = libzcash::SpendingKey::random();
             libzcash::PaymentAddress dummyaddr = dummykey.address();
-            dummyout = libzcash::JSOutput(dummyaddr, note.value - value);
-        } else if (note.value < value) {
+            dummyout = libzcash::JSOutput(dummyaddr, note.value() - value);
+        } else if (note.value() < value) {
             libzcash::SpendingKey dummykey = libzcash::SpendingKey::random();
             libzcash::PaymentAddress dummyaddr = dummykey.address();
-            libzcash::SproutNote dummynote(dummyaddr.a_pk, (value - note.value), uint256(), uint256());
+            libzcash::SproutNote dummynote(dummyaddr.a_pk, (value - note.value()), uint256(), uint256());
             tree.append(dummynote.cm());
             dummyin = libzcash::JSInput(tree.witness(), dummynote, dummykey);
         }
index 6e6d3c7d0995aa107aae3f58b0d96b8bc534dc5a..b2d9eb4abf48ed64b0af94f8408c6f2f5bdf2833 100644 (file)
@@ -753,7 +753,7 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(
              getId(),
              tx_.vjoinsplit.size(),
              FormatMoney(info.vpub_old), FormatMoney(info.vpub_new),
-             FormatMoney(info.vjsin[0].note.value), FormatMoney(info.vjsin[1].note.value),
+             FormatMoney(info.vjsin[0].note.value()), FormatMoney(info.vjsin[1].note.value()),
              FormatMoney(info.vjsout[0].value), FormatMoney(info.vjsout[1].value));
 
     // Generate the proof, this can take over a minute.
index de6da102f14df7cfc920d7ff53fee1f10502767d..42805b5e6b5909473ac9af45b6298cd08338b36e 100644 (file)
@@ -968,7 +968,7 @@ UniValue AsyncRPCOperation_sendmany::perform_joinsplit(
             getId(),
             tx_.vjoinsplit.size(),
             FormatMoney(info.vpub_old), FormatMoney(info.vpub_new),
-            FormatMoney(info.vjsin[0].note.value), FormatMoney(info.vjsin[1].note.value),
+            FormatMoney(info.vjsin[0].note.value()), FormatMoney(info.vjsin[1].note.value()),
             FormatMoney(info.vjsout[0].value), FormatMoney(info.vjsout[1].value)
             );
 
index b7ace4dd56d731ba3e7fcdafc7c95d0e29c4f87a..dcadc6a785e6fbd030d99043502f45f2fe58e5b1 100644 (file)
@@ -341,7 +341,7 @@ UniValue AsyncRPCOperation_shieldcoinbase::perform_joinsplit(ShieldCoinbaseJSInf
             getId(),
             tx_.vjoinsplit.size(),
             FormatMoney(info.vpub_old), FormatMoney(info.vpub_new),
-            FormatMoney(info.vjsin[0].note.value), FormatMoney(info.vjsin[1].note.value),
+            FormatMoney(info.vjsin[0].note.value()), FormatMoney(info.vjsin[1].note.value()),
             FormatMoney(info.vjsout[0].value), FormatMoney(info.vjsout[1].value)
             );
 
index 3b237a7ce1eafd9861394882b35d95e98d66a6e7..0463c07e5bf42b8f443c59599161624109fff54f 100644 (file)
@@ -2833,7 +2833,7 @@ UniValue zc_raw_receive(const UniValue& params, bool fHelp)
     ss << npt;
 
     UniValue result(UniValue::VOBJ);
-    result.push_back(Pair("amount", ValueFromAmount(decrypted_note.value)));
+    result.push_back(Pair("amount", ValueFromAmount(decrypted_note.value())));
     result.push_back(Pair("note", HexStr(ss.begin(), ss.end())));
     result.push_back(Pair("exists", (bool) witnesses[0]));
     return result;
index 2d7ed115375b83bdcec03ae34e8587a3520ab747..5751d1c6d01a742af2dee791236fa15ff7f6a308 100644 (file)
@@ -168,7 +168,7 @@ public:
             // Sanity checks of input
             {
                 // If note has nonzero value
-                if (inputs[i].note.value != 0) {
+                if (inputs[i].note.value() != 0) {
                     // The witness root must equal the input root.
                     if (inputs[i].witness.root() != rt) {
                         throw std::invalid_argument("joinsplit not anchored to the correct root");
@@ -186,11 +186,11 @@ public:
                 }
 
                 // Balance must be sensical
-                if (inputs[i].note.value > MAX_MONEY) {
+                if (inputs[i].note.value() > MAX_MONEY) {
                     throw std::invalid_argument("nonsensical input note value");
                 }
 
-                lhs_value += inputs[i].note.value;
+                lhs_value += inputs[i].note.value();
 
                 if (lhs_value > MAX_MONEY) {
                     throw std::invalid_argument("nonsensical left hand size of joinsplit balance");
index c16a225ffb9f9c06f7e38d1ee7c7de8e139d935b..5b1ccf51ddf17003ef647f1fbd229f28ab6e3672 100644 (file)
@@ -13,7 +13,6 @@ SproutNote::SproutNote() {
     a_pk = random_uint256();
     rho = random_uint256();
     r = random_uint256();
-    value = 0;
 }
 
 uint256 SproutNote::cm() const {
@@ -23,7 +22,7 @@ uint256 SproutNote::cm() const {
     hasher.Write(&discriminant, 1);
     hasher.Write(a_pk.begin(), 32);
 
-    auto value_vec = convertIntToVectorLE(value);
+    auto value_vec = convertIntToVectorLE(value_);
 
     hasher.Write(&value_vec[0], value_vec.size());
     hasher.Write(rho.begin(), 32);
@@ -43,7 +42,7 @@ NotePlaintext::NotePlaintext(
     const SproutNote& note,
     boost::array<unsigned char, ZC_MEMO_SIZE> memo) : memo(memo)
 {
-    value = note.value;
+    value = note.value();
     rho = note.rho;
     r = note.r;
 }
index 623fdbb6c5fc14be15d9b7d5d57020877b7fc9aa..f4cd4e0f64efbef48abbe8a2c0918f182d3fdcd6 100644 (file)
@@ -9,19 +9,23 @@
 namespace libzcash {
 
 class BaseNote {
+protected:
+    uint64_t value_ = 0;
 public:
+    BaseNote() {}
+    BaseNote(uint64_t value) : value_(value) {};
     virtual uint256 cm() const {};
+    inline uint64_t value() const { return value_; };
 };
 
 class SproutNote : public BaseNote {
 public:
     uint256 a_pk;
-    uint64_t value;
     uint256 rho;
     uint256 r;
 
     SproutNote(uint256 a_pk, uint64_t value, uint256 rho, uint256 r)
-        : a_pk(a_pk), value(value), rho(rho), r(r) {}
+        : BaseNote(value), a_pk(a_pk), rho(rho), r(r) {}
 
     SproutNote();
 
index d13c05962e680feda6f472b8b86201e99978b927..6d057459f77bf66f4651033edb5390eda804a974 100644 (file)
@@ -222,7 +222,7 @@ public:
             // Witness total_uint64 bits
             uint64_t left_side_acc = vpub_old;
             for (size_t i = 0; i < NumInputs; i++) {
-                left_side_acc += inputs[i].note.value;
+                left_side_acc += inputs[i].note.value();
             }
 
             zk_total_uint64.fill_with_bits(
index 69526ec71b9019edc34f7cb03f3affa18c90de5d..d1534ec4b68c33f92bf96a754d85f0da4cb52642 100644 (file)
@@ -23,7 +23,7 @@ public:
 
     void generate_r1cs_witness(const SproutNote& note) {
         r->bits.fill_with_bits(this->pb, uint256_to_bool_vector(note.r));
-        value.fill_with_bits(this->pb, uint64_to_bool_vector(note.value));
+        value.fill_with_bits(this->pb, uint64_to_bool_vector(note.value()));
     }
 };
 
@@ -158,7 +158,7 @@ public:
         );
 
         // Set enforce flag for nonzero input value
-        this->pb.val(value_enforce) = (note.value != 0) ? FieldT::one() : FieldT::zero();
+        this->pb.val(value_enforce) = (note.value() != 0) ? FieldT::one() : FieldT::zero();
 
         // Witness merkle tree authentication path
         witness_input->generate_r1cs_witness(path);
This page took 0.040787 seconds and 4 git commands to generate.