Skip to content
Permalink
Browse files
[backport#16383 1/3] rpcwallet: default include_watchonly to true for…
… watchonly wallets

Summary:
The logic before would only include watchonly addresses if it was
explicitly set in the rpc argument.

This changes the logic like so:

If the include_watchonly argument is missing, check the
WALLET_FLAG_DISABLE_PRIVATE_KEYS flag to determine if we're working
with a watchonly wallet. If so, default include_watchonly to true.

If the include_watchonly argument is explicit set to false, we still
disable them from the listing. Although this would always return
nothing, it might be still useful in situations where you want to
explicitly filter out watchonly addresses regardless of what wallet
you are dealing with.

Signed-off-by: William Casarin <jb55@jb55.com>

bitcoin/bitcoin@a50d9e6

---

Partial backport of Core [[bitcoin/bitcoin#16383 | PR16383]]

Test Plan:
  ninja check check-functional

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D7121
  • Loading branch information
jb55 authored and majcosta committed Aug 7, 2020
1 parent 86511aa commit 2940d7338dea594dedb3a8126e09a0b535ac663b
Showing 1 changed file with 31 additions and 16 deletions.
@@ -53,6 +53,22 @@ static inline bool GetAvoidReuseFlag(CWallet *const pwallet,
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 @@ static UniValue getbalance(const Config &config,
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 @@ ListReceived(const Config &config, interfaces::Chain::Lock &locked_chain,
}

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 @@ UniValue listtransactions(const Config &config, const JSONRPCRequest &request) {
}

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 @@ static UniValue listsinceblock(const Config &config,
}
}

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 @@ static UniValue gettransaction(const Config &config,
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 @@ void FundTransaction(CWallet *const pwallet, CMutableTransaction &tx,
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 @@ void FundTransaction(CWallet *const pwallet, CMutableTransaction &tx,
options["subtractFeeFromOutputs"].get_array();
}
}
} else {
// if options is null and not a bool
coinControl.fAllowWatchOnly =
ParseIncludeWatchonly(NullUniValue, *pwallet);
}

if (tx.vout.size() == 0) {

0 comments on commit 2940d73

Please sign in to comment.