rpcwallet: ‘ischange’ field for ‘getaddressinfo’ RPC #14410

pull rodentrabies wants to merge 2 commits into bitcoin:master from rodentrabies:getaddressinfo-is-change changing 5 files +30 −3
  1. rodentrabies commented at 9:58 pm on October 5, 2018: contributor

    Implementation of proposal in #14396.

    This introduces CWallet::IsChange(CScript&) method and replaces original CWallet::IsChange(CTxOut&) method with overloaded version that delegates to the new method with txout’s scriptPubKey. In this way TODO note from the original method can still be addressed in a single place.

  2. fanquake added the label Wallet on Oct 5, 2018
  3. fanquake added the label RPC/REST/ZMQ on Oct 5, 2018
  4. rodentrabies force-pushed on Oct 6, 2018
  5. promag commented at 0:04 am on October 7, 2018: member

    Not sure about this.. What is the rationale?

    Also, could test the new field.

  6. instagibbs commented at 7:22 am on October 8, 2018: member
    concept ACK, needs test. @promag Why not? It’s useful to probe the state of the wallet, especially when using things like importmulti where this can be set.
  7. in src/wallet/rpcwallet.cpp:3543 in c2f4b3324c outdated
    3539@@ -3540,6 +3540,7 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
    3540             "  \"ismine\" : true|false,        (boolean) If the address is yours or not\n"
    3541             "  \"iswatchonly\" : true|false,   (boolean) If the address is watchonly\n"
    3542             "  \"isscript\" : true|false,      (boolean) If the key is a script\n"
    3543+            "  \"ischange\" : true|false,      (boolean) If the address is for change output\n"
    


    promag commented at 8:13 am on October 8, 2018:
    Reading this looks like the address can be reused. Suggestion If the address was used for change output?

    rodentrabies commented at 12:10 pm on October 9, 2018:
    Thanks for the suggestion. Fixed that.
  8. promag commented at 8:20 am on October 8, 2018: member

    @instagibbs because it can be misleading? Especially if you fundrawtransaction with explicit changeAddress

    especially when using things like importmulti where this can be set.

    I’m not following, can you explain?

  9. achow101 commented at 0:46 am on October 9, 2018: member

    especially when using things like importmulti where this can be set.

    I’m not following, can you explain?

    importmulti lets you mark imported things as internal, i.e. change. It can be useful to know whether something is change, especially if it was imported and so other ways of identifying change addresses may not be useful.

  10. rodentrabies force-pushed on Oct 9, 2018
  11. in src/wallet/wallet.h:964 in ee014ae452 outdated
    960@@ -961,6 +961,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
    961     isminetype IsMine(const CTxOut& txout) const;
    962     CAmount GetCredit(const CTxOut& txout, const isminefilter& filter) const;
    963     bool IsChange(const CTxOut& txout) const;
    964+    bool IsChange(const CScript& dest) const;
    


    practicalswift commented at 9:21 am on October 10, 2018:

    Please make the parameter naming between those two consistent:

    0bool CWallet::IsChange(const CScript& script) const {  }
    1bool IsChange(const CScript& dest) const;
    

    Make both script or both dest :-)


    rodentrabies commented at 9:41 am on October 10, 2018:
    Done.
  12. rodentrabies force-pushed on Oct 10, 2018
  13. rodentrabies commented at 11:11 am on October 12, 2018: contributor
    I’m not sure it needs a dedicated test, so I added testing of ischange field to wallet_address_types.py functional test.
  14. in test/functional/wallet_address_types.py:164 in fa7b6fb070 outdated
    158@@ -159,6 +159,13 @@ def test_change_output_type(self, node_sender, destinations, expected_type):
    159         change_addresses = [d for d in output_addresses if d not in destinations]
    160         assert_equal(len(change_addresses), 1)
    161 
    162+        # Check if 'getaddressinfo' correctly marks change address as change:
    163+        for d in output_addresses:
    164+            if d in destinations:
    


    promag commented at 11:14 am on October 12, 2018:

    nit,

    0for address in output_addresses
    1    assert_equal(self.nodes[node_sender].getaddressinfo(address)['ischange'], address not in destinations)
    

    rodentrabies commented at 3:30 pm on October 12, 2018:
    Done, with some changes though:)
  15. in test/functional/wallet_address_types.py:162 in fa7b6fb070 outdated
    158@@ -159,6 +159,13 @@ def test_change_output_type(self, node_sender, destinations, expected_type):
    159         change_addresses = [d for d in output_addresses if d not in destinations]
    160         assert_equal(len(change_addresses), 1)
    161 
    162+        # Check if 'getaddressinfo' correctly marks change address as change:
    


    promag commented at 11:20 am on October 12, 2018:
    Maybe this does not belong here — test_change_output_type? Maybe somewhere in wallet_basic.py?

    rodentrabies commented at 3:33 pm on October 12, 2018:
    Moved it to wallet_basic.py with some additional code to ensure transaction with change.
  16. promag commented at 11:21 am on October 12, 2018: member
    Agree that there’s no need for a dedicated test.
  17. rodentrabies force-pushed on Oct 12, 2018
  18. rodentrabies force-pushed on Oct 12, 2018
  19. rodentrabies force-pushed on Oct 12, 2018
  20. sipa commented at 7:04 pm on October 12, 2018: member

    utACK 9298081df8a9b538cf5b572fd99f7063a67dae76

    No reason why this can’t be exposed.

  21. promag commented at 11:18 pm on October 12, 2018: member

    Could test that setting a label for a change address sets ischange to false. This is the test change:

     0@@ -497,7 +497,12 @@ class WalletTest(BitcoinTestFramework):
     1         output_addresses = [vout['scriptPubKey']['addresses'][0] for vout in tx["vout"]]
     2         assert len(output_addresses) > 1
     3         for address in output_addresses:
     4-            assert_equal(self.nodes[0].getaddressinfo(address)['ischange'], address != destination)
     5+            ischange = self.nodes[0].getaddressinfo(address)['ischange']
     6+            assert_equal(ischange, address != destination)
     7+            if ischange: change = address
     8+        self.nodes[0].setlabel(change, 'foobar')
     9+        assert_equal(self.nodes[0].getaddressinfo(change)['ischange'], False)
    10
    11 if __name__ == '__main__':
    12     WalletTest().main()
    

    Also could add a small release note? Maybe in doc/release-notes-14282.md?

    Tested ACK 9298081.

  22. rpcwallet: add 'ischange' field to 'getaddressinfo' response 93d1aa9abc
  23. rodentrabies force-pushed on Oct 13, 2018
  24. rodentrabies commented at 4:34 pm on October 13, 2018: contributor
    @promag done and done (amended release node into first commit and test fix into second one). Let me know if release note is ok.
  25. tests: add test for 'getaddressinfo' RPC result 'ischange' field 14a06525b2
  26. rodentrabies force-pushed on Oct 13, 2018
  27. DrahtBot commented at 10:13 am on October 20, 2018: member

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

    Conflicts

    No conflicts as of last run.

  28. promag commented at 6:29 pm on November 4, 2018: member
    utACK 14a06525.
  29. MarcoFalke merged this on Nov 4, 2018
  30. MarcoFalke closed this on Nov 4, 2018

  31. MarcoFalke referenced this in commit b74078868b on Nov 4, 2018
  32. rodentrabies deleted the branch on Nov 4, 2018
  33. fanquake deleted a comment on Nov 5, 2018
  34. fanquake locked this on Nov 5, 2018

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

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