From 81e0fd2eb94d4db216face9d30ad7368b2f4c532 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Sat, 4 Aug 2018 12:07:18 +0100 Subject: [PATCH] wallet: Add HaveSpendingKeyForPaymentAddress visitor --- src/wallet/wallet.cpp | 20 ++++++++++++++++++++ src/wallet/wallet.h | 12 ++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index e016cc476..62b344522 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -4374,6 +4374,26 @@ bool PaymentAddressBelongsToWallet::operator()(const libzcash::InvalidEncoding& return false; } +bool HaveSpendingKeyForPaymentAddress::operator()(const libzcash::SproutPaymentAddress &zaddr) const +{ + return m_wallet->HaveSproutSpendingKey(zaddr); +} + +bool HaveSpendingKeyForPaymentAddress::operator()(const libzcash::SaplingPaymentAddress &zaddr) const +{ + libzcash::SaplingIncomingViewingKey ivk; + libzcash::SaplingFullViewingKey fvk; + + return m_wallet->GetSaplingIncomingViewingKey(zaddr, ivk) && + m_wallet->GetSaplingFullViewingKey(ivk, fvk) && + m_wallet->HaveSaplingSpendingKey(fvk); +} + +bool HaveSpendingKeyForPaymentAddress::operator()(const libzcash::InvalidEncoding& no) const +{ + return false; +} + boost::optional GetSpendingKeyForPaymentAddress::operator()( const libzcash::SproutPaymentAddress &zaddr) const { diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 2e23b2169..6c57d6112 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1319,6 +1319,18 @@ public: bool operator()(const libzcash::InvalidEncoding& no) const; }; +class HaveSpendingKeyForPaymentAddress : public boost::static_visitor +{ +private: + CWallet *m_wallet; +public: + HaveSpendingKeyForPaymentAddress(CWallet *wallet) : m_wallet(wallet) {} + + bool operator()(const libzcash::SproutPaymentAddress &zaddr) const; + bool operator()(const libzcash::SaplingPaymentAddress &zaddr) const; + bool operator()(const libzcash::InvalidEncoding& no) const; +}; + class GetSpendingKeyForPaymentAddress : public boost::static_visitor> { private: