Add Sapling support to z_exportkey

This commit is contained in:
Jay Graber 2018-07-11 13:22:41 -07:00 committed by Simon
parent 3eefe12c79
commit 2afc8eb0ec
1 changed files with 26 additions and 8 deletions

View File

@ -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<libzcash::SproutPaymentAddress>(&address) != nullptr);
auto addr = boost::get<libzcash::SproutPaymentAddress>(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<libzcash::SproutPaymentAddress>(&address) != nullptr || boost::get<libzcash::SaplingPaymentAddress>(&address) != nullptr;
assert(isValidAddr);
if (boost::get<libzcash::SproutPaymentAddress>(&address) != nullptr) {
auto addr = boost::get<libzcash::SproutPaymentAddress>(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<libzcash::SaplingPaymentAddress>(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)