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

View File

@@ -777,14 +777,32 @@ UniValue z_exportkey(const UniValue& params, bool fHelp)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid zaddr"); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid zaddr");
} }
// TODO: Add Sapling support. For now, ensure we can freely convert. // TODO: Add Sapling support. For now, ensure we can freely convert.
assert(boost::get<libzcash::SproutPaymentAddress>(&address) != nullptr); bool isValidAddr = boost::get<libzcash::SproutPaymentAddress>(&address) != nullptr || boost::get<libzcash::SaplingPaymentAddress>(&address) != nullptr;
auto addr = boost::get<libzcash::SproutPaymentAddress>(address); assert(isValidAddr);
libzcash::SproutSpendingKey k; if (boost::get<libzcash::SproutPaymentAddress>(&address) != nullptr) {
if (!pwalletMain->GetSpendingKey(addr, k)) auto addr = boost::get<libzcash::SproutPaymentAddress>(address);
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet does not hold private zkey for this zaddr");
libzcash::SproutSpendingKey k;
return EncodeSpendingKey(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) UniValue z_exportviewingkey(const UniValue& params, bool fHelp)