@@ -52,6 +52,23 @@ static inline bool GetAvoidReuseFlag(CWallet * const pwallet, const UniValue& pa
52
52
return avoid_reuse;
53
53
}
54
54
55
+
56
+ /* * Used by RPC commands that have an include_watchonly parameter.
57
+ * We default to true for watchonly wallets if include_watchonly isn't
58
+ * explicitly set.
59
+ */
60
+ static bool ParseIncludeWatchonly (const UniValue& include_watchonly, const CWallet& pwallet)
61
+ {
62
+ if (include_watchonly.isNull ()) {
63
+ // if include_watchonly isn't explicitly set, then check if we have a watchonly wallet
64
+ return pwallet.IsWalletFlagSet (WALLET_FLAG_DISABLE_PRIVATE_KEYS);
65
+ }
66
+
67
+ // otherwise return whatever include_watchonly was set to
68
+ return include_watchonly.get_bool ();
69
+ }
70
+
71
+
55
72
/* * Checks if a CKey is in the given CWallet compressed or otherwise*/
56
73
bool HaveKey (const CWallet& wallet, const CKey& key)
57
74
{
@@ -748,10 +765,7 @@ static UniValue getbalance(const JSONRPCRequest& request)
748
765
min_depth = request.params [1 ].get_int ();
749
766
}
750
767
751
- bool include_watchonly = false ;
752
- if (!request.params [2 ].isNull () && request.params [2 ].get_bool ()) {
753
- include_watchonly = true ;
754
- }
768
+ bool include_watchonly = ParseIncludeWatchonly (request.params [2 ], *pwallet);
755
769
756
770
bool avoid_reuse = GetAvoidReuseFlag (pwallet, request.params [3 ]);
757
771
@@ -1033,9 +1047,10 @@ static UniValue ListReceived(interfaces::Chain::Lock& locked_chain, CWallet * co
1033
1047
fIncludeEmpty = params[1 ].get_bool ();
1034
1048
1035
1049
isminefilter filter = ISMINE_SPENDABLE;
1036
- if (!params[2 ].isNull ())
1037
- if (params[2 ].get_bool ())
1038
- filter = filter | ISMINE_WATCH_ONLY;
1050
+
1051
+ if (ParseIncludeWatchonly (params[2 ], *pwallet)) {
1052
+ filter |= ISMINE_WATCH_ONLY;
1053
+ }
1039
1054
1040
1055
bool has_filtered_address = false ;
1041
1056
CTxDestination filtered_address = CNoDestination ();
@@ -1434,9 +1449,10 @@ UniValue listtransactions(const JSONRPCRequest& request)
1434
1449
if (!request.params [2 ].isNull ())
1435
1450
nFrom = request.params [2 ].get_int ();
1436
1451
isminefilter filter = ISMINE_SPENDABLE;
1437
- if (!request.params [3 ].isNull ())
1438
- if (request.params [3 ].get_bool ())
1439
- filter = filter | ISMINE_WATCH_ONLY;
1452
+
1453
+ if (ParseIncludeWatchonly (request.params [3 ], *pwallet)) {
1454
+ filter |= ISMINE_WATCH_ONLY;
1455
+ }
1440
1456
1441
1457
if (nCount < 0 )
1442
1458
throw JSONRPCError (RPC_INVALID_PARAMETER, " Negative count" );
@@ -1579,8 +1595,8 @@ static UniValue listsinceblock(const JSONRPCRequest& request)
1579
1595
}
1580
1596
}
1581
1597
1582
- if (!request. params [ 2 ]. isNull () && request.params [2 ]. get_bool ( )) {
1583
- filter = filter | ISMINE_WATCH_ONLY;
1598
+ if (ParseIncludeWatchonly ( request.params [2 ], *pwallet )) {
1599
+ filter |= ISMINE_WATCH_ONLY;
1584
1600
}
1585
1601
1586
1602
bool include_removed = (request.params [3 ].isNull () || request.params [3 ].get_bool ());
@@ -1697,9 +1713,10 @@ static UniValue gettransaction(const JSONRPCRequest& request)
1697
1713
uint256 hash (ParseHashV (request.params [0 ], " txid" ));
1698
1714
1699
1715
isminefilter filter = ISMINE_SPENDABLE;
1700
- if (!request.params [1 ].isNull ())
1701
- if (request.params [1 ].get_bool ())
1702
- filter = filter | ISMINE_WATCH_ONLY;
1716
+
1717
+ if (ParseIncludeWatchonly (request.params [1 ], *pwallet)) {
1718
+ filter |= ISMINE_WATCH_ONLY;
1719
+ }
1703
1720
1704
1721
UniValue entry (UniValue::VOBJ);
1705
1722
auto it = pwallet->mapWallet .find (hash);
@@ -3014,8 +3031,7 @@ void FundTransaction(CWallet* const pwallet, CMutableTransaction& tx, CAmount& f
3014
3031
}
3015
3032
}
3016
3033
3017
- if (options.exists (" includeWatching" ))
3018
- coinControl.fAllowWatchOnly = options[" includeWatching" ].get_bool ();
3034
+ coinControl.fAllowWatchOnly = ParseIncludeWatchonly (options[" includeWatching" ], *pwallet);
3019
3035
3020
3036
if (options.exists (" lockUnspents" ))
3021
3037
lockUnspents = options[" lockUnspents" ].get_bool ();
@@ -3047,6 +3063,9 @@ void FundTransaction(CWallet* const pwallet, CMutableTransaction& tx, CAmount& f
3047
3063
}
3048
3064
}
3049
3065
}
3066
+ } else {
3067
+ // if options is null and not a bool
3068
+ coinControl.fAllowWatchOnly = ParseIncludeWatchonly (NullUniValue, *pwallet);
3050
3069
}
3051
3070
3052
3071
if (tx.vout .size () == 0 )
0 commit comments