dash/src/wallet
Konstantin Akimov 86dc99f10d
refactor: using reference instead reference to unique_ptr with object (#5381)
## Issue being fixed or feature implemented
Many objects created and functions called by passing `const
std::unique_ptr<Obj>& obj` instead directly passing `Obj& obj`

In some cases it is indeed needed, but in most cases it is just extra
complexity that is better to avoid.

Motivation:
- providing reference to object instead `unique_ptr` is giving warranty
that there's no `nullptr` and no need to keep it in mind
- value inside unique_ptr by reference can be changed externally and
instead `nullptr` it can turn to real object later (or in opposite)
 - code is shorter but cleaner

Based on that this refactoring is useful as it reduces mental load when
reading or writing code.
`std::unique` should be used ONLY for owning object, but not for passing
it everywhere.

## What was done?
Replaced most of usages `std::unique_ptr<Obj>& obj` to `Obj& obj`.
Btw, in several cases implementation assumes that object can be nullptr
and replacement to reference is not possible.
Even using raw pointer is not possible, because the empty
std::unique_ptr can be initialized later somewhere in code.
For example, in `src/init.cpp` there's called `PeerManager::make` and
pass unique_ptr to the `node.llmq_ctx` that would be initialized way
later.
That is out of scope this PR.
List of cases, where reference to `std::unique_ptr` stayed as they are:
- `std::unique_ptr<LLMQContext>& llmq_ctx` in `PeerManagerImpl`,
`PeerManager` and `CDSNotificationInterface`
- `std::unique_ptr<CDeterministicMNManager>& dmnman` in
`CDSNotificationInterface`

Also `CChainState` have 3 references to `unique_ptr` that can't be
replaced too:
 - `std::unique_ptr<llmq::CChainLocksHandler>& m_clhandler;`
 - `std::unique_ptr<llmq::CInstantSendManager>& m_isman;`
- `std::unique_ptr<llmq::CQuorumBlockProcessor>&
m_quorum_block_processor;`


## How Has This Been Tested?
Run unit/functional tests.

## Breaking Changes
No breaking changes, all of these changes - are internal APIs for Dash
Core developers only.

## Checklist:
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have added or updated relevant unit/integration/functional/e2e
tests
- [x] I have made corresponding changes to the documentation
- [x] I have assigned this pull request to a milestone

---------

Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2023-06-04 15:26:23 -05:00
..
test Merge #17585: rpc: deprecate getaddressinfo label 2023-05-31 18:14:23 -05:00
bdb.cpp Merge #17891: scripted-diff: Replace CCriticalSection with RecursiveMutex 2023-05-24 12:43:57 -05:00
bdb.h Merge #20952: wallet: Add BerkeleyDB version sanity check at init time 2023-04-09 00:06:56 -05:00
coincontrol.cpp Merge #15906: [wallet] Move min_depth and max_depth to coin control 2023-04-04 12:45:27 -05:00
coincontrol.h Merge #15906: [wallet] Move min_depth and max_depth to coin control 2023-04-04 12:45:27 -05:00
coinselection.cpp merge bitcoin#21415: remove Optional & nullopt 2022-10-20 16:08:45 -05:00
coinselection.h
context.cpp
context.h
crypter.cpp
crypter.h
db.cpp Merge #17891: scripted-diff: Replace CCriticalSection with RecursiveMutex 2023-05-24 12:43:57 -05:00
db.h merge bitcoin#20275: List all wallets in non-SQLite and non-BDB builds 2023-02-07 10:53:33 -06:00
fees.cpp
fees.h
init.cpp Merge #16524: Wallet: Disable -fallbackfee by default 2023-04-17 10:42:25 -05:00
interfaces.cpp Merge #18192: Bugfix: Wallet: Safely deal with change in the address book 2023-05-31 18:14:23 -05:00
ismine.h
load.cpp Merge #21516: remove unnecessary newline from initWarning() argument 2023-04-14 23:34:13 -05:00
load.h revert: revert bitcoin#15454 (Remove the automatic creation and loading of the default wallet) 2022-12-04 18:02:40 -06:00
rpcdump.cpp Merge #18192: Bugfix: Wallet: Safely deal with change in the address book 2023-05-31 18:14:23 -05:00
rpcwallet.cpp Merge #18192: Bugfix: Wallet: Safely deal with change in the address book 2023-05-31 18:14:23 -05:00
rpcwallet.h Merge #17261: Make ScriptPubKeyMan an actual interface and the wallet to have multiple 2023-03-19 11:08:31 -05:00
salvage.cpp Merge #17261: Make ScriptPubKeyMan an actual interface and the wallet to have multiple 2023-03-19 11:08:31 -05:00
salvage.h
scriptpubkeyman.cpp partial bitcoin#17938: Disallow automatic conversion between disparate hash types 2023-04-15 12:12:30 -05:00
scriptpubkeyman.h Merge #17891: scripted-diff: Replace CCriticalSection with RecursiveMutex 2023-05-24 12:43:57 -05:00
sqlite.cpp fix: 5072 follow-ups (#5197) 2023-02-12 20:12:53 -06:00
sqlite.h merge bitcoin#20275: List all wallets in non-SQLite and non-BDB builds 2023-02-07 10:53:33 -06:00
wallet.cpp refactor: using reference instead reference to unique_ptr with object (#5381) 2023-06-04 15:26:23 -05:00
wallet.h Merge #18192: Bugfix: Wallet: Safely deal with change in the address book 2023-05-31 18:14:23 -05:00
walletdb.cpp Merge #18192: Bugfix: Wallet: Safely deal with change in the address book 2023-05-31 18:14:23 -05:00
walletdb.h Merge #15709: wallet: Do not add "setting" key as unknown 2023-03-29 21:01:56 +03:00
wallettool.cpp Merge #18192: Bugfix: Wallet: Safely deal with change in the address book 2023-05-31 18:14:23 -05:00
wallettool.h merge bitcoin#19619: Remove wallet.dat path handling from wallet.cpp, rpcwallet.cpp 2022-10-17 08:03:10 +05:30
walletutil.cpp merge bitcoin#20275: List all wallets in non-SQLite and non-BDB builds 2023-02-07 10:53:33 -06:00
walletutil.h merge bitcoin#20275: List all wallets in non-SQLite and non-BDB builds 2023-02-07 10:53:33 -06:00