wallet: replace raw pointer with const reference in AddrToPubKey #17584

pull brakmic wants to merge 1 commits into bitcoin:master from brakmic:rpcwallet-redundant-pointer-conversion changing 3 files +5 −5
  1. brakmic commented at 10:15 PM on November 24, 2019: contributor

    This PR replaces a redundant reference-to-pointer conversion in addmultisigaddress from wallet/rpcwallet.cpp. It also makes the API from rpc/util.h look more straightforward as AddrToPubKey now uses const references like other functions from there.

    I am not sure why there is a ref-to-ptr conversion in addmultisignatures, so I can only speculate that this is because of "historical reasons".

    The ref-to-ptr conversion happens here: https://github.com/bitcoin/bitcoin/blob/master/src/wallet/rpcwallet.cpp#L1001

    There, the address of LegacyScriptPubKeyMan& is given to AddrToPubKey.

    Later, in AddrToPubKey, it gets converted back to a reference, because GetKeyForDestination in rpc/util.cpp expects a const ref: https://github.com/bitcoin/bitcoin/blob/master/src/rpc/util.cpp#L140

    Regards,

  2. wallet: replace raw pointer with const reference in AddrToPubKey 1a3a256d5e
  3. fanquake added the label RPC/REST/ZMQ on Nov 24, 2019
  4. fanquake added the label Wallet on Nov 24, 2019
  5. MarcoFalke added the label Refactoring on Nov 24, 2019
  6. MarcoFalke removed the label RPC/REST/ZMQ on Nov 24, 2019
  7. practicalswift commented at 12:10 AM on November 25, 2019: contributor

    Concept ACK

  8. instagibbs commented at 4:27 PM on November 25, 2019: member

    Any idea why it was a pointer in the first place? Always happy to get rid of pointers.

    concept ACK

  9. vasild commented at 9:01 PM on November 25, 2019: member

    The pointer argument was introduced in 1df206f854. Maybe @achow101 remembers?

    At that time the keystore argument was used in two expressions inside AddrToPubKey(): GetKeyForDestination(*keystore, dest) and keystore->GetPubKey(). The first takes a const reference arg and in the second GetPubKey() method is marked as const (even back then). So it cannot have been that keystore was a pointer (to non-const!) only to be able to use it inside AddrToPubKey().

    However at that time all callers of GetKeyForDestination() used a dereferenced pointer:

    1df206f854:src/rpc/misc.cpp:229:            CKeyID key_id = GetKeyForDestination(*pwallet, dest);
    1df206f854:src/rpc/util.cpp:33:    CKeyID key = GetKeyForDestination(*keystore, dest);
    1df206f854:src/wallet/rpcdump.cpp:606:    auto keyid = GetKeyForDestination(*pwallet, dest);
    

    So maybe it was due to some code mimicing?

    Other callers of GetKeyForDestination() have switched to using a const reference, so this change should be welcome.

    Concept ACK

  10. achow101 commented at 10:21 PM on November 25, 2019: member

    So maybe it was due to some code mimicing?

    More like code copying.

    Concept ACK

  11. promag commented at 11:02 PM on November 25, 2019: member

    Code review ACK 1a3a256d5e0443d19757c1f1fceb9c9ede17758a.

  12. hebasto approved
  13. hebasto commented at 11:30 PM on November 25, 2019: member

    ACK 1a3a256d5e0443d19757c1f1fceb9c9ede17758a, I have not tested the code, but I have reviewed it and it looks OK, I agree it can be merged.

  14. achow101 commented at 11:49 PM on November 25, 2019: member

    ACK 1a3a256d5e0443d19757c1f1fceb9c9ede17758a

  15. meshcollider commented at 8:26 AM on November 26, 2019: contributor

    utACK 1a3a256d5e0443d19757c1f1fceb9c9ede17758a

  16. meshcollider referenced this in commit 0ee914ba9e on Nov 26, 2019
  17. meshcollider merged this on Nov 26, 2019
  18. meshcollider closed this on Nov 26, 2019

  19. brakmic deleted the branch on Nov 26, 2019
  20. sidhujag referenced this in commit 3815259236 on Nov 27, 2019
  21. deadalnix referenced this in commit be62d940c4 on Oct 1, 2020
  22. sidhujag referenced this in commit f9fcb62a04 on Nov 10, 2020
  23. MarcoFalke 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: 2026-04-13 15:14 UTC

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