diff --git a/src/zcash/address/unified.cpp b/src/zcash/address/unified.cpp index 27067e6b1..d72a8686e 100644 --- a/src/zcash/address/unified.cpp +++ b/src/zcash/address/unified.cpp @@ -39,8 +39,17 @@ ZcashdUnifiedFullViewingKey ZcashdUnifiedSpendingKey::ToFullViewingKey() const { return ufvk; } -std::optional ZcashdUnifiedFullViewingKey::Address(diversifier_index_t j) const { - ZcashdUnifiedAddress ua; +std::optional ZcashdUnifiedFullViewingKey::Address(diversifier_index_t j) const { + UnifiedAddress ua; + + if (saplingKey.has_value()) { + auto saplingAddress = saplingKey.value().Address(j); + if (saplingAddress.has_value()) { + ua.AddReceiver(saplingAddress.value()); + } else { + return std::nullopt; + } + } if (transparentKey.has_value()) { auto childIndex = j.ToTransparentChildIndex(); @@ -53,16 +62,7 @@ std::optional ZcashdUnifiedFullViewingKey::Address(diversi CExtPubKey childKey; if (externalKey.Derive(childKey, childIndex.value())) { - ua.transparentAddress = childKey.pubkey.GetID(); - } else { - return std::nullopt; - } - } - - if (saplingKey.has_value()) { - auto saplingAddress = saplingKey.value().Address(j); - if (saplingAddress.has_value()) { - ua.saplingAddress = saplingAddress.value(); + ua.AddReceiver(childKey.pubkey.GetID()); } else { return std::nullopt; } diff --git a/src/zcash/address/unified.h b/src/zcash/address/unified.h index 08269b771..be87a8d6b 100644 --- a/src/zcash/address/unified.h +++ b/src/zcash/address/unified.h @@ -7,31 +7,13 @@ #include "zip32.h" #include "bip44.h" +#include "zcash/Address.hpp" namespace libzcash { class ZcashdUnifiedSpendingKey; class ZcashdUnifiedFullViewingKey; -class ZcashdUnifiedAddress { -private: - diversifier_index_t diversifier_index; - std::optional transparentAddress; - std::optional saplingAddress; - - friend class ZcashdUnifiedFullViewingKey; - - ZcashdUnifiedAddress() {} -public: - const std::optional& GetTransparentAddress() const { - return transparentAddress; - } - - const std::optional& GetSaplingPaymentAddress() const { - return saplingAddress; - } -}; - class ZcashdUnifiedFullViewingKey { private: std::optional transparentKey; @@ -49,9 +31,9 @@ public: return saplingKey; } - std::optional Address(diversifier_index_t j) const; + std::optional Address(diversifier_index_t j) const; - std::pair FindAddress(diversifier_index_t j) const { + std::pair FindAddress(diversifier_index_t j) const { auto addr = Address(j); while (!addr.has_value()) { if (!j.increment())