Auto merge of #4553 - oxarbitrage:issue4356, r=daira

Return address in z_importviewingkey error

Closes https://github.com/zcash/zcash/issues/4536.
This commit is contained in:
Homu 2020-11-19 17:49:58 +00:00
commit bf70e357cf
1 changed files with 3 additions and 2 deletions

View File

@ -850,14 +850,15 @@ UniValue z_importviewingkey(const UniValue& params, bool fHelp)
auto addrInfo = boost::apply_visitor(libzcash::AddressInfoFromViewingKey{}, viewingkey);
UniValue result(UniValue::VOBJ);
const string strAddress = keyIO.EncodePaymentAddress(addrInfo.second);
result.pushKV("type", addrInfo.first);
result.pushKV("address", keyIO.EncodePaymentAddress(addrInfo.second));
result.pushKV("address", strAddress);
auto addResult = boost::apply_visitor(AddViewingKeyToWallet(pwalletMain), viewingkey);
if (addResult == SpendingKeyExists) {
throw JSONRPCError(
RPC_WALLET_ERROR,
"The wallet already contains the private key for this viewing key");
"The wallet already contains the private key for this viewing key (address: " + strAddress + ")");
} else if (addResult == KeyAlreadyExists && fIgnoreExistingKey) {
return result;
}