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,
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid redeem script \"" + strRedeemScript + "\": must be hex string");
        }
        auto parsed_redeemscript = ParseHex(strRedeemScript);
        import_data.redeemscript = MakeUnique<CScript>(parsed_redeemscript.begin(), parsed_redeemscript.end());
    }
    if (witness_script_hex.size()) {
        if (!IsHex(witness_script_hex)) {
            throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid witness script \"" + witness_script_hex + "\": must be hex string");
        }
        auto parsed_witnessscript = ParseHex(witness_script_hex);
        import_data.witnessscript = MakeUnique<CScript>(parsed_witnessscript.begin(), parsed_witnessscript.end());
    }
    for (size_t i = 0; i < pubKeys.size(); ++i) {
        const auto& str = pubKeys[i].get_str();
        if (!IsHex(str)) {
            throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Pubkey \"" + str + "\" must be a hex string");
        }
        auto parsed_pubkey = ParseHex(str);
        CPubKey pubkey(parsed_pubkey.begin(), parsed_pubkey.end());
        if (!pubkey.IsFullyValid()) {
            throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Pubkey \"" + str + "\" is not a valid public key");
        }
        pubkey_map.emplace(pubkey.GetID(), pubkey);
        ordered_pubkeys.push_back(pubkey.GetID());
    }
    for (size_t i = 0; i < keys.size(); ++i) {
        const auto& str = keys[i].get_str();
        CKey key = DecodeSecret(str);
        if (!key.IsValid()) {
            throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key encoding");