While working on this PR https://github.com/bitcoin/bitcoin/pull/18570 I ran into a bit confusing situation where in one function a **CWallet reference** was expected while two others dealt with **CWallet pointers**. My initial reaction was: `let's harmonize them by making them references`. However, not being part of the PR itself I did't change anything and completed the PR first.

Now, after having analyzed the `rpcwallet.cpp` code I came to the conclusion that:

* converting them all into references is not the solution as they're originally **shared_ptr**s
* but also: there is no (visible) reason why every RPC function should begin like this:

```cpp
std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
const CWallet* const pwallet = wallet.get();
```

This clearly defeats the purpose of shared pointers for no obvious reason. *Maybe I am missing something?*

In my (unpublished) [code changes](https://github.com/brakmic/bitcoin/commit/0b3ee615491edf6f542631bf6ae6f72eac406550) all raw pointers got replaced with **shared_ptr**s but kept their original names (that is, *pwallet*). In the end, they're pointers too, so the most of the original code remained untouched.

However, some of the helper functions couldn't be changed because external code is accessing them and I didn't want to make this task "virulent". So I introduced new ("Ref") variants that expect **shared_ptr** parameters, namely: 

```cpp
void EnsureWalletRefIsUnlocked(const std::shared_ptr<CWallet>);
bool EnsureWalletRefIsAvailable(const std::shared_ptr<CWallet>, bool avoidException);
```

I have tested the code, with python and boost-tests, and could not find any errors. 
But before opening a PR I would like to open a discussion about this. 

Is there any reason to keep on working with raw pointers when every function call actually begins with *shared_ptr*s?

Regards,
{RPCResult::Type::STR, "pubkey", ""},
                        }},
                        {RPCResult::Type::NUM, "sigsrequired",  true, "The number of signatures required to spend multisig output (only if script is multisig)."},
                        {RPCResult::Type::STR_HEX, "pubkey",  true, "The hex value of the raw public key for single-key addresses (possibly embedded in P2SH or P2WSH)."},
                        {RPCResult::Type::OBJ, "embedded",  true, "Information about the address embedded in P2SH or P2WSH, if relevant and known.",
                        {
                            {RPCResult::Type::ELISION, "", "Includes all getaddressinfo output fields for the embedded address, excluding metadata (timestamp, hdkeypath, hdseedid)\n"
                            "and relation to the wallet (ismine, iswatchonly)."},
                        }},
                        {RPCResult::Type::BOOL, "iscompressed",  true, "If the pubkey is compressed."},
                        {RPCResult::Type::NUM_TIME, "timestamp",  true, "The creation time of the key, if available, expressed in " + UNIX_EPOCH_TIME + "."},
                        {RPCResult::Type::STR, "hdkeypath",  true, "The HD keypath, if the key is HD and available."},
                        {RPCResult::Type::STR_HEX, "hdseedid",  true, "The Hash160 of the HD seed."},
                        {RPCResult::Type::STR_HEX, "hdmasterfingerprint",  true, "The fingerprint of the master key."},
                        {RPCResult::Type::ARR, "labels", "Array of labels associated with the address. Currently limited to one label but returned\n"
                            "as an array to keep the API stable if multiple labels are enabled in the future.",
                        {
                            {RPCResult::Type::STR, "label name", "Label name (defaults to \"\")."},
                        }},
                    }
                },
                RPCExamples{
                    HelpExampleCli("getaddressinfo", "\"" + EXAMPLE_ADDRESS[0] + "\"") +
                    HelpExampleRpc("getaddressinfo", "\"" + EXAMPLE_ADDRESS[0] + "\"")
                },
        [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
    std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
    if (!wallet) return NullUniValue;
    const CWallet* const pwallet = wallet.get();