[RPC] Split part of validateaddress into getaddressinfo #10583

pull achow101 wants to merge 4 commits into bitcoin:master from achow101:getaddressinfo changing 23 files +427 −302
  1. achow101 commented at 10:17 pm on June 13, 2017: member
    This PR makes a new RPC command called getaddressinfo which relies on the wallet. It contains all of validateaddress’s address info stuff. Those parts in validateaddress have been marked as deprecated. The tests have been updated to use getaddressinfo except the disablewallet test which is the only test that actually uses validateaddress to validate an address.
  2. fanquake added the label RPC/REST/ZMQ on Jun 14, 2017
  3. laanwj commented at 2:16 pm on June 14, 2017: member
    Concept ACK. Makes a lot of sense to move the wallet-specific information to a separate RPC.
  4. gmaxwell commented at 7:33 pm on June 15, 2017: contributor
    Concept ACK.
  5. sipa commented at 10:20 pm on June 16, 2017: member
    Currently this duplicates a singificant amount of code. Would it be possible to abstract out the ‘info’ part of getaddressinfo, and then call that from validateaddress as well (temporarily, until removed)?
  6. sipa added the label Needs release notes on Jun 17, 2017
  7. achow101 force-pushed on Jun 19, 2017
  8. achow101 commented at 11:33 pm on June 19, 2017: member
    @sipa Apparently, no, this is not possible. My attempt at doing so has resulted in a linker failure. Apparently there is some makefile problems with that. https://github.com/achow101/bitcoin/tree/getaddressinfo-broken is the branch with the duplication removed, but there is a linker error with IsMine calls. The full build error is here: https://gist.github.com/achow101/0f0e2d9e75d9d77132ab83a7605f2377
  9. achow101 commented at 0:04 am on June 20, 2017: member
    On second thought, I think I fixed the problem.
  10. achow101 force-pushed on Jun 20, 2017
  11. achow101 force-pushed on Jun 20, 2017
  12. sipa commented at 8:16 pm on June 20, 2017: member

    I believe you can do:

    0 bitcoind_LDADD = \
    1   $(LIBBITCOIN_SERVER) \
    2+  $(LIBBITCOIN_WALLET) \
    3   $(LIBBITCOIN_COMMON) \
    4   $(LIBUNIVALUE) \
    5   $(LIBBITCOIN_UTIL) \
    6-  $(LIBBITCOIN_WALLET) \
    7   $(LIBBITCOIN_ZMQ) \
    

    in Makefile.am.

    Then the _ismine code can move from wallet to common (which I think belongs there, as signing code is already in common too).

  13. achow101 commented at 0:01 am on June 21, 2017: member
    @sipa I did that in my latest commit, but it seems that travis doesn’t like it.
  14. achow101 force-pushed on Jun 21, 2017
  15. laanwj commented at 2:21 pm on June 24, 2017: member

    Then the _ismine code can move from wallet to common (which I think belongs there, as signing code is already in common too).

    From what I remember it was already moved in the other direction at some point for the same reason. The circular dependency between _wallet and _server remains a problem. We’ll need to solve #7965 to get rid of it. Unfortunately, this is part of that…

  16. jnewbery commented at 2:35 pm on August 15, 2017: member
    needs rebase
  17. achow101 force-pushed on Aug 15, 2017
  18. achow101 commented at 9:27 pm on August 15, 2017: member
    rebased
  19. achow101 force-pushed on Aug 15, 2017
  20. achow101 force-pushed on Aug 17, 2017
  21. jnewbery commented at 4:07 pm on September 1, 2017: member

    Concept ACK. This PR is currently difficult to review because there are broken intermediate commits, commits which reverse previous commits, random style changes in unconnected commits, etc. Are you able to tidy this up to make it easier to review? If not, I’m happy to take this PR and tidy it up.

    My high-level feedback is that we should hide the deprecated fields in validateaddress behind a command-line argument (similar to #11031). The ismine move to libbitcoin_common seems fine to me.

  22. achow101 force-pushed on Sep 5, 2017
  23. achow101 force-pushed on Sep 5, 2017
  24. achow101 force-pushed on Sep 5, 2017
  25. achow101 commented at 5:39 pm on September 5, 2017: member
    Rebased and tidied up
  26. jnewbery commented at 8:29 pm on September 5, 2017: member
    Travis is failing on invalid scripted diff check.
  27. achow101 force-pushed on Sep 5, 2017
  28. in src/rpc/misc.cpp:172 in 7c3e7ac6cd outdated
    195-                    ret.push_back(Pair("hdkeypath", it->second.hdKeypath));
    196-                    ret.push_back(Pair("hdmasterkeyid", it->second.hdMasterKeyID.GetHex()));
    197-                }
    198+        try {
    199+            ret.pushKVs(getaddressinfo(request));
    200+        } catch (UniValue e) {
    


    jnewbery commented at 8:48 pm on September 5, 2017:

    I don’t understand this. Why do we swallow the RPC_METHOD_NOT_FOUND error?

    Can you add a comment explaining this?


    achow101 commented at 11:21 pm on September 5, 2017:

    That is swallowed in the event that -disablewallet is used; getaddressinfo will return RPC_METHOD_NOT_FOUND but validateaddress should still work and validate addresses.

    I will add a comment.


    jnewbery commented at 11:45 pm on September 5, 2017:

    In that case, I think it’s preferable to test for wallet existence before calling getaddressinfo. The following should do it:

    0        if (!::vpwallets.empty()) {
    1            ret.pushKVs(getaddressinfo(request));
    2        }
    

    achow101 commented at 0:16 am on September 6, 2017:
    Done
  29. in src/wallet/rpcwallet.cpp:3219 in 7c3e7ac6cd outdated
    3214+{
    3215+    CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
    3216+    if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
    3217+        return NullUniValue;
    3218+
    3219+    if (request.fHelp || request.params.size() != 1)
    


    jnewbery commented at 9:46 pm on September 5, 2017:
    nit: braces for if block
  30. in src/wallet/rpcwallet.cpp:3242 in 7c3e7ac6cd outdated
    3223+            "to be in the wallet.\n"
    3224+            "\nArguments:\n"
    3225+            "1. \"address\"     (string, required) The bitcoin address to get the information of.\n"
    3226+            "\nResult:\n"
    3227+            "{\n"
    3228+            "  \"address\" : \"address\", (string) The bitcoin address validated\n"
    


    jnewbery commented at 9:48 pm on September 5, 2017:
    Help text seems to be missing result fields, including at least script, hex, addresses, sigsrequired.

    achow101 commented at 2:04 am on September 19, 2017:
    Forgot to say that this was addressed.
  31. jnewbery commented at 11:05 pm on September 5, 2017: member

    A few nits inline. I think you could drop the third commit by making your scripted diff more focussed:

    0find ./test/functional -path '*py' -not -path ./test/functional/disablewallet.py -exec sed -i'' -e 's/validateaddress/getaddressinfo/g' {} \;
    

    note that sed syntax differs between BSD and GNU. You’ll need to use sed -i '' (space between i and empty string) on BSD.

    (this also has the benefit of not breaking git bisect)

    I still think it’s a good idea to hide the deprecated functionality behind a command-line argument to make removing it in the next version easier.

  32. in src/wallet/rpcwallet.cpp:3178 in 7c3e7ac6cd outdated
    3169@@ -3169,6 +3170,114 @@ UniValue generate(const JSONRPCRequest& request)
    3170     return generateBlocks(coinbase_script, num_generate, max_tries, true);
    3171 }
    3172 
    3173+class DescribeAddressVisitor : public boost::static_visitor<UniValue>
    3174+{
    3175+public:
    3176+    CWallet * const pwallet;
    3177+
    3178+    DescribeAddressVisitor(CWallet *_pwallet) : pwallet(_pwallet) {}
    


    promag commented at 11:20 pm on September 5, 2017:
    Nit, * and & next to type. In this case also const: const CWallet* wallet.

    achow101 commented at 2:06 am on September 19, 2017:
    Done
  33. in src/wallet/rpcwallet.cpp:3569 in 7c3e7ac6cd outdated
    3175+public:
    3176+    CWallet * const pwallet;
    3177+
    3178+    DescribeAddressVisitor(CWallet *_pwallet) : pwallet(_pwallet) {}
    3179+
    3180+    UniValue operator()(const CNoDestination &dest) const { return UniValue(UniValue::VOBJ); }
    


    promag commented at 11:21 pm on September 5, 2017:
    Nit, expand to multiline?

    achow101 commented at 2:06 am on September 19, 2017:
    I don’t think that is necessary
  34. achow101 force-pushed on Sep 5, 2017
  35. achow101 force-pushed on Sep 6, 2017
  36. promag commented at 0:52 am on September 6, 2017: member
    New code (and probably moved code) should take into account developer notes.
  37. achow101 force-pushed on Sep 19, 2017
  38. achow101 force-pushed on Sep 19, 2017
  39. achow101 commented at 2:58 pm on September 19, 2017: member
    Rebased
  40. in src/rpc/misc.cpp:76 in 098cebb709 outdated
    82+#ifdef ENABLE_WALLET
    83+        if (!::vpwallets.empty()) {
    84+            ret.pushKVs(getaddressinfo(request));
    85+        }
    86+#endif
    87+        if (ret["address"].isNull()) {
    


    jnewbery commented at 3:06 pm on September 19, 2017:
    nit: indentation for this if block
  41. in src/wallet/rpcwallet.cpp:3230 in 098cebb709 outdated
    3225+};
    3226+
    3227+UniValue getaddressinfo(const JSONRPCRequest& request)
    3228+{
    3229+    CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
    3230+    if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
    


    jnewbery commented at 3:07 pm on September 19, 2017:
    nit: braces
  42. in src/wallet/rpcwallet.cpp:3277 in 098cebb709 outdated
    3272+    ret.push_back(Pair("address", currentAddress));
    3273+
    3274+    CScript scriptPubKey = GetScriptForDestination(dest);
    3275+    ret.push_back(Pair("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end())));;
    3276+    
    3277+    ret.push_back(Pair("isscript", scriptPubKey.IsPayToScriptHash()));
    


    jnewbery commented at 3:10 pm on September 19, 2017:
    micronit: not in same ordering as help text (either for getaddressinfo or validateaddress. Suggest you move this line below ret.push_back(Pair("iswatchonly", ...
  43. in src/wallet/rpcwallet.cpp:3239 in 098cebb709 outdated
    3234+        throw std::runtime_error(
    3235+            "getaddressinfo \"address\"\n"
    3236+            "\nReturn information about the given bitcoin address. Some information requires the address\n"
    3237+            "to be in the wallet.\n"
    3238+            "\nArguments:\n"
    3239+            "1. \"address\"     (string, required) The bitcoin address to get the information of.\n"
    


    jnewbery commented at 3:18 pm on September 19, 2017:
    nit: help text alignment
  44. in src/wallet/rpcwallet.cpp:3242 in 098cebb709 outdated
    3237+            "to be in the wallet.\n"
    3238+            "\nArguments:\n"
    3239+            "1. \"address\"     (string, required) The bitcoin address to get the information of.\n"
    3240+            "\nResult:\n"
    3241+            "{\n"
    3242+            "  \"address\" : \"address\", (string) The bitcoin address validated\n"
    


    jnewbery commented at 3:18 pm on September 19, 2017:
    nit: help text alignment
  45. in src/wallet/rpcwallet.cpp:3257 in 098cebb709 outdated
    3252+            "      ,...\n"
    3253+            "    ]\n"
    3254+            "  \"sigsrequired\" : xxxxx        (numeric, optional) Number of signatures required to spend multisig output\n"
    3255+            "  \"pubkey\" : \"publickeyhex\",    (string) The hex value of the raw public key\n"
    3256+            "  \"iscompressed\" : true|false,  (boolean) If the address is compressed\n"
    3257+            "  \"timestamp\" : timestamp,        (number, optional) The creation time of the key if available in seconds since epoch (Jan 1 1970 GMT)\n"
    


    jnewbery commented at 3:18 pm on September 19, 2017:
    nit: help text alignment
  46. in src/rpc/misc.cpp:143 in 098cebb709 outdated
    82         throw std::runtime_error(
    83             "validateaddress \"address\"\n"
    84             "\nReturn information about the given bitcoin address.\n"
    85+            "Parts of this command have been deprecated and moved to getaddressinfo\n"
    86             "\nArguments:\n"
    87             "1. \"address\"     (string, required) The bitcoin address to validate\n"
    


    jnewbery commented at 3:18 pm on September 19, 2017:
    nit: help text alignment
  47. in src/rpc/misc.cpp:46 in 098cebb709 outdated
    86             "\nArguments:\n"
    87             "1. \"address\"     (string, required) The bitcoin address to validate\n"
    88             "\nResult:\n"
    89             "{\n"
    90             "  \"isvalid\" : true|false,       (boolean) If the address is valid or not. If not, this is the only property returned.\n"
    91             "  \"address\" : \"address\", (string) The bitcoin address validated\n"
    


    jnewbery commented at 3:18 pm on September 19, 2017:
    nit: help text alignment
  48. in src/rpc/misc.cpp:63 in 098cebb709 outdated
    114+            "  \"iscompressed\" : true|false,  (boolean) DEPRECATED. If the address is compressed\n"
    115             "  \"account\" : \"account\"         (string) DEPRECATED. The account associated with the address, \"\" is the default account\n"
    116-            "  \"timestamp\" : timestamp,        (number, optional) The creation time of the key if available in seconds since epoch (Jan 1 1970 GMT)\n"
    117-            "  \"hdkeypath\" : \"keypath\"       (string, optional) The HD keypath if the key is HD and available\n"
    118-            "  \"hdmasterkeyid\" : \"<hash160>\" (string, optional) The Hash160 of the HD master pubkey\n"
    119+            "  \"timestamp\" : timestamp,        (number, optional) DEPRECATED. The creation time of the key if available in seconds since epoch (Jan 1 1970 GMT)\n"
    


    jnewbery commented at 3:18 pm on September 19, 2017:
    nit: help text alignment
  49. jnewbery commented at 3:28 pm on September 19, 2017: member

    A bunch of nits inline. I’m currently running this over the extended test suite to verify no regressions.

    My high-level feedback hasn’t been addressed:

    we should hide the deprecated fields in validateaddress behind a command-line argument (similar to #11031).

    We need to do something to phase out deprecated RPC methods over a couple of releases. The proposal in #11031 is my suggested way of doing that, but I’m open to other suggestions.

  50. jnewbery commented at 5:34 pm on September 19, 2017: member
    extended test suite passes. Travis is failing the scripted diff check.
  51. achow101 force-pushed on Sep 19, 2017
  52. achow101 commented at 6:25 pm on September 19, 2017: member
    Addressed most of @jnewbery’s comments except for the deprecation thing
  53. jnewbery commented at 6:40 pm on September 19, 2017: member

    Thanks for addressing the nits.

    My preference is that this doesn’t get merged without some kind of phased deprecation. I’m happy to provide a commit to cherry pick if that would help.

  54. achow101 commented at 6:45 pm on September 19, 2017: member

    My preference is that this doesn’t get merged without some kind of phased deprecation. I’m happy to provide a commit to cherry pick if that would help.

    I’m planning on making a generic deprecation interface type thing that I will then rebase this and some other stuff on top of.

  55. achow101 force-pushed on Sep 26, 2017
  56. achow101 commented at 7:00 pm on September 26, 2017: member
    Rebased onto #11031 and moved the deprecated parts behind IsDeprecatedRPCEnabled. I wasn’t sure what to do with the help text so I just left it as is (except for info about using -deprecatedrpc).
  57. in src/rpc/misc.cpp:40 in c288c958e9 outdated
    80 {
    81     if (request.fHelp || request.params.size() != 1)
    82         throw std::runtime_error(
    83             "validateaddress \"address\"\n"
    84             "\nReturn information about the given bitcoin address.\n"
    85+            "Parts of this command have been deprecated and moved to getaddressinfo. To have those deprecated\n"
    


    jnewbery commented at 7:30 pm on September 26, 2017:
    Suggestion only: Perhaps start this with DEPRECATION WARNING: to draw attention. It might be easy to miss this warning.

    achow101 commented at 8:43 pm on September 26, 2017:
    Done
  58. jnewbery commented at 7:36 pm on September 26, 2017: member

    Looks good. Tested ACK c288c958e96d9c2c856abcde901518f0de9fd3ce.

    One suggestion inline, which you could take or leave.

    A test for the difference between the return object when -deprecatedrpc=validateaddress is set and not would be a nice to have, but not essential.

  59. achow101 force-pushed on Sep 26, 2017
  60. achow101 commented at 8:44 pm on September 26, 2017: member
    @jnewbery I added a super basic test to check that -deprecatedrpc=validateaddress changes what is returned.
  61. in src/rpc/misc.cpp:90 in 8d5d4cf4c3 outdated
    112+            ret.pushKVs(getaddressinfo(request));
    113         }
    114 #endif
    115+        if (ret["address"].isNull()) {
    116+            std::string currentAddress = EncodeDestination(dest);
    117+            ret.push_back(Pair("address", currentAddress));
    


    promag commented at 9:02 pm on September 26, 2017:
    Comply with #11386 here and below?

    achow101 commented at 10:11 pm on September 26, 2017:
    Done.
  62. in src/wallet/rpcwallet.h:13 in 8d5d4cf4c3 outdated
     9@@ -10,6 +10,7 @@
    10 class CRPCTable;
    11 class CWallet;
    12 class JSONRPCRequest;
    13+class UniValue;
    


    promag commented at 9:27 pm on September 26, 2017:
    Why?

    achow101 commented at 10:10 pm on September 26, 2017:
    UniValue is needed below for UniValue getaddressinfo...
  63. in src/wallet/rpcwallet.cpp:3279 in 8d5d4cf4c3 outdated
    3274+
    3275+    CScript scriptPubKey = GetScriptForDestination(dest);
    3276+    ret.push_back(Pair("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end())));;
    3277+
    3278+    isminetype mine = pwallet ? IsMine(*pwallet, dest) : ISMINE_NO;
    3279+    ret.push_back(Pair("ismine", (mine & ISMINE_SPENDABLE) ? true : false));
    


    promag commented at 9:32 pm on September 26, 2017:
    bool(mine & ISMINE_SPENDABLE)? Same below.
  64. in test/functional/deprecated_rpc.py:24 in df53fd1c4d outdated
    19+        self.log.info("Using -deprecatedrpc=estimatefee bypasses the error")
    20+        self.nodes[1].estimatefee(1)
    21+
    22+        # test validateaddress deprecation
    23+        dep_validate_address = self.nodes[0].validateaddress("mnvGjUy3NMj67yJ6gkK5o9e5RS33Z2Vqcu")
    24+        assert("ismine" not in dep_validate_address)
    


    jnewbery commented at 9:34 pm on September 26, 2017:

    assert is a statement, not a function:

    0assert "ismine" not in dep_validate_address
    

    same for assert below.


    achow101 commented at 10:11 pm on September 26, 2017:
    Done
  65. in test/functional/deprecated_rpc.py:22 in df53fd1c4d outdated
    17+        assert_raises_jsonrpc(-32, 'estimatefee is deprecated', self.nodes[0].estimatefee, 1)
    18+
    19+        self.log.info("Using -deprecatedrpc=estimatefee bypasses the error")
    20+        self.nodes[1].estimatefee(1)
    21+
    22+        # test validateaddress deprecation
    


    jnewbery commented at 9:34 pm on September 26, 2017:
    suggestion: change this to a self.log.info()

    achow101 commented at 10:11 pm on September 26, 2017:
    Done
  66. achow101 force-pushed on Sep 26, 2017
  67. in test/functional/deprecated_rpc.py:23 in df53fd1c4d outdated
    18+
    19+        self.log.info("Using -deprecatedrpc=estimatefee bypasses the error")
    20+        self.nodes[1].estimatefee(1)
    21+
    22+        # test validateaddress deprecation
    23+        dep_validate_address = self.nodes[0].validateaddress("mnvGjUy3NMj67yJ6gkK5o9e5RS33Z2Vqcu")
    


    jnewbery commented at 9:36 pm on September 26, 2017:
    Perhaps declare this address as a variable above (with comment) to avoid having magic strings in the RPC method call.

    achow101 commented at 10:11 pm on September 26, 2017:
    Done
  68. in test/functional/deprecated_rpc.py:24 in 8d5d4cf4c3 outdated
    18@@ -19,5 +19,11 @@ def run_test(self):
    19         self.log.info("Using -deprecatedrpc=estimatefee bypasses the error")
    20         self.nodes[1].estimatefee(1)
    21 
    22+        # test validateaddress deprecation
    23+        dep_validate_address = self.nodes[0].validateaddress("mnvGjUy3NMj67yJ6gkK5o9e5RS33Z2Vqcu")
    24+        assert("ismine" not in dep_validate_address)
    


    promag commented at 9:36 pm on September 26, 2017:
    Is it enough to check ismine key? Maybe merge nodes[0].validateaddress with nodes[0].getaddressinfo and that should contain nodes[1].validateaddress?

    achow101 commented at 10:09 pm on September 26, 2017:
    It’s enough to determine that they are returning different things as one should have ismine and the other not.
  69. jnewbery commented at 9:36 pm on September 26, 2017: member
    The changed commit broke the scripted-diff checker. You’ll need to add your -deprecatedrpc=validateaddress test as a separate commit.
  70. promag commented at 9:36 pm on September 26, 2017: member
    Only reviewed [RPC] Split part of validateaddress into getaddressinfo commit.
  71. achow101 force-pushed on Sep 26, 2017
  72. achow101 commented at 10:12 pm on September 26, 2017: member

    The changed commit broke the scripted-diff checker.

    I noticed. I believe that should be fixed now as I changed the script to exclude deprecatedrpc.py.

  73. achow101 force-pushed on Sep 26, 2017
  74. achow101 force-pushed on Sep 26, 2017
  75. achow101 force-pushed on Sep 26, 2017
  76. achow101 force-pushed on Sep 27, 2017
  77. achow101 commented at 3:26 pm on September 27, 2017: member
    Rebased onto master
  78. in src/rpc/misc.cpp:42 in fa4eea7385 outdated
    81     if (request.fHelp || request.params.size() != 1)
    82         throw std::runtime_error(
    83             "validateaddress \"address\"\n"
    84             "\nReturn information about the given bitcoin address.\n"
    85+            "DEPRECATION WARNING: Parts of this command have been deprecated and moved to getaddressinfo. To have those deprecated\n"
    86+            "information shown, start bitcoind with -deprecatedrpc=validateaddress"
    


    jnewbery commented at 8:33 pm on September 27, 2017:
    I think this warning should also say something like “Clients must transition to using getaddressinfo to access this information before upgrading to v0.17”

    achow101 commented at 0:04 am on September 28, 2017:
    Done
  79. jnewbery commented at 8:38 pm on September 27, 2017: member

    Looks generally good. One question. If I pass an invalid address to getaddressinfo, I get the following output:

    0→ bitcoin-cli getaddressinfo fAkEAdDrEsS
    1{
    2  "address": "",
    3  "scriptPubKey": "",
    4  "ismine": 0,
    5  "iswatchonly": 0,
    6  "isscript": 0
    7}
    

    I think it would be more intuitive to either:

    • have an isvalid field that returns False (like for validateaddress); or
    • throw a RPC_INVALID_ADDRESS_OR_KEY error

    What do you think?

  80. jtimon commented at 11:48 pm on September 27, 2017: contributor

    Concept ACK

    throw a RPC_INVALID_ADDRESS_OR_KEY error

    I like this option.

  81. achow101 force-pushed on Sep 28, 2017
  82. achow101 commented at 0:04 am on September 28, 2017: member

    throw a RPC_INVALID_ADDRESS_OR_KEY error

    Did that. I didn’t realize that I hadn’t added that error there.

  83. jnewbery commented at 8:38 pm on September 28, 2017: member
    ACK ea088845fb8dd903f681c4c08b6bfe412cecc536
  84. in src/wallet/rpcwallet.cpp:3680 in ea088845fb outdated
    3270+    UniValue ret(UniValue::VOBJ);
    3271+    CTxDestination dest = DecodeDestination(request.params[0].get_str());
    3272+
    3273+    // Make sure the destination is valid
    3274+    if (!IsValidDestination(dest)) {
    3275+        throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
    


    promag commented at 8:51 pm on September 28, 2017:
    Missing test.

    achow101 commented at 2:35 am on September 29, 2017:
    Added a brief test for getaddressinfo in wallet.py
  85. in src/wallet/rpcwallet.cpp:3284 in ea088845fb outdated
    3279+    ret.pushKV("address", currentAddress);
    3280+
    3281+    CScript scriptPubKey = GetScriptForDestination(dest);
    3282+    ret.pushKV("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end()));
    3283+
    3284+    isminetype mine = pwallet ? IsMine(*pwallet, dest) : ISMINE_NO;
    


    promag commented at 8:52 pm on September 28, 2017:
    pwallet is valid because of EnsureWalletIsAvailable above.

    achow101 commented at 2:35 am on September 29, 2017:
    Removed the pwallet check.
  86. in src/wallet/rpcwallet.cpp:3231 in ea088845fb outdated
    3226+
    3227+UniValue getaddressinfo(const JSONRPCRequest& request)
    3228+{
    3229+    CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
    3230+    if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
    3231+            return NullUniValue;
    


    promag commented at 8:52 pm on September 28, 2017:
    Nit, fix indentation.

    achow101 commented at 2:35 am on September 29, 2017:
    Done
  87. in src/wallet/rpcwallet.cpp:3472 in ea088845fb outdated
    3215+            UniValue a(UniValue::VARR);
    3216+            for (const CTxDestination& addr : addresses) {
    3217+                a.push_back(EncodeDestination(addr));
    3218+            }
    3219+            obj.push_back(Pair("addresses", a));
    3220+            if (whichType == TX_MULTISIG)
    


    promag commented at 8:53 pm on September 28, 2017:
    Nit, add { or single line.

    achow101 commented at 2:35 am on September 29, 2017:
    Done
  88. in src/rpc/misc.cpp:42 in ea088845fb outdated
    82         throw std::runtime_error(
    83             "validateaddress \"address\"\n"
    84             "\nReturn information about the given bitcoin address.\n"
    85+            "DEPRECATION WARNING: Parts of this command have been deprecated and moved to getaddressinfo. Clients must\n"
    86+            "transition to using getaddressinfo to access this information before upgrading to v0.17. To have those deprecated\n"
    87+            "information shown, start bitcoind with -deprecatedrpc=validateaddress"
    


    TheBlueMatt commented at 0:48 am on September 29, 2017:
    Grammar here: “To have those deprecated information shown” -> “To have those deprecated fields shown”

    achow101 commented at 2:35 am on September 29, 2017:
    Done
  89. in src/wallet/rpcwallet.cpp:3248 in ea088845fb outdated
    3243+            "  \"address\" : \"address\",        (string) The bitcoin address validated\n"
    3244+            "  \"scriptPubKey\" : \"hex\",       (string) The hex encoded scriptPubKey generated by the address\n"
    3245+            "  \"ismine\" : true|false,        (boolean) If the address is yours or not\n"
    3246+            "  \"iswatchonly\" : true|false,   (boolean) If the address is watchonly\n"
    3247+            "  \"isscript\" : true|false,      (boolean) If the key is a script\n"
    3248+            "  \"script\" : \"type\"             (string, optional) The output script type. Possible types: nonstandard, pubkey, pubkeyhash, scripthash, multisig, nulldata, witness_v0_keyhash, witness_v0_scripthash\n"
    


    TheBlueMatt commented at 0:59 am on September 29, 2017:
    While you’re at it, can you clarify the docs on this? Its the redeemScript type, afaict, not the address type…Maybe even move the redeemScript-specific stuff to a separate object? like redeemScript: { script:, hex: addresses: []}…

    achow101 commented at 2:36 am on September 29, 2017:
    I changed that field to redeemscript. I didn’t make it a separate object.
  90. in src/rpc/misc.cpp:186 in ea088845fb outdated
    132-#ifdef ENABLE_WALLET
    133-    CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
    134-
    135-    LOCK2(cs_main, pwallet ? &pwallet->cs_wallet : nullptr);
    136-#else
    137     LOCK(cs_main);
    


    TheBlueMatt commented at 1:08 am on September 29, 2017:
    I do not believe you need cs_main here anymore.
  91. in src/wallet/rpcwallet.cpp:3268 in ea088845fb outdated
    3263+            + HelpExampleCli("getaddressinfo", "\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"")
    3264+            + HelpExampleRpc("getaddressinfo", "\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"")
    3265+        );
    3266+    }
    3267+
    3268+    LOCK2(cs_main, pwallet->cs_wallet);
    


    TheBlueMatt commented at 1:08 am on September 29, 2017:
    I believe you only need cs_wallet here.

    achow101 commented at 2:36 am on September 29, 2017:
    Done.
  92. in src/rpc/misc.cpp:52 in ea088845fb outdated
     98-            "  \"iswatchonly\" : true|false,   (boolean) If the address is watchonly\n"
     99             "  \"isscript\" : true|false,      (boolean) If the key is a script\n"
    100-            "  \"script\" : \"type\"             (string, optional) The output script type. Possible types: nonstandard, pubkey, pubkeyhash, scripthash, multisig, nulldata, witness_v0_keyhash, witness_v0_scripthash\n"
    101-            "  \"hex\" : \"hex\",                (string, optional) The redeemscript for the p2sh address\n"
    102-            "  \"addresses\"                   (string, optional) Array of addresses associated with the known redeemscript\n"
    103+            "  \"ismine\" : true|false,        (boolean) DEPRECATED. If the address is yours or not\n"
    


    TheBlueMatt commented at 1:19 am on September 29, 2017:
    Why change the ordering here? UniValue returns things ordered in insertion-order (and hence bitcoin-cli and some JSON libraries will print it in that order) so might as well just leave it…having deprecation warnings interspersed is fine, they’ll all go away soon enough :)

    achow101 commented at 2:10 am on September 29, 2017:
    The idea was to group the deprecated things together. The ordering is still correct though.
  93. in src/rpc/misc.cpp:74 in ea088845fb outdated
    114-            "  \"pubkey\" : \"publickeyhex\",    (string) The hex value of the raw public key\n"
    115-            "  \"iscompressed\" : true|false,  (boolean) If the address is compressed\n"
    116+            "  \"sigsrequired\" : xxxxx        (numeric, optional) DEPRECATED. Number of signatures required to spend multisig output\n"
    117+            "  \"pubkey\" : \"publickeyhex\",    (string) DEPRECATED. The hex value of the raw public key\n"
    118+            "  \"iscompressed\" : true|false,  (boolean) DEPRECATED. If the address is compressed\n"
    119             "  \"account\" : \"account\"         (string) DEPRECATED. The account associated with the address, \"\" is the default account\n"
    


    TheBlueMatt commented at 1:23 am on September 29, 2017:
    You removed this from the output, but not the docs. For now I think we should leave the account display here, primarily just because we will want to keep it identical but just rename it label when we do accounts->label conversion.

    achow101 commented at 2:35 am on September 29, 2017:
    Added the accounts field back to the output.
  94. TheBlueMatt commented at 1:24 am on September 29, 2017: member
    Thanks for tackling one of the ifdef WALLETs!
  95. achow101 force-pushed on Sep 29, 2017
  96. achow101 commented at 2:38 am on September 29, 2017: member
    Addressed @TheBlueMatt’s and @promag’s comments. I also changed two of the pushKVs back to push_back(Pair(...)) because they were not properly showing booleans (they were displayed as 0 and 1).
  97. achow101 force-pushed on Sep 29, 2017
  98. MarcoFalke commented at 2:36 pm on September 29, 2017: member
    Needs rebase
  99. in test/functional/wallet.py:429 in 205fdcdfc1 outdated
    425@@ -426,6 +426,15 @@ def run_test(self):
    426 
    427         # Verify nothing new in wallet
    428         assert_equal(total_txs, len(self.nodes[0].listtransactions("*",99999)))
    429+        
    


    MarcoFalke commented at 2:37 pm on September 29, 2017:
    No trailing whitespace, please.

    achow101 commented at 3:15 pm on September 29, 2017:
    Removed.
  100. achow101 force-pushed on Sep 29, 2017
  101. achow101 commented at 3:15 pm on September 29, 2017: member
    Rebased onto master.
  102. achow101 force-pushed on Sep 29, 2017
  103. achow101 force-pushed on Sep 29, 2017
  104. achow101 commented at 3:33 am on October 19, 2017: member
    n’th rebase
  105. achow101 force-pushed on Oct 19, 2017
  106. achow101 force-pushed on Oct 19, 2017
  107. in src/rpc/misc.cpp:57 in d1539bd607 outdated
    147+            "  \"ismine\" : true|false,        (boolean) DEPRECATED. If the address is yours or not\n"
    148+            "  \"iswatchonly\" : true|false,   (boolean) DEPRECATED. If the address is watchonly\n"
    149+            "  \"iswitness\" : true|false,     (boolean) DEPRECATED. If the address is a witness address\n"
    150+            "  \"witness_version\" : version   (numeric, optional) DEPRECATED. The version number of the witness program\n"
    151+            "  \"witness_program\" : \"hex\"   (string, optional) DEPRECATED. The hex value of the witness program\n"
    152+            "  \"isscript\" : true|false,      (boolean) DEPRECATED. If the key is a script\n"
    


    meshcollider commented at 7:03 am on November 17, 2017:
    Is this deprecated or not? isscript is on line 51 too which hasn’t been deleted, and in the if-statement below Pair("isscript", scriptPubKey.IsPayToScriptHash()) is pushed on line 98. I think the deprecation is correct, so both those lines should be removed?

    achow101 commented at 5:04 pm on November 30, 2017:
    I think that isscript shouldn’t be deprecated, so I fixed that
  108. in src/wallet/rpcwallet.cpp:3661 in d1539bd607 outdated
    3405+            "      \"address\"\n"
    3406+            "      ,...\n"
    3407+            "    ]\n"
    3408+            "  \"sigsrequired\" : xxxxx        (numeric, optional) Number of signatures required to spend multisig output\n"
    3409+            "  \"pubkey\" : \"publickeyhex\",    (string) The hex value of the raw public key\n"
    3410+            "  \"iscompressed\" : true|false,  (boolean) If the address is compressed\n"
    


    meshcollider commented at 7:09 am on November 17, 2017:
    Should be optional. Same as pubkey on line above. Then make same changes to the deprecated fields in validateaddress so they’re consistent.

    achow101 commented at 5:04 pm on November 30, 2017:
    Done.
  109. in src/rpc/misc.cpp:57 in d1539bd607 outdated
    148+            "  \"iswatchonly\" : true|false,   (boolean) DEPRECATED. If the address is watchonly\n"
    149+            "  \"iswitness\" : true|false,     (boolean) DEPRECATED. If the address is a witness address\n"
    150+            "  \"witness_version\" : version   (numeric, optional) DEPRECATED. The version number of the witness program\n"
    151+            "  \"witness_program\" : \"hex\"   (string, optional) DEPRECATED. The hex value of the witness program\n"
    152+            "  \"isscript\" : true|false,      (boolean) DEPRECATED. If the key is a script\n"
    153+            "  \"redeemscript\" : \"type\"       (string, optional) DEPRECATED. The type of the redeemscript. Possible types: nonstandard, pubkey, pubkeyhash, scripthash, multisig, nulldata, witness_v0_keyhash, witness_v0_scripthash\n"
    


    meshcollider commented at 7:18 am on November 17, 2017:
    If the deprecation switch is enabled, should redeemscript be named script for compatibility in the output of validateaddress? Otherwise its a breaking change anyway

    achow101 commented at 5:04 pm on November 30, 2017:
    Done
  110. meshcollider commented at 7:25 am on November 17, 2017: contributor

    utACK https://github.com/bitcoin/bitcoin/pull/10583/commits/aa32c679e75e18996a26f2d4659f91cfa5654964, generally looks good, modulo some feedback inline.

    In the case of P2SH-P2WPKH and P2SH-P2WSH, IMO the output should include the witness_version and witness_program of the internal witness too. Although sipa mentioned he may have done this or something similar in 11403 I think

    The deprecation warning mentions v0.17 specifically, perhaps this should have a 0.16.0 milestone, or that may need to be modified

    Needs another rebase too sorry :)

  111. achow101 force-pushed on Nov 30, 2017
  112. achow101 force-pushed on Nov 30, 2017
  113. achow101 commented at 5:06 pm on November 30, 2017: member

    Rebased and addresses @MeshCollider’s comments.

    The P2SH nested witness info is being done in #11403.

  114. in src/rpc/misc.cpp:43 in 4ecc207a48 outdated
    125     if (request.fHelp || request.params.size() != 1)
    126         throw std::runtime_error(
    127             "validateaddress \"address\"\n"
    128             "\nReturn information about the given bitcoin address.\n"
    129+            "DEPRECATION WARNING: Parts of this command have been deprecated and moved to getaddressinfo. Clients must\n"
    130+            "transition to using getaddressinfo to access this information before upgrading to v0.17. To have those deprecated\n"
    


    instagibbs commented at 8:26 pm on November 30, 2017:
    please tell the reader what type of things are moving
  115. jnewbery commented at 6:16 pm on December 4, 2017: member

    Sorry for the late feedback after several rebases, but looking at this again I don’t really like DescribeAddressVisitor moving into bitcoin-wallet, since there’s functionality in there that’s useful even when running with wallet disabled.

    Can you take a look at https://github.com/jnewbery/bitcoin/commits/pr10583.1 . It’s almost the same as this, but I’ve moved the generic parts of DescribeAddressVisitor into rpc/util, so they can be accessed by bitcoin-server.

  116. achow101 commented at 8:05 pm on December 4, 2017: member
    @jnewbery I’ll take a look.
  117. achow101 commented at 4:25 am on December 5, 2017: member
    I cherry-picked @jnewbery’s commit for splitting and moving DescribeAddressVisitor.
  118. achow101 force-pushed on Dec 5, 2017
  119. jnewbery commented at 3:37 pm on December 5, 2017: member

    I think this is better, but obviously needs more review from others.

    Incidentally, I think that you’ve made this more difficult to review by squashing my commits down into a single commit (having a commit that splits a function into two and moves half of it to a new file is more difficult to review than one commit to split and a second commit that is move-only). You’ve also:

    • re-added the DEPRECATED notice to iswitness, witness_version and witness_program when they’re not actually now deprecated
    • re-introduced the script/redeemscript error in the help text.
  120. achow101 force-pushed on Dec 7, 2017
  121. achow101 commented at 7:39 pm on December 7, 2017: member

    I cherry-picked the split and move commits from @jnewbery and I think I fixed the regressions

    They actually weren’t squashed earlier. Rather I had only cherry picked one commit due to merge conflict stuff. That is resolved by taking the commits before mine.

  122. achow101 force-pushed on Jan 10, 2018
  123. achow101 commented at 8:04 pm on January 10, 2018: member
    Rebased this but there’s a linker error I can’t quite figure out.
  124. meshcollider commented at 9:36 am on January 11, 2018: contributor
    @achow101: I guess it might be because you’re adding rpc/util.cpp to libbitcoin_server_a_SOURCES rather than libbitcoin_util_a_SOURCES in the Makefile.am Also the scripted diff seems to have an issue
  125. achow101 force-pushed on Jan 11, 2018
  126. achow101 commented at 7:00 pm on January 11, 2018: member
    Rebased and fixed the linker error.
  127. achow101 force-pushed on Jan 11, 2018
  128. achow101 force-pushed on Feb 1, 2018
  129. achow101 commented at 9:36 pm on February 1, 2018: member
    Rebased
  130. achow101 force-pushed on Feb 1, 2018
  131. achow101 force-pushed on Feb 2, 2018
  132. achow101 force-pushed on Feb 2, 2018
  133. in src/rpc/util.cpp:76 in 1de28c236c outdated
    71+    return UniValue(UniValue::VOBJ);
    72+}
    73+
    74+UniValue DescribeAddressVisitor::operator()(const CKeyID &keyID) const {
    75+    UniValue obj(UniValue::VOBJ);
    76+    CPubKey vchPubKey;
    


  134. in src/rpc/util.cpp:84 in 1de28c236c outdated
    79+    return obj;
    80+}
    81+
    82+UniValue DescribeAddressVisitor::operator()(const CScriptID &scriptID) const {
    83+    UniValue obj(UniValue::VOBJ);
    84+    CScript subscript;
    


  135. in src/rpc/util.cpp:93 in 1de28c236c outdated
    88+}
    89+
    90+UniValue DescribeAddressVisitor::operator()(const WitnessV0KeyHash& id) const
    91+{
    92+    UniValue obj(UniValue::VOBJ);
    93+    CPubKey pubkey;
    


  136. in src/rpc/util.cpp:104 in 1de28c236c outdated
     99+}
    100+
    101+UniValue DescribeAddressVisitor::operator()(const WitnessV0ScriptHash& id) const
    102+{
    103+    UniValue obj(UniValue::VOBJ);
    104+    CScript subscript;
    


  137. in src/rpc/util.cpp:115 in 1de28c236c outdated
    110+}
    111+
    112+UniValue DescribeAddressVisitor::operator()(const WitnessUnknown& id) const
    113+{
    114+    UniValue obj(UniValue::VOBJ);
    115+    CScript subscript;
    


  138. in src/rpc/util.h:26 in 1de28c236c outdated
    22@@ -16,4 +23,17 @@ CPubKey HexToPubKey(const std::string& hex_in);
    23 CPubKey AddrToPubKey(CKeyStore* const keystore, const std::string& addr_in);
    24 CScript CreateMultisigRedeemscript(const int required, const std::vector<CPubKey>& pubkeys);
    25 
    26+class DescribeAddressVisitor : public boost::static_visitor<UniValue>
    


    jamesob commented at 9:33 pm on February 5, 2018:

    In https://github.com/bitcoin/bitcoin/pull/10583/commits/4dadd7c7ac0934447b8ca33942535cc8a22e78f5

    Curious: if we’re looking to eventually get away from using Boost, should we reserve continued/new usage of it for cases when the feature at hand would be hard to replicate on our own? Seems like each use of

    0boost::apply_visitor(DescribeAddressVisitor(), foo);
    

    could be replaced with DescribeAddressVisitor()(foo).

    I guess usages of static_visitor are relatively easy to unwind if we ever want to, and it may be worthwhile to remain consistent with our usage of it in the wallet code.

    Feel free to ignore; not proposing we hold this changeset up on the basis of Boost usage, just curious.


    sipa commented at 2:30 am on February 9, 2018:
    I think you can keep the DescribeAddressVisitor class entirely local to rpc/util.cpp, and only expose a UniValue DescribeAddress(const CTxDestination& dest) function.

    achow101 commented at 5:01 pm on February 9, 2018:
    Changed this and DescribeWalletAddressVisitor to helper functions which called the visitors.
  139. jamesob commented at 10:03 pm on February 5, 2018: member

    Tested concept ACK https://github.com/bitcoin/bitcoin/pull/10583/commits/1de28c236c593fc3af770e901ae5d2977370be3f

    A few small comments attached. I think the only blocking ones are about unused variables.

  140. achow101 force-pushed on Feb 6, 2018
  141. achow101 commented at 6:09 pm on February 6, 2018: member
    Removed the unused variables.
  142. jamesob commented at 6:29 pm on February 6, 2018: member
  143. meshcollider commented at 9:56 pm on February 7, 2018: contributor
    Hopefully this can go in soon now 0.16 is branched off, looks like a painful one to keep rebasing. Will re-review as soon as I can
  144. laanwj added this to the "Blockers" column in a project

  145. achow101 force-pushed on Feb 8, 2018
  146. achow101 commented at 8:43 pm on February 8, 2018: member
    Rebased yet again.
  147. in src/rpc/misc.cpp:73 in 9f61967fef outdated
    71+    }
    72+
    73+    UniValue operator()(const WitnessV0ScriptHash& id) const
    74+    {
    75+        UniValue obj(UniValue::VOBJ);
    76+        CScript subscript;
    


    instagibbs commented at 8:50 pm on February 8, 2018:
    unused?
  148. in src/rpc/misc.cpp:45 in 9f61967fef outdated
    42+
    43+    UniValue operator()(const CNoDestination &dest) const { return UniValue(UniValue::VOBJ); }
    44+
    45+    UniValue operator()(const CKeyID &keyID) const {
    46+        UniValue obj(UniValue::VOBJ);
    47+        CPubKey vchPubKey;
    


    instagibbs commented at 8:51 pm on February 8, 2018:
    unused?
  149. in src/rpc/misc.cpp:53 in 9f61967fef outdated
    50+        return obj;
    51+    }
    52+
    53+    UniValue operator()(const CScriptID &scriptID) const {
    54+        UniValue obj(UniValue::VOBJ);
    55+        CScript subscript;
    


    instagibbs commented at 8:51 pm on February 8, 2018:
    unused?
  150. in src/rpc/misc.cpp:62 in 9f61967fef outdated
    60 
    61-    explicit DescribeAddressVisitor(CWallet *_pwallet) : pwallet(_pwallet) {}
    62+    UniValue operator()(const WitnessV0KeyHash& id) const
    63+    {
    64+        UniValue obj(UniValue::VOBJ);
    65+        CPubKey pubkey;
    


    instagibbs commented at 8:51 pm on February 8, 2018:
    unused?
  151. in src/rpc/misc.cpp:84 in 9f61967fef outdated
    82+    }
    83+
    84+    UniValue operator()(const WitnessUnknown& id) const
    85+    {
    86+        UniValue obj(UniValue::VOBJ);
    87+        CScript subscript;
    


    instagibbs commented at 8:52 pm on February 8, 2018:
    unused?
  152. instagibbs approved
  153. instagibbs commented at 9:07 pm on February 8, 2018: member

    utACK

    unused variables don’t break anything and quickly disappear, just noting them

  154. sipa commented at 11:18 pm on February 8, 2018: member

    Looking very good, and the commits are easy to follow. A few comments:

    • The unused variables @instagibbs pointed out are removed after your move commit, but not before.
    • I think addresses and pubkeys also moved to getaddressinfo, but aren’t listed as DEPRECATED in the help.
    • Can we remove addresses from getaddressinfo at the same time? It could remain in validateaddress when -deprecatedrpc=validateaddress is given, but this is the perfect opportunity to remove it in favor of pubkeys for new users.
    • Do we need to keep the full description of all deprecated fields in validateaddress? I think you could just say at the top “DEPRECATION WARNING: The following fields have moved to getaddressinfo and are only included here when running with -deprecatedrpc=validateaddress: ismine, iswatchonly, script, sigsrequired, pubkey, pubkeys, embedded, iscompressed, timestamp, hdkeypath, hdmasterkeyid.”.
  155. achow101 force-pushed on Feb 9, 2018
  156. achow101 force-pushed on Feb 9, 2018
  157. achow101 commented at 1:40 am on February 9, 2018: member
    • Removed the extra unused variables
    • Shortened validateaddress help
    • Set addresses to only be shown if -deprecatedrpc=validateaddress is set.
  158. achow101 force-pushed on Feb 9, 2018
  159. in src/rpc/misc.cpp:45 in 66ba1b84c7 outdated
    156             "validateaddress \"address\"\n"
    157             "\nReturn information about the given bitcoin address.\n"
    158+            "DEPRECATION WARNING: Parts of this command have been deprecated and moved to getaddressinfo. Clients must\n"
    159+            "transition to using getaddressinfo to access this information before upgrading to v0.18. The following deprecated\n"
    160+            "fields have moved to getaddressinfo and will only be shown here with -deprecatedrpc=validateaddress: ismine, iswatchonly,\n"
    161+            "script, hex, pubkeys, sigsrequired, pubkey, embedded, iscompressed, account, timestamp, hdkeypath, kdmasterkeyid.\n"
    


    sipa commented at 2:14 am on February 9, 2018:
    There probably still needs to be a mention of addresses, as there is now no information about it anywhere anymore.

    achow101 commented at 5:00 pm on February 9, 2018:
    Added mention of it back.
  160. in src/wallet/rpcwallet.cpp:3565 in 66ba1b84c7 outdated
    3560+
    3561+        // The "addresses" field is confusing because it refers to public keys using their P2PKH address.
    3562+        // For that reason, only add the 'addresses' field when needed for backward compatibility. New applications
    3563+        // can use the 'embedded'->'address' field for P2SH or P2WSH wrapped addresses, and 'pubkeys' for
    3564+        // inspecting multisig participants.
    3565+        if (IsDeprecatedRPCEnabled("validateaddress")) obj.pushKV("addresses", std::move(a));
    


    sipa commented at 2:27 am on February 9, 2018:
    This will include the addresses field when -deprecatedrpc=validateaddress is set, even for witness addresses (currently it will only include it for legacy addresses).

    achow101 commented at 5:01 pm on February 9, 2018:
    I changed it back to the original one and used IsDeprecatedRPC in a different place to handle this issue.
  161. achow101 force-pushed on Feb 9, 2018
  162. achow101 force-pushed on Feb 9, 2018
  163. in src/rpc/util.cpp:126 in ba2cc57065 outdated
    121+};
    122+
    123+UniValue DescribeAddress(CTxDestination dest)
    124+{
    125+    return boost::apply_visitor(DescribeAddressVisitor(), dest);
    126+}
    


    promag commented at 10:28 pm on February 15, 2018:
    Nit, add newline.

    achow101 commented at 11:28 pm on February 15, 2018:
    Done
  164. in src/rpc/util.cpp:86 in ba2cc57065 outdated
    81+        obj.push_back(Pair("isscript", false));
    82+        obj.push_back(Pair("iswitness", false));
    83+        return obj;
    84+    }
    85+
    86+    UniValue operator()(const CScriptID &scriptID) const {
    


    promag commented at 10:28 pm on February 15, 2018:
    Nit, const CScriptID& scriptID. { on new line.

    achow101 commented at 11:28 pm on February 15, 2018:
    Done
  165. in src/rpc/util.cpp:75 in ba2cc57065 outdated
    70+class DescribeAddressVisitor : public boost::static_visitor<UniValue>
    71+{
    72+public:
    73+    explicit DescribeAddressVisitor() {}
    74+
    75+    UniValue operator()(const CNoDestination &dest) const {
    


    promag commented at 10:29 pm on February 15, 2018:
    Nit, const CNoDestination& dest . { on new line.

    achow101 commented at 11:28 pm on February 15, 2018:
    Done
  166. in src/rpc/misc.cpp:56 in ba2cc57065 outdated
    194-            "  \"hdkeypath\" : \"keypath\"       (string, optional) The HD keypath if the key is HD and available\n"
    195-            "  \"hdmasterkeyid\" : \"<hash160>\" (string, optional) The Hash160 of the HD master pubkey\n"
    196+            "  \"isscript\" : true|false,      (boolean) If the key is a script\n"
    197+            "  \"iswitness\" : true|false,     (boolean) If the address is a witness address\n"
    198+            "  \"witness_version\" : version   (numeric, optional) The version number of the witness program\n"
    199+            "  \"witness_program\" : \"hex\"   (string, optional) The hex value of the witness program\n"
    


    promag commented at 10:30 pm on February 15, 2018:
    Fix alignment.

    achow101 commented at 11:32 pm on February 15, 2018:
    Done
  167. in src/Makefile.am:337 in ba2cc57065 outdated
    333@@ -335,6 +334,7 @@ libbitcoin_common_a_SOURCES = \
    334   scheduler.cpp \
    335   script/sign.cpp \
    336   script/standard.cpp \
    337+  script/ismine.cpp \
    


    promag commented at 10:30 pm on February 15, 2018:
    Nit, sort.

    achow101 commented at 11:28 pm on February 15, 2018:
    Done
  168. in src/Makefile.am:392 in ba2cc57065 outdated
    388@@ -389,10 +389,10 @@ endif
    389 
    390 bitcoind_LDADD = \
    391   $(LIBBITCOIN_SERVER) \
    392+  $(LIBBITCOIN_WALLET) \
    


    promag commented at 10:30 pm on February 15, 2018:
    Why this change? Does the order matter? 🙄

    achow101 commented at 11:17 pm on February 15, 2018:
    Yes, the order matters
  169. in src/rpc/util.h:26 in ba2cc57065 outdated
    22@@ -16,4 +23,6 @@ CPubKey HexToPubKey(const std::string& hex_in);
    23 CPubKey AddrToPubKey(CKeyStore* const keystore, const std::string& addr_in);
    24 CScript CreateMultisigRedeemscript(const int required, const std::vector<CPubKey>& pubkeys);
    25 
    26+UniValue DescribeAddress(CTxDestination dest);
    


    promag commented at 10:33 pm on February 15, 2018:
    const CTxDestination& dest.

    achow101 commented at 11:28 pm on February 15, 2018:
    Done
  170. in src/wallet/rpcwallet.cpp:30 in ba2cc57065 outdated
    26@@ -27,6 +27,7 @@
    27 #include <wallet/feebumper.h>
    28 #include <wallet/wallet.h>
    29 #include <wallet/walletdb.h>
    30+#include <wallet/rpcwallet.h>
    


    promag commented at 10:33 pm on February 15, 2018:
    Nit, sort.

    achow101 commented at 11:31 pm on February 15, 2018:
    Done
  171. in src/wallet/rpcwallet.cpp:3521 in ba2cc57065 outdated
    3515@@ -3515,6 +3516,207 @@ UniValue rescanblockchain(const JSONRPCRequest& request)
    3516     return response;
    3517 }
    3518 
    3519+class DescribeWalletAddressVisitor : public boost::static_visitor<UniValue>
    3520+{
    3521+public:
    3522+    CWallet * const pwallet;
    


    promag commented at 10:34 pm on February 15, 2018:
    Nit, m_wallet, why public?

    achow101 commented at 11:17 pm on February 15, 2018:
    why not?

    promag commented at 9:34 am on February 16, 2018:

    See CAffectedKeysVisitor, DestinationEncoder and CScriptVisitor with private members. On the other hand Witnessifier members are public (could be “fixed”) .

    IMO all members, by default, should be private. When reading the code it’s clear that a private member is not externally accessed/changed.

  172. promag commented at 10:36 pm on February 15, 2018: member
    Needs rebase, some comments (mostly nits).
  173. [rpc] split wallet and non-wallet parts of DescribeAddressVisitor 39633ecd5c
  174. in src/rpc/util.cpp:79 in ba2cc57065 outdated
    74+
    75+    UniValue operator()(const CNoDestination &dest) const {
    76+        return UniValue(UniValue::VOBJ);
    77+    }
    78+
    79+    UniValue operator()(const CKeyID &keyID) const {
    


    promag commented at 10:37 pm on February 15, 2018:
    Nit, const CKeyID& keyID. { on new line.

    achow101 commented at 11:28 pm on February 15, 2018:
    Done
  175. achow101 force-pushed on Feb 15, 2018
  176. achow101 force-pushed on Feb 15, 2018
  177. in src/wallet/rpcwallet.cpp:3571 in baef775c41 outdated
    3566+
    3567+    explicit DescribeWalletAddressVisitor(CWallet *_pwallet) : pwallet(_pwallet) {}
    3568+
    3569+    UniValue operator()(const CNoDestination &dest) const { return UniValue(UniValue::VOBJ); }
    3570+
    3571+    UniValue operator()(const CKeyID &keyID) const {
    


    promag commented at 9:36 am on February 16, 2018:
    & before space and { new line.
  178. in src/wallet/rpcwallet.cpp:3581 in baef775c41 outdated
    3576+            obj.pushKV("iscompressed", vchPubKey.IsCompressed());
    3577+        }
    3578+        return obj;
    3579+    }
    3580+
    3581+    UniValue operator()(const CScriptID &scriptID) const {
    


    promag commented at 9:36 am on February 16, 2018:
    & before space and { new line.
  179. in src/rpc/util.cpp:75 in baef775c41 outdated
    70+class DescribeAddressVisitor : public boost::static_visitor<UniValue>
    71+{
    72+public:
    73+    explicit DescribeAddressVisitor() {}
    74+
    75+    UniValue operator()(const CNoDestination &dest) const 
    


    promag commented at 9:41 am on February 16, 2018:
    & before space.

    instagibbs commented at 2:47 pm on February 16, 2018:
    travis linter is complaining about trailing whitespace…. I don’t know protocol if it matters but just reporting where the complaint is coming from
  180. in src/wallet/rpcwallet.cpp:3569 in baef775c41 outdated
    3564+        if (include_addresses) obj.pushKV("addresses", std::move(a));
    3565+    }
    3566+
    3567+    explicit DescribeWalletAddressVisitor(CWallet *_pwallet) : pwallet(_pwallet) {}
    3568+
    3569+    UniValue operator()(const CNoDestination &dest) const { return UniValue(UniValue::VOBJ); }
    


    promag commented at 9:42 am on February 16, 2018:
    & before space.
  181. in src/wallet/rpcwallet.cpp:3694 in baef775c41 outdated
    3687+    isminetype mine = IsMine(*pwallet, dest);
    3688+    ret.pushKV("ismine", bool(mine & ISMINE_SPENDABLE));
    3689+    ret.pushKV("iswatchonly", bool(mine & ISMINE_WATCH_ONLY));
    3690+    UniValue detail = DescribeWalletAddress(pwallet, dest);
    3691+    ret.pushKVs(detail);
    3692+    if (pwallet->mapAddressBook.count(dest)) {
    


    promag commented at 9:46 am on February 16, 2018:
    Use find to avoid 2nd lookup below (unless you don’t want to touch moved code).
  182. in src/wallet/rpcwallet.cpp:3648 in baef775c41 outdated
    3643+            "  \"ismine\" : true|false,        (boolean) If the address is yours or not\n"
    3644+            "  \"iswatchonly\" : true|false,   (boolean) If the address is watchonly\n"
    3645+            "  \"isscript\" : true|false,      (boolean) If the key is a script\n"
    3646+            "  \"iswitness\" : true|false,     (boolean) If the address is a witness address\n"
    3647+            "  \"witness_version\" : version   (numeric, optional) The version number of the witness program\n"
    3648+            "  \"witness_program\" : \"hex\"   (string, optional) The hex value of the witness program\n"
    


    promag commented at 9:53 am on February 16, 2018:
    Fix alignment.
  183. in src/wallet/rpcwallet.cpp:3649 in baef775c41 outdated
    3644+            "  \"iswatchonly\" : true|false,   (boolean) If the address is watchonly\n"
    3645+            "  \"isscript\" : true|false,      (boolean) If the key is a script\n"
    3646+            "  \"iswitness\" : true|false,     (boolean) If the address is a witness address\n"
    3647+            "  \"witness_version\" : version   (numeric, optional) The version number of the witness program\n"
    3648+            "  \"witness_program\" : \"hex\"   (string, optional) The hex value of the witness program\n"
    3649+            "  \"script\" : \"type\"       (string, optional) The output script type. Only if \"isscript\" is true and the redeemscript is known. Possible types: nonstandard, pubkey, pubkeyhash, scripthash, multisig, nulldata, witness_v0_keyhash, witness_v0_scripthash, witness_unknown\n"
    


    promag commented at 9:53 am on February 16, 2018:
    Fix alignment.
  184. in src/wallet/rpcwallet.cpp:3660 in baef775c41 outdated
    3653+            "      \"pubkey\"\n"
    3654+            "      ,...\n"
    3655+            "    ]\n"
    3656+            "  \"sigsrequired\" : xxxxx        (numeric, optional) Number of signatures required to spend multisig output (only if \"script\" is \"multisig\")\n"
    3657+            "  \"pubkey\" : \"publickeyhex\",    (string, optional) The hex value of the raw public key, for single-key addresses (possibly embedded in P2SH or P2WSH)\n"
    3658+            "  \"embedded\" : {...},           (object, optional) Information about the address embedded in P2SH or P2WSH, if relevant and known. It includes all getaddressinfo output fields for the embedded address, excluding metadata (\"timestamp\", \"hdkeypath\", \"hdmasterkeyid\") and relation to the wallet (\"ismine\", \"iswatchonly\", \"account\").\n"
    


    promag commented at 9:58 am on February 16, 2018:
    Remove period? (my personal preference if to add period on all, currently it’s a mix)
  185. in src/wallet/rpcwallet.cpp:3567 in baef775c41 outdated
    3562+        // can use the 'embedded'->'address' field for P2SH or P2WSH wrapped addresses, and 'pubkeys' for
    3563+        // inspecting multisig participants.
    3564+        if (include_addresses) obj.pushKV("addresses", std::move(a));
    3565+    }
    3566+
    3567+    explicit DescribeWalletAddressVisitor(CWallet *_pwallet) : pwallet(_pwallet) {}
    


    promag commented at 9:59 am on February 16, 2018:
    * before space.
  186. in src/wallet/rpcwallet.cpp:3620 in baef775c41 outdated
    3613+    UniValue operator()(const WitnessUnknown& id) const { return UniValue(UniValue::VOBJ); }
    3614+};
    3615+
    3616+UniValue DescribeWalletAddress(CWallet* pwallet, const CTxDestination& dest)
    3617+{
    3618+    UniValue ret(UniValue::VOBJ);
    


    promag commented at 10:01 am on February 16, 2018:
    Nit, could AssertLockHeld(pwallet->cs_wallet).
  187. in src/wallet/rpcwallet.cpp:3586 in baef775c41 outdated
    3579+    }
    3580+
    3581+    UniValue operator()(const CScriptID &scriptID) const {
    3582+        UniValue obj(UniValue::VOBJ);
    3583+        CScript subscript;
    3584+        if (pwallet && pwallet->GetCScript(scriptID, subscript)) {
    


    promag commented at 10:02 am on February 16, 2018:

    In this context pwallet is valid so:

    0if (pwallet->GetCScript(scriptID, subscript)) {
    
  188. in src/wallet/rpcwallet.cpp:3575 in baef775c41 outdated
    3569+    UniValue operator()(const CNoDestination &dest) const { return UniValue(UniValue::VOBJ); }
    3570+
    3571+    UniValue operator()(const CKeyID &keyID) const {
    3572+        UniValue obj(UniValue::VOBJ);
    3573+        CPubKey vchPubKey;
    3574+        if (pwallet && pwallet->GetPubKey(keyID, vchPubKey)) {
    


    promag commented at 10:03 am on February 16, 2018:

    In this context pwallet is valid so:

    0if (pwallet->GetCScript(scriptID, subscript)) {
    
  189. in src/wallet/rpcwallet.cpp:3608 in baef775c41 outdated
    3601+    {
    3602+        UniValue obj(UniValue::VOBJ);
    3603+        CScript subscript;
    3604+        CRIPEMD160 hasher;
    3605+        uint160 hash;
    3606+        hasher.Write(id.begin(), 32).Finalize(hash.begin());
    


    promag commented at 10:06 am on February 16, 2018:

    Unless you don’t want to touch moved code, remove hasher and just do:

    0CRIPEMD160().Write(id.begin(), 32).Finalize(hash.begin());
    
  190. in src/wallet/rpcwallet.cpp:3609 in baef775c41 outdated
    3602+        UniValue obj(UniValue::VOBJ);
    3603+        CScript subscript;
    3604+        CRIPEMD160 hasher;
    3605+        uint160 hash;
    3606+        hasher.Write(id.begin(), 32).Finalize(hash.begin());
    3607+        if (pwallet && pwallet->GetCScript(CScriptID(hash), subscript)) {
    


    promag commented at 10:07 am on February 16, 2018:

    In this context pwallet is valid so:

    0if (pwallet->GetCScript(CScriptID(hash), subscript)) {
    
  191. in src/rpc/misc.cpp:72 in baef775c41 outdated
    253-                if (!meta->hdKeypath.empty()) {
    254-                    ret.pushKV("hdkeypath", meta->hdKeypath);
    255-                    ret.pushKV("hdmasterkeyid", meta->hdMasterKeyID.GetHex());
    256-                }
    257-            }
    258+        if (!::vpwallets.empty() && IsDeprecatedRPCEnabled("validateaddress")) {
    


    promag commented at 10:09 am on February 16, 2018:
    Why !::vpwallets.empty()? There is alwasy one wallet right?

    achow101 commented at 5:07 pm on February 16, 2018:
    No, you can run with -disablewallet which will disable wallets and thus vpwallets will be empty.
  192. in src/rpc/util.cpp:80 in baef775c41 outdated
    75+    UniValue operator()(const CNoDestination &dest) const 
    76+    {
    77+        return UniValue(UniValue::VOBJ);
    78+    }
    79+
    80+    UniValue operator()(const CKeyID &keyID) const
    


    promag commented at 10:10 am on February 16, 2018:
    & before space.
  193. in src/rpc/util.cpp:88 in baef775c41 outdated
    83+        obj.pushKV("isscript", false);
    84+        obj.pushKV("iswitness", false);
    85+        return obj;
    86+    }
    87+
    88+    UniValue operator()(const CScriptID &scriptID) const
    


    promag commented at 10:10 am on February 16, 2018:
    & before space.
  194. in src/wallet/rpcwallet.cpp:3596 in baef775c41 outdated
    3589+
    3590+    UniValue operator()(const WitnessV0KeyHash& id) const
    3591+    {
    3592+        UniValue obj(UniValue::VOBJ);
    3593+        CPubKey pubkey;
    3594+        if (pwallet && pwallet->GetPubKey(CKeyID(id), pubkey)) {
    


    promag commented at 10:11 am on February 16, 2018:

    In this context pwallet is valid so:

    0if (pwallet->GetPubKey(CKeyID(id), pubkey)) {
    
  195. promag commented at 10:24 am on February 16, 2018: member
    Lightly tested ACK. Please consider the following comments.
  196. jnewbery commented at 2:36 pm on February 16, 2018: member

    @promag - personally, I’d generally discourage nits after a PR has been open for many months and been rebased/re-reviewed many times already. Adding additional churn and workload to the contributor and reviewers at this point seems borderline sadistic :slightly_smiling_face:

    (just my opinion though)

  197. [rpc] Move DescribeAddressVisitor to rpc/util 1598f32304
  198. Create getaddressinfo RPC and deprecate parts of validateaddress
    Moves the parts of validateaddress which require the wallet into getaddressinfo
    which is part of the wallet RPCs. Mark those parts of validateaddress which
    require the wallet as deprecated.
    
    Validateaddress will  call getaddressinfo
    for the data that both share for right now.
    
    Moves IsMine functions to libbitcoin_common and then links libbitcoin_wallet
    before libbitcoin_common in order to prevent linker errors since IsMine is no
    longer used in libbitcoin_server.
    b98bfc5ed0
  199. scripted-diff: validateaddress to getaddressinfo in tests
    Change all instances of validateaddress to getaddressinfo since it seems that
    no test actually uses validateaddress for actually validating addresses.
    
    -BEGIN VERIFY SCRIPT-
    find ./test/functional -path '*py' -not -path ./test/functional/wallet_disable.py -not -path ./test/functional/rpc_deprecated.py -not -path ./test/functional/wallet_address_types.py -exec sed -i'' -e 's/validateaddress/getaddressinfo/g' {} \;
    -END VERIFY SCRIPT-
    b22cce0148
  200. achow101 force-pushed on Feb 16, 2018
  201. achow101 commented at 5:10 pm on February 16, 2018: member
    Addressed some of @promag’s nits. I don’t really feel like fixing the other ones. It’s also getting really tedious to do fix nits at this point, so I probably won’t do so in the future for this PR.
  202. jnewbery commented at 6:48 pm on February 16, 2018: member

    Tested ACK b22cce014852b082d80f1cc35f902b375cba0318. Travis failure looks unrelated.

    Let’s get this merged!

  203. sipa commented at 7:12 pm on February 16, 2018: member

    utACK b22cce014852b082d80f1cc35f902b375cba0318

    I have a few minor improvements, but I’ll submit them as a separate PR after merge, nothing worth holding this up for.

  204. promag commented at 7:20 pm on February 16, 2018: member
    @jnewbery @achow101 sorry! didn’t want to cause such pain :) I did report tested ACK.
  205. jonasschnelli commented at 11:27 am on February 17, 2018: contributor
    Tested ACK b22cce014
  206. jonasschnelli merged this on Feb 17, 2018
  207. jonasschnelli closed this on Feb 17, 2018

  208. jonasschnelli referenced this in commit 8a98dfeebf on Feb 17, 2018
  209. laanwj removed this from the "Blockers" column in a project

  210. tynes referenced this in commit 5b47d87430 on Mar 16, 2019
  211. fanquake removed the label Needs release note on Mar 20, 2019
  212. tynes referenced this in commit 26a2000b01 on Mar 26, 2019
  213. tynes referenced this in commit d350c097af on Apr 2, 2019
  214. boymanjor referenced this in commit 62b4de584c on Apr 9, 2019
  215. tuxcanfly referenced this in commit 4c6c73e555 on Apr 19, 2019
  216. xdustinface referenced this in commit 122078b9ec on Dec 17, 2020
  217. DrahtBot locked this on Dec 16, 2021

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 09:12 UTC

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