diff --git a/src/gtest/test_sapling_note.cpp b/src/gtest/test_sapling_note.cpp index e54bfb0ac..de06b54c1 100644 --- a/src/gtest/test_sapling_note.cpp +++ b/src/gtest/test_sapling_note.cpp @@ -45,7 +45,7 @@ TEST(SaplingNote, TestVectors) // Test commitment SaplingNote note = SaplingNote(diversifier, pk_d, v, r); - ASSERT_EQ(note.cm(), cm); + ASSERT_EQ(note.cm().get(), cm); // Test nullifier SaplingSpendingKey spendingKey(sk); diff --git a/src/zcash/Note.cpp b/src/zcash/Note.cpp index be074dab9..d84a98067 100644 --- a/src/zcash/Note.cpp +++ b/src/zcash/Note.cpp @@ -9,7 +9,7 @@ #include "zcash/util.h" #include "librustzcash.h" -namespace libzcash { +using namespace libzcash; SproutNote::SproutNote() { a_pk = random_uint256(); @@ -48,7 +48,7 @@ SaplingNote::SaplingNote(const SaplingPaymentAddress& address, const uint64_t va } // Call librustzcash to compute the commitment -uint256 SaplingNote::cm() const { +boost::optional SaplingNote::cm() const { uint256 result; if (!librustzcash_sapling_compute_cm( d.data(), @@ -58,14 +58,14 @@ uint256 SaplingNote::cm() const { result.begin() )) { - throw std::runtime_error("librustzcash_sapling_compute_cm returned false"); + return boost::none; } return result; } // Call librustzcash to compute the nullifier -uint256 SaplingNote::nullifier(const SaplingSpendingKey& sk, const uint64_t position) const +boost::optional SaplingNote::nullifier(const SaplingSpendingKey& sk, const uint64_t position) const { auto vk = sk.full_viewing_key(); auto ak = vk.ak; @@ -83,7 +83,7 @@ uint256 SaplingNote::nullifier(const SaplingSpendingKey& sk, const uint64_t posi result.begin() )) { - throw std::runtime_error("librustzcash_sapling_compute_nf returned false"); + return boost::none; } return result; @@ -137,5 +137,3 @@ ZCNoteEncryption::Ciphertext SproutNotePlaintext::encrypt(ZCNoteEncryption& encr return encryptor.encrypt(pk_enc, pt); } - -} \ No newline at end of file diff --git a/src/zcash/Note.hpp b/src/zcash/Note.hpp index 23cbf8b30..39610fce0 100644 --- a/src/zcash/Note.hpp +++ b/src/zcash/Note.hpp @@ -7,6 +7,7 @@ #include "NoteEncryption.hpp" #include +#include namespace libzcash { @@ -18,7 +19,6 @@ public: BaseNote(uint64_t value) : value_(value) {}; virtual ~BaseNote() {}; - virtual uint256 cm() const = 0; inline uint64_t value() const { return value_; }; }; @@ -35,7 +35,7 @@ public: virtual ~SproutNote() {}; - virtual uint256 cm() const override; + uint256 cm() const; uint256 nullifier(const SproutSpendingKey& a_sk) const; }; @@ -56,9 +56,8 @@ public: virtual ~SaplingNote() {}; - virtual uint256 cm() const override; - - uint256 nullifier(const SaplingSpendingKey &sk, const uint64_t position) const; + boost::optional cm() const; + boost::optional nullifier(const SaplingSpendingKey &sk, const uint64_t position) const; }; class BaseNotePlaintext {