From 2afc8eb0ecdb959310a0e2a6063ecdb7b4f0cf3e Mon Sep 17 00:00:00 2001 From: Jay Graber Date: Wed, 11 Jul 2018 13:22:41 -0700 Subject: [PATCH] Add Sapling support to z_exportkey --- src/wallet/rpcdump.cpp | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 6ddecbad4..fe4b66ec5 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -777,14 +777,32 @@ UniValue z_exportkey(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid zaddr"); } // TODO: Add Sapling support. For now, ensure we can freely convert. - assert(boost::get(&address) != nullptr); - auto addr = boost::get(address); - - libzcash::SproutSpendingKey k; - if (!pwalletMain->GetSpendingKey(addr, k)) - throw JSONRPCError(RPC_WALLET_ERROR, "Wallet does not hold private zkey for this zaddr"); - - return EncodeSpendingKey(k); + bool isValidAddr = boost::get(&address) != nullptr || boost::get(&address) != nullptr; + assert(isValidAddr); + + if (boost::get(&address) != nullptr) { + auto addr = boost::get(address); + + libzcash::SproutSpendingKey k; + if (!pwalletMain->GetSpendingKey(addr, k)) { + throw JSONRPCError(RPC_WALLET_ERROR, "Wallet does not hold private zkey for this zaddr"); + } + + return EncodeSpendingKey(k); + } else { + auto addr = boost::get(address); + libzcash::SaplingIncomingViewingKey ivk; + libzcash::SaplingFullViewingKey fvk; + libzcash::SaplingSpendingKey sk; + + if (!pwalletMain->GetSaplingIncomingViewingKey(addr, ivk) || + !pwalletMain->GetSaplingFullViewingKey(ivk, fvk) || + !pwalletMain->GetSaplingSpendingKey(fvk, sk)) { + throw JSONRPCError(RPC_WALLET_ERROR, "Wallet does not hold private zkey for this zaddr"); + } + + return EncodeSpendingKey(sk); + } } UniValue z_exportviewingkey(const UniValue& params, bool fHelp)