|
51 | 51 |
|
52 | 52 | static const std::string WALLET_ENDPOINT_BASE = "/wallet/"; |
53 | 53 |
|
| 54 | +/** Used by RPC commands that have an include_watchonly parameter. |
| 55 | + * We default to true for watchonly wallets if include_watchonly isn't |
| 56 | + * explicitly set. |
| 57 | + */ |
| 58 | +static bool ParseIncludeWatchonly(const UniValue& include_watchonly, const CWallet& pwallet) |
| 59 | +{ |
| 60 | + if (include_watchonly.isNull()) { |
| 61 | + // if include_watchonly isn't explicitly set, then check if we have a watchonly wallet |
| 62 | + return pwallet.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS); |
| 63 | + } |
| 64 | + |
| 65 | + // otherwise return whatever include_watchonly was set to |
| 66 | + return include_watchonly.get_bool(); |
| 67 | +} |
| 68 | + |
| 69 | + |
| 70 | + |
54 | 71 | bool GetWalletNameFromJSONRPCRequest(const JSONRPCRequest& request, std::string& wallet_name) |
55 | 72 | { |
56 | 73 | if (request.URI.substr(0, WALLET_ENDPOINT_BASE.size()) == WALLET_ENDPOINT_BASE) { |
@@ -780,7 +797,7 @@ static UniValue getbalance(const JSONRPCRequest& request) |
780 | 797 | {"dummy", RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "Remains for backward compatibility. Must be excluded or set to \"*\"."}, |
781 | 798 | {"minconf", RPCArg::Type::NUM, /* default */ "0", "Only include transactions confirmed at least this many times."}, |
782 | 799 | {"addlocked", RPCArg::Type::BOOL, /* default */ "false", "Whether to include transactions locked via InstantSend in the wallet's balance."}, |
783 | | - {"include_watchonly", RPCArg::Type::BOOL, /* default */ "false", "Also include balance in watch-only addresses (see 'importaddress')"}, |
| 800 | + {"include_watchonly", RPCArg::Type::BOOL, /* default */ "true for watch-only wallets, otherwise false", "Also include balance in watch-only addresses (see 'importaddress')"}, |
784 | 801 | }, |
785 | 802 | RPCResult{ |
786 | 803 | "amount (numeric) The total amount in " + CURRENCY_UNIT + " received for this wallet.\n" |
@@ -818,10 +835,7 @@ static UniValue getbalance(const JSONRPCRequest& request) |
818 | 835 | fAddLocked = addlocked.get_bool(); |
819 | 836 | } |
820 | 837 |
|
821 | | - bool include_watchonly = false; |
822 | | - if (!request.params[3].isNull() && request.params[3].get_bool()) { |
823 | | - include_watchonly = true; |
824 | | - } |
| 838 | + bool include_watchonly = ParseIncludeWatchonly(request.params[2], *pwallet); |
825 | 839 |
|
826 | 840 | const auto bal = pwallet->GetBalance(min_depth, fAddLocked); |
827 | 841 |
|
@@ -1123,9 +1137,10 @@ static UniValue ListReceived(interfaces::Chain::Lock& locked_chain, CWallet * co |
1123 | 1137 | fIncludeEmpty = params[2].get_bool(); |
1124 | 1138 |
|
1125 | 1139 | isminefilter filter = ISMINE_SPENDABLE; |
1126 | | - if(!params[3].isNull()) |
1127 | | - if(params[3].get_bool()) |
1128 | | - filter = filter | ISMINE_WATCH_ONLY; |
| 1140 | + |
| 1141 | + if (ParseIncludeWatchonly(params[3], *pwallet)) { |
| 1142 | + filter |= ISMINE_WATCH_ONLY; |
| 1143 | + } |
1129 | 1144 |
|
1130 | 1145 | bool has_filtered_address = false; |
1131 | 1146 | CTxDestination filtered_address = CNoDestination(); |
@@ -1275,7 +1290,7 @@ static UniValue listreceivedbyaddress(const JSONRPCRequest& request) |
1275 | 1290 | {"minconf", RPCArg::Type::NUM, /* default */ "1", "The minimum number of confirmations before payments are included."}, |
1276 | 1291 | {"addlocked", RPCArg::Type::BOOL, /* default */ "false", "Whether to include transactions locked via InstantSend."}, |
1277 | 1292 | {"include_empty", RPCArg::Type::BOOL, /* default */ "false", "Whether to include addresses that haven't received any payments."}, |
1278 | | - {"include_watchonly", RPCArg::Type::BOOL, /* default */ "false", "Whether to include watch-only addresses (see 'importaddress')."}, |
| 1293 | + {"include_watchonly", RPCArg::Type::BOOL, /* default */ "true for watch-only wallets, otherwise false", "Whether to include watch-only addresses (see 'importaddress')"}, |
1279 | 1294 | {"address_filter", RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "If present, only return information on this address."}, |
1280 | 1295 | }, |
1281 | 1296 | RPCResult{ |
@@ -1331,7 +1346,7 @@ static UniValue listreceivedbylabel(const JSONRPCRequest& request) |
1331 | 1346 | {"minconf", RPCArg::Type::NUM, /* default */ "1", "The minimum number of confirmations before payments are included."}, |
1332 | 1347 | {"addlocked", RPCArg::Type::BOOL, /* default */ "false", "Whether to include transactions locked via InstantSend."}, |
1333 | 1348 | {"include_empty", RPCArg::Type::BOOL, /* default */ "false", "Whether to include labels that haven't received any payments."}, |
1334 | | - {"include_watchonly", RPCArg::Type::BOOL, /* default */ "false", "Whether to include watch-only addresses (see 'importaddress')."}, |
| 1349 | + {"include_watchonly", RPCArg::Type::BOOL, /* default */ "true for watch-only wallets, otherwise false", "Whether to include watch-only addresses (see 'importaddress')"}, |
1335 | 1350 | }, |
1336 | 1351 | RPCResult{ |
1337 | 1352 | "[\n" |
@@ -1475,7 +1490,7 @@ static UniValue listtransactions(const JSONRPCRequest& request) |
1475 | 1490 | " with the specified label, or \"*\" to disable filtering and return all transactions."}, |
1476 | 1491 | {"count", RPCArg::Type::NUM, /* default */ "10", "The number of transactions to return"}, |
1477 | 1492 | {"skip", RPCArg::Type::NUM, /* default */ "0", "The number of transactions to skip"}, |
1478 | | - {"include_watchonly", RPCArg::Type::BOOL, /* default */ "false", "Include transactions to watch-only addresses (see 'importaddress')"}, |
| 1493 | + {"include_watchonly", RPCArg::Type::BOOL, /* default */ "true for watch-only wallets, otherwise false", "Include transactions to watch-only addresses (see 'importaddress')"}, |
1479 | 1494 | }, |
1480 | 1495 | RPCResult{ |
1481 | 1496 | "[\n" |
@@ -1543,9 +1558,10 @@ static UniValue listtransactions(const JSONRPCRequest& request) |
1543 | 1558 | if (!request.params[2].isNull()) |
1544 | 1559 | nFrom = request.params[2].get_int(); |
1545 | 1560 | isminefilter filter = ISMINE_SPENDABLE; |
1546 | | - if(!request.params[3].isNull()) |
1547 | | - if(request.params[3].get_bool()) |
1548 | | - filter = filter | ISMINE_WATCH_ONLY; |
| 1561 | + |
| 1562 | + if (ParseIncludeWatchonly(request.params[3], *pwallet)) { |
| 1563 | + filter |= ISMINE_WATCH_ONLY; |
| 1564 | + } |
1549 | 1565 |
|
1550 | 1566 | if (nCount < 0) |
1551 | 1567 | throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative count"); |
@@ -1600,7 +1616,7 @@ static UniValue listsinceblock(const JSONRPCRequest& request) |
1600 | 1616 | { |
1601 | 1617 | {"blockhash", RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "If set, the block hash to list transactions since, otherwise list all transactions."}, |
1602 | 1618 | {"target_confirmations", RPCArg::Type::NUM, /* default */ "1", "Return the nth block hash from the main chain. e.g. 1 would mean the best block hash. Note: this is not used as a filter, but only affects [lastblock] in the return value"}, |
1603 | | - {"include_watchonly", RPCArg::Type::BOOL, /* default */ "false", "Include transactions to watch-only addresses (see 'importaddress')"}, |
| 1619 | + {"include_watchonly", RPCArg::Type::BOOL, /* default */ "true for watch-only wallets, otherwise false", "Include transactions to watch-only addresses (see 'importaddress')"}, |
1604 | 1620 | {"include_removed", RPCArg::Type::BOOL, /* default */ "true", "Show transactions that were removed due to a reorg in the \"removed\" array\n" |
1605 | 1621 | " (not guaranteed to work on pruned nodes)"}, |
1606 | 1622 | }, |
@@ -1674,8 +1690,8 @@ static UniValue listsinceblock(const JSONRPCRequest& request) |
1674 | 1690 | } |
1675 | 1691 | } |
1676 | 1692 |
|
1677 | | - if (!request.params[2].isNull() && request.params[2].get_bool()) { |
1678 | | - filter = filter | ISMINE_WATCH_ONLY; |
| 1693 | + if (ParseIncludeWatchonly(request.params[2], *pwallet)) { |
| 1694 | + filter |= ISMINE_WATCH_ONLY; |
1679 | 1695 | } |
1680 | 1696 |
|
1681 | 1697 | bool include_removed = (request.params[3].isNull() || request.params[3].get_bool()); |
@@ -1739,7 +1755,7 @@ static UniValue gettransaction(const JSONRPCRequest& request) |
1739 | 1755 | "\nGet detailed information about in-wallet transaction <txid>\n", |
1740 | 1756 | { |
1741 | 1757 | {"txid", RPCArg::Type::STR, RPCArg::Optional::NO, "The transaction id"}, |
1742 | | - {"include_watchonly", RPCArg::Type::BOOL, /* default */ "false", "Whether to include watch-only addresses in balance calculation and details[]"}, |
| 1758 | + {"include_watchonly", RPCArg::Type::BOOL, /* default */ "true for watch-only wallets, otherwise false", "Whether to include watch-only addresses in balance calculation and details[]"}, |
1743 | 1759 | }, |
1744 | 1760 | RPCResult{ |
1745 | 1761 | "{\n" |
@@ -1791,9 +1807,10 @@ static UniValue gettransaction(const JSONRPCRequest& request) |
1791 | 1807 | hash.SetHex(request.params[0].get_str()); |
1792 | 1808 |
|
1793 | 1809 | isminefilter filter = ISMINE_SPENDABLE; |
1794 | | - if(!request.params[1].isNull()) |
1795 | | - if(request.params[1].get_bool()) |
1796 | | - filter = filter | ISMINE_WATCH_ONLY; |
| 1810 | + |
| 1811 | + if (ParseIncludeWatchonly(request.params[1], *pwallet)) { |
| 1812 | + filter |= ISMINE_WATCH_ONLY; |
| 1813 | + } |
1797 | 1814 |
|
1798 | 1815 | UniValue entry(UniValue::VOBJ); |
1799 | 1816 | auto it = pwallet->mapWallet.find(hash); |
@@ -3268,8 +3285,7 @@ void FundTransaction(CWallet* const pwallet, CMutableTransaction& tx, CAmount& f |
3268 | 3285 | if (options.exists("changePosition")) |
3269 | 3286 | change_position = options["changePosition"].get_int(); |
3270 | 3287 |
|
3271 | | - if (options.exists("includeWatching")) |
3272 | | - coinControl.fAllowWatchOnly = options["includeWatching"].get_bool(); |
| 3288 | + coinControl.fAllowWatchOnly = ParseIncludeWatchonly(options["includeWatching"], *pwallet); |
3273 | 3289 |
|
3274 | 3290 | if (options.exists("lockUnspents")) |
3275 | 3291 | lockUnspents = options["lockUnspents"].get_bool(); |
@@ -3297,6 +3313,9 @@ void FundTransaction(CWallet* const pwallet, CMutableTransaction& tx, CAmount& f |
3297 | 3313 | } |
3298 | 3314 | } |
3299 | 3315 | } |
| 3316 | + } else { |
| 3317 | + // if options is null and not a bool |
| 3318 | + coinControl.fAllowWatchOnly = ParseIncludeWatchonly(NullUniValue, *pwallet); |
3300 | 3319 | } |
3301 | 3320 |
|
3302 | 3321 | if (tx.vout.size() == 0) |
@@ -3352,7 +3371,7 @@ static UniValue fundrawtransaction(const JSONRPCRequest& request) |
3352 | 3371 | { |
3353 | 3372 | {"changeAddress", RPCArg::Type::STR, /* default */ "pool address", "The dash address to receive the change"}, |
3354 | 3373 | {"changePosition", RPCArg::Type::NUM, /* default */ "random", "The index of the change output"}, |
3355 | | - {"includeWatching", RPCArg::Type::BOOL, /* default */ "false", "Also select inputs which are watch only"}, |
| 3374 | + {"includeWatching", RPCArg::Type::BOOL, /* default */ "true for watch-only wallets, otherwise false", "Also select inputs which are watch only"}, |
3356 | 3375 | {"lockUnspents", RPCArg::Type::BOOL, /* default */ "false", "Lock selected unspent outputs"}, |
3357 | 3376 | {"feeRate", RPCArg::Type::AMOUNT, /* default */ "not set: makes wallet determine the fee", "Set a specific fee rate in " + CURRENCY_UNIT + "/kB"}, |
3358 | 3377 | {"subtractFeeFromOutputs", RPCArg::Type::ARR, /* default */ "empty array", "A json array of integers.\n" |
@@ -4072,7 +4091,7 @@ UniValue walletcreatefundedpsbt(const JSONRPCRequest& request) |
4072 | 4091 | { |
4073 | 4092 | {"changeAddress", RPCArg::Type::STR_HEX, /* default */ "pool address", "The dash address to receive the change"}, |
4074 | 4093 | {"changePosition", RPCArg::Type::NUM, /* default */ "random", "The index of the change output"}, |
4075 | | - {"includeWatching", RPCArg::Type::BOOL, /* default */ "false", "Also select inputs which are watch only"}, |
| 4094 | + {"includeWatching", RPCArg::Type::BOOL, /* default */ "true for watch-only wallets, otherwise false", "Also select inputs which are watch only"}, |
4076 | 4095 | {"lockUnspents", RPCArg::Type::BOOL, /* default */ "false", "Lock selected unspent outputs"}, |
4077 | 4096 | {"feeRate", RPCArg::Type::AMOUNT, /* default */ "not set: makes wallet determine the fee", "Set a specific fee rate in " + CURRENCY_UNIT + "/kB"}, |
4078 | 4097 | {"subtractFeeFromOutputs", RPCArg::Type::ARR, /* default */ "empty array", "A json array of integers.\n" |
|
0 commit comments