refactor: remove ::vpwallets and related global variables

Move global wallet variables to WalletContext struct
This commit is contained in:
Russell Yanofsky
2020-05-28 13:06:43 -04:00
parent fdd80b0a53
commit 62a09a3077
13 changed files with 167 additions and 127 deletions

View File

@ -5,11 +5,22 @@
#ifndef BITCOIN_WALLET_CONTEXT_H
#define BITCOIN_WALLET_CONTEXT_H
#include <sync.h>
#include <functional>
#include <list>
#include <memory>
#include <vector>
class ArgsManager;
class CWallet;
namespace interfaces {
class Chain;
class Wallet;
} // namespace interfaces
using LoadWalletFn = std::function<void(std::unique_ptr<interfaces::Wallet> wallet)>;
//! WalletContext struct containing references to state shared between CWallet
//! instances, like the reference to the chain interface, and the list of opened
//! wallets.
@ -22,7 +33,10 @@ class Chain;
//! behavior.
struct WalletContext {
interfaces::Chain* chain{nullptr};
ArgsManager* args{nullptr};
ArgsManager* args{nullptr}; // Currently a raw pointer because the memory is not managed by this struct
Mutex wallets_mutex;
std::vector<std::shared_ptr<CWallet>> wallets GUARDED_BY(wallets_mutex);
std::list<LoadWalletFn> wallet_load_fns GUARDED_BY(wallets_mutex);
//! Declare default constructor and destructor that are not inline, so code
//! instantiating the WalletContext struct doesn't need to #include class