diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -53,6 +53,22 @@ return avoid_reuse; } +/** + * Used by RPC commands that have an include_watchonly parameter. We default to + * true for watchonly wallets if include_watchonly isn't explicitly set. + */ +static bool ParseIncludeWatchonly(const UniValue &include_watchonly, + const CWallet &pwallet) { + if (include_watchonly.isNull()) { + // if include_watchonly isn't explicitly set, then check if we have a + // watchonly wallet + return pwallet.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS); + } + + // otherwise return whatever include_watchonly was set to + return include_watchonly.get_bool(); +} + /** * Checks if a CKey is in the given CWallet compressed or otherwise */ @@ -848,10 +864,7 @@ min_depth = request.params[1].get_int(); } - bool include_watchonly = false; - if (!request.params[2].isNull() && request.params[2].get_bool()) { - include_watchonly = true; - } + bool include_watchonly = ParseIncludeWatchonly(request.params[2], *pwallet); bool avoid_reuse = GetAvoidReuseFlag(pwallet, request.params[3]); @@ -1183,8 +1196,8 @@ } isminefilter filter = ISMINE_SPENDABLE; - if (!params[2].isNull() && params[2].get_bool()) { - filter = filter | ISMINE_WATCH_ONLY; + if (ParseIncludeWatchonly(params[2], *pwallet)) { + filter |= ISMINE_WATCH_ONLY; } bool has_filtered_address = false; @@ -1646,8 +1659,8 @@ } isminefilter filter = ISMINE_SPENDABLE; - if (!request.params[3].isNull() && request.params[3].get_bool()) { - filter = filter | ISMINE_WATCH_ONLY; + if (ParseIncludeWatchonly(request.params[3], *pwallet)) { + filter |= ISMINE_WATCH_ONLY; } if (nCount < 0) { @@ -1838,8 +1851,8 @@ } } - if (!request.params[2].isNull() && request.params[2].get_bool()) { - filter = filter | ISMINE_WATCH_ONLY; + if (ParseIncludeWatchonly(request.params[2], *pwallet)) { + filter |= ISMINE_WATCH_ONLY; } bool include_removed = @@ -1992,8 +2005,8 @@ TxId txid(ParseHashV(request.params[0], "txid")); isminefilter filter = ISMINE_SPENDABLE; - if (!request.params[1].isNull() && request.params[1].get_bool()) { - filter = filter | ISMINE_WATCH_ONLY; + if (ParseIncludeWatchonly(request.params[1], *pwallet)) { + filter |= ISMINE_WATCH_ONLY; } UniValue entry(UniValue::VOBJ); @@ -3548,10 +3561,8 @@ change_position = options["changePosition"].get_int(); } - if (options.exists("includeWatching")) { - coinControl.fAllowWatchOnly = - options["includeWatching"].get_bool(); - } + coinControl.fAllowWatchOnly = + ParseIncludeWatchonly(options["includeWatching"], *pwallet); if (options.exists("lockUnspents")) { lockUnspents = options["lockUnspents"].get_bool(); @@ -3568,6 +3579,10 @@ options["subtractFeeFromOutputs"].get_array(); } } + } else { + // if options is null and not a bool + coinControl.fAllowWatchOnly = + ParseIncludeWatchonly(NullUniValue, *pwallet); } if (tx.vout.size() == 0) {