fix z_listunspent includeWatchonly logic

This commit is contained in:
Larry Ruane
2018-10-04 12:26:36 -06:00
parent 5f57babd08
commit 27a6a99cb0

View File

@@ -2535,14 +2535,14 @@ UniValue z_listunspent(const UniValue& params, bool fHelp)
} }
string address = o.get_str(); string address = o.get_str();
auto zaddr = DecodePaymentAddress(address); auto zaddr = DecodePaymentAddress(address);
if (IsValidPaymentAddress(zaddr)) { if (!IsValidPaymentAddress(zaddr)) {
auto hasSpendingKey = boost::apply_visitor(HaveSpendingKeyForPaymentAddress(pwalletMain), zaddr);
if (hasSpendingKey) {
zaddrs.insert(zaddr);
}
} else {
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, address is not a valid zaddr: ") + address); throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, address is not a valid zaddr: ") + address);
} }
auto hasSpendingKey = boost::apply_visitor(HaveSpendingKeyForPaymentAddress(pwalletMain), zaddr);
if (!fIncludeWatchonly && !hasSpendingKey) {
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, spending key for address does not belong to wallet: ") + address);
}
zaddrs.insert(zaddr);
if (setAddress.count(address)) { if (setAddress.count(address)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ") + address); throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ") + address);