rpcwallet: default include_watchonly to true for watchonly wallets #16383

pull jb55 wants to merge 4 commits into bitcoin:master from jb55:20190713-watchonly-defaults changing 4 files +161 −25
  1. jb55 commented at 4:09 pm on July 13, 2019: member

    Right now it’s a bit annoying to deal with watchonly wallets, many rpc commands have an include_watchonly argument that needs to be explicitly set.

    Wallets created with createwallet can have a disable_private_keys parameter, for those wallets we already know that they are watchonly, so there’s no reason to have to explicitly ask for it for every command. Instead we check this wallet flag when the include_watchonly parameter isn’t set.

  2. in src/wallet/rpcwallet.cpp:60 in 5bd7c0c805 outdated
    51@@ -52,6 +52,23 @@ static inline bool GetAvoidReuseFlag(CWallet * const pwallet, const UniValue& pa
    52     return avoid_reuse;
    53 }
    54 
    55+
    56+/* Used by RPC commands that include an include_watchonly parameter.
    57+ * We default to true for watchonly wallets if include_watchonly isn't
    58+ * explicitly set
    59+ */
    60+static bool IncludeWatchonly(const UniValue& include_watchonly, CWallet* const pwallet)
    


    MarcoFalke commented at 4:17 pm on July 13, 2019:
    0static bool IncludeWatchonly(const UniValue& include_watchonly, const CWallet& wallet)
    
  3. MarcoFalke commented at 4:17 pm on July 13, 2019: member
    Would have to update the documentation as well for the “smart” default value.
  4. jb55 force-pushed on Jul 13, 2019
  5. achow101 commented at 4:35 pm on July 13, 2019: member
    Concept ACK. I think having include_watchonly default to true for actual watchonly wallets is super useful.
  6. jb55 force-pushed on Jul 13, 2019
  7. jb55 commented at 4:49 pm on July 13, 2019: member
    @MarcoFalke I’m a bit new, which docs specifically would need to be updated?
  8. in src/wallet/rpcwallet.cpp:56 in d60e77c7a6 outdated
    51@@ -52,6 +52,23 @@ static inline bool GetAvoidReuseFlag(CWallet * const pwallet, const UniValue& pa
    52     return avoid_reuse;
    53 }
    54 
    55+
    56+/* Used by RPC commands that include an include_watchonly parameter.
    


    darosior commented at 5:14 pm on July 13, 2019:
    nit: /**-starting comments are prefered

    jonatack commented at 5:30 pm on July 13, 2019:
    nit: for readability perhaps employ a different verb than “include” here (have, take, etc.)

    jb55 commented at 7:08 pm on July 13, 2019:
    done

    jb55 commented at 7:08 pm on July 13, 2019:
    done
  9. MarcoFalke commented at 5:17 pm on July 13, 2019: member

    @MarcoFalke I’m a bit new, which docs specifically would need to be updated?

    0-                    {"include_watchonly", RPCArg::Type::BOOL, /* default */ "false", "Whether to include watch-only addresses in balance calculation and details[]"},
    1+                    {"include_watchonly", RPCArg::Type::BOOL, /* default */ ">>>>>>>>>>> update here<<<<<<<<", "Whether to include watch-only addresses in balance calculation and details[]"},
    
  10. in src/wallet/rpcwallet.cpp:58 in d60e77c7a6 outdated
    51@@ -52,6 +52,23 @@ static inline bool GetAvoidReuseFlag(CWallet * const pwallet, const UniValue& pa
    52     return avoid_reuse;
    53 }
    54 
    55+
    56+/* Used by RPC commands that include an include_watchonly parameter.
    57+ * We default to true for watchonly wallets if include_watchonly isn't
    58+ * explicitly set
    


    jonatack commented at 5:31 pm on July 13, 2019:
    nit: s/set/set./

    jb55 commented at 7:08 pm on July 13, 2019:
    done
  11. jonatack commented at 5:34 pm on July 13, 2019: member
    Concept ACK. Will test when help docs are updated. Seems this change would merit test coverage?
  12. jb55 force-pushed on Jul 13, 2019
  13. jb55 force-pushed on Jul 13, 2019
  14. jb55 commented at 7:07 pm on July 13, 2019: member
    @MarcoFalke I wasn’t quite sure what to do for documenting the smart default, let me know if that looks ok
  15. fanquake added the label RPC/REST/ZMQ on Jul 13, 2019
  16. fanquake added the label Wallet on Jul 13, 2019
  17. DrahtBot commented at 0:48 am on July 14, 2019: member

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #16397 (Clarify includeWatching for fundrawtransaction by stevenroose)
    • #16185 (gettransaction: add an argument to decode the transaction by darosior)
    • #15729 (rpc: Raise error in getbalance if minconf is not zero by promag)
    • #14707 ([RPC] Include coinbase transactions in receivedby RPCs by andrewtoth)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  18. in src/wallet/rpcwallet.cpp:735 in 3c145c3954 outdated
    731@@ -732,7 +732,7 @@ static UniValue getbalance(const JSONRPCRequest& request)
    732                 {
    733                     {"dummy", RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "Remains for backward compatibility. Must be excluded or set to \"*\"."},
    734                     {"minconf", RPCArg::Type::NUM, /* default */ "0", "Only include transactions confirmed at least this many times."},
    735-                    {"include_watchonly", RPCArg::Type::BOOL, /* default */ "false", "Also include balance in watch-only addresses (see 'importaddress')"},
    736+                    {"include_watchonly", RPCArg::Type::BOOL, /* default */ "false, true for watchonly wallets", "Also include balance in watch-only addresses (see 'importaddress')"},
    


    jonatack commented at 11:31 am on July 14, 2019:

    Suggestion for the RPCHelpMan default messages: "true for watch-only wallets, otherwise false"

    Grepping related cases in the codebase comes up with similar, e.g. src/wallet/rpcdump.cpp:120

    As for “watchonly” vs “watch-only”, in the descriptions on the same line it is dasherized and git grepping shows the same for user-facing messages. Unless other reviewers have a different opinion, it might be more clear to do the same?


    jb55 commented at 3:23 pm on July 14, 2019:
    yeah that message sounds better. I’ll go with watch-only as well.

    jb55 commented at 5:25 pm on July 14, 2019:
    done
  19. jb55 force-pushed on Jul 14, 2019
  20. in src/wallet/rpcwallet.cpp:60 in cc0d8343e2 outdated
    51@@ -52,6 +52,23 @@ static inline bool GetAvoidReuseFlag(CWallet * const pwallet, const UniValue& pa
    52     return avoid_reuse;
    53 }
    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 IncludeWatchonly(const UniValue& include_watchonly, const CWallet& pwallet)
    


    promag commented at 9:49 pm on July 14, 2019:
    nit, I’d name this ParseIncludeWatchonly.
  21. in src/wallet/rpcwallet.cpp:1452 in cc0d8343e2 outdated
    1447@@ -1434,9 +1448,9 @@ UniValue listtransactions(const JSONRPCRequest& request)
    1448     if (!request.params[2].isNull())
    1449         nFrom = request.params[2].get_int();
    1450     isminefilter filter = ISMINE_SPENDABLE;
    1451-    if(!request.params[3].isNull())
    1452-        if(request.params[3].get_bool())
    1453-            filter = filter | ISMINE_WATCH_ONLY;
    1454+
    1455+    if (IncludeWatchonly(request.params[3], *pwallet))
    


    promag commented at 9:50 pm on July 14, 2019:
    nit, add { }.
  22. in src/wallet/rpcwallet.cpp:1596 in cc0d8343e2 outdated
    1592@@ -1579,9 +1593,8 @@ static UniValue listsinceblock(const JSONRPCRequest& request)
    1593         }
    1594     }
    1595 
    1596-    if (!request.params[2].isNull() && request.params[2].get_bool()) {
    1597-        filter = filter | ISMINE_WATCH_ONLY;
    1598-    }
    1599+    if (IncludeWatchonly(request.params[2], *pwallet))
    


    promag commented at 9:51 pm on July 14, 2019:
    nit, add { }.
  23. in src/wallet/rpcwallet.cpp:1714 in cc0d8343e2 outdated
    1709@@ -1697,9 +1710,9 @@ static UniValue gettransaction(const JSONRPCRequest& request)
    1710     uint256 hash(ParseHashV(request.params[0], "txid"));
    1711 
    1712     isminefilter filter = ISMINE_SPENDABLE;
    1713-    if(!request.params[1].isNull())
    1714-        if(request.params[1].get_bool())
    1715-            filter = filter | ISMINE_WATCH_ONLY;
    1716+
    1717+    if (IncludeWatchonly(request.params[1], *pwallet))
    


    promag commented at 9:51 pm on July 14, 2019:
    nit, add { }.
  24. promag commented at 9:52 pm on July 14, 2019: member

    Concept ACK

    Seems this change would merit test coverage?

    Agree with @jonatack. Also add a minor release note?

  25. laanwj commented at 6:02 pm on July 15, 2019: member
    Concept ACK, this definitely seems like the only sensible default to have in that case.
  26. instagibbs commented at 1:05 am on July 16, 2019: member
    concept ACK, needs tests(as others have said)
  27. jb55 commented at 6:22 pm on July 16, 2019: member
    One thing I missed was rpcs with the includeWatching option such as fundrawtransaction and walletcreatefundedpsbt. I think it makes sense to add the default on those as well.
  28. jonasschnelli commented at 8:07 pm on July 16, 2019: contributor
    Concept ACK
  29. jb55 force-pushed on Jul 18, 2019
  30. rpcwallet: default include_watchonly to true for watchonly wallets
    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>
    a50d9e6c0b
  31. rpcwallet: document include_watchonly default for watchonly wallets
    Signed-off-by: William Casarin <jb55@jb55.com>
    003a3c73c0
  32. jb55 force-pushed on Jul 18, 2019
  33. jb55 force-pushed on Jul 18, 2019
  34. jb55 commented at 8:43 pm on July 18, 2019: member

    Latest updates:

    • Added the new defaulting logic to walletcreatefundedpsbt and fundrawtransaction’s includeWatching option.
    • Fixed @promag’s nits
    • Added release notes
    • Added functional tests for the new defaults

    This is the first time I’ve done the last two things, so let me know if I did anything wrong.

  35. in doc/release-notes-16383.md:5 in c7cbf290ae outdated
    0@@ -0,0 +1,8 @@
    1+RPC changes
    2+-----------
    3+
    4+RPCs which have an `include_watchonly` argument or `includeWatching`
    5+option now default to `true` for watch-only wallets. affected RPCs
    


    practicalswift commented at 11:16 am on July 22, 2019:
    Nit: Should be “Affected”? :-)

    jb55 commented at 10:34 am on July 24, 2019:
    done
  36. practicalswift commented at 11:17 am on July 22, 2019: contributor

    Concept ACK

    Good idea!

  37. doc: add release note for include_watchonly default changes
    Signed-off-by: William Casarin <jb55@jb55.com>
    72ffbdc579
  38. tests: functional watch-only wallet tests
    These test the new watch-only defaults for rpcs with include_watchonly
    and includeWatching options.
    
    Signed-off-by: William Casarin <jb55@jb55.com>
    72eaab073b
  39. jb55 force-pushed on Jul 24, 2019
  40. achow101 commented at 11:32 pm on July 30, 2019: member
    Code review ACK 72eaab073bc747425fe551777154b13a6c4c37c9
  41. in doc/release-notes-16383.md:6 in 72eaab073b
    0@@ -0,0 +1,8 @@
    1+RPC changes
    2+-----------
    3+
    4+RPCs which have an `include_watchonly` argument or `includeWatching`
    5+option now default to `true` for watch-only wallets. Affected RPCs
    6+are: `getbalance`, `listreceivedbyaddress`, `listreceivedbylabel`,
    


    promag commented at 0:22 am on July 31, 2019:
    nit, sort.
  42. in test/functional/wallet_watchonly.py:105 in 72eaab073b
    100+        result = wo_wallet.fundrawtransaction(hexstring=rawtx, options=options)
    101+        assert_equal("hex" in result, True)
    102+        assert_raises_rpc_error(-4, "Insufficient funds", wo_wallet.fundrawtransaction, rawtx, no_wo_options)
    103+
    104+
    105+
    


    promag commented at 0:23 am on July 31, 2019:
    nit, remove extra line.
  43. in test/functional/wallet_watchonly.py:47 in 72eaab073b
    42+
    43+        # send 1 btc to our watch-only address
    44+        txid = def_wallet.sendtoaddress(wo_addr, 1)
    45+        self.nodes[0].generate(1)
    46+
    47+        # getbalance
    


    promag commented at 0:25 am on July 31, 2019:
    nit, drop comment.
  44. promag commented at 0:27 am on July 31, 2019: member
    ACK 72eaab073bc747425fe551777154b13a6c4c37c9, code review only, didn’t look closely to the test.
  45. meshcollider commented at 7:16 am on August 1, 2019: contributor
    This makes a lot of sense, Concept ACK
  46. Sjors commented at 6:02 pm on August 15, 2019: member
    ACK 72eaab073bc747425fe551777154b13a6c4c37c9
  47. in src/wallet/rpcwallet.cpp:55 in 72eaab073b
    51@@ -52,6 +52,23 @@ static inline bool GetAvoidReuseFlag(CWallet * const pwallet, const UniValue& pa
    52     return avoid_reuse;
    53 }
    54 
    55+
    


    kallewoof commented at 3:40 am on August 16, 2019:
    Nit: Extraneous newline.
  48. in src/wallet/rpcwallet.cpp:69 in 72eaab073b
    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+}
    


    kallewoof commented at 3:42 am on August 16, 2019:

    Can do

    0return include_watchonly.isNull()
    1    ? pwallet.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)
    2    : include_watchonly.get_bool();
    
  49. in src/wallet/rpcwallet.cpp:71 in 72eaab073b
    66+
    67+    // otherwise return whatever include_watchonly was set to
    68+    return include_watchonly.get_bool();
    69+}
    70+
    71+
    


    kallewoof commented at 3:42 am on August 16, 2019:
    Nit: Extraneous newline.
  50. kallewoof approved
  51. kallewoof commented at 3:45 am on August 16, 2019: member

    ACK 72eaab073bc747425fe551777154b13a6c4c37c9

    Lots of unnecessary newlines all over, and a few nits, but merge-worthy IMO!

  52. fanquake approved
  53. fanquake commented at 3:52 am on August 16, 2019: member

    ACK 72eaab073bc747425fe551777154b13a6c4c37c9 - I’ve looked over the changes, they make sense to me. Compiled and ran the tests etc.

    Thanks to @kallewoof and @ajtowns (he said he sanity checked on his lunch break) for following up my review prod.

    I know there are some nits here, however this has ACKs, and has been sitting for a while, so I’m going to merge it. The nits can be scooped up by someone in either a follow up PR, or a related change.

  54. fanquake merged this on Aug 16, 2019
  55. fanquake closed this on Aug 16, 2019

  56. fanquake referenced this in commit 0d65106dce on Aug 16, 2019
  57. sidhujag referenced this in commit 6a032185ef on Aug 17, 2019
  58. jb55 deleted the branch on May 21, 2020
  59. deadalnix referenced this in commit 2940d7338d on Aug 7, 2020
  60. deadalnix referenced this in commit 5938b3612c on Aug 7, 2020
  61. deadalnix referenced this in commit 9cfb6eb98a on Aug 7, 2020
  62. vijaydasmp referenced this in commit 4c13b5f356 on Dec 6, 2021
  63. vijaydasmp referenced this in commit b98e575e39 on Dec 10, 2021
  64. vijaydasmp referenced this in commit ca4977d1ba on Dec 10, 2021
  65. vijaydasmp referenced this in commit b31f625d88 on Dec 10, 2021
  66. vijaydasmp referenced this in commit db15c6da39 on Dec 11, 2021
  67. vijaydasmp referenced this in commit 2348170569 on Dec 11, 2021
  68. vijaydasmp referenced this in commit 9f999a3a1d on Dec 11, 2021
  69. vijaydasmp referenced this in commit 4094aa7d6a on Dec 11, 2021
  70. vijaydasmp referenced this in commit 02fb4b1710 on Dec 11, 2021
  71. vijaydasmp referenced this in commit 088ab59e8b on Dec 13, 2021
  72. vijaydasmp referenced this in commit c7783bfa4b on Dec 13, 2021
  73. vijaydasmp referenced this in commit 24ac85cf30 on Dec 13, 2021
  74. vijaydasmp referenced this in commit 27761a3b3c on Dec 14, 2021
  75. vijaydasmp referenced this in commit 4fbdba9b66 on Dec 14, 2021
  76. vijaydasmp referenced this in commit 0d3152f18d on Dec 15, 2021
  77. vijaydasmp referenced this in commit bed7ffca44 on Dec 15, 2021
  78. vijaydasmp referenced this in commit 62581c3613 on Dec 18, 2021
  79. vijaydasmp referenced this in commit 8ffd454da5 on Dec 19, 2021
  80. vijaydasmp referenced this in commit 23b2b63fad on Dec 19, 2021
  81. DrahtBot locked this on Feb 15, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-17 15:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me