2020-05-28 02:13:19 -04:00
|
|
|
// Copyright (c) 2020 The Bitcoin Core developers
|
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#ifndef BITCOIN_WALLET_CONTEXT_H
|
|
|
|
#define BITCOIN_WALLET_CONTEXT_H
|
|
|
|
|
2020-05-28 13:06:43 -04:00
|
|
|
#include <sync.h>
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include <list>
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
2020-05-11 11:40:21 -04:00
|
|
|
class ArgsManager;
|
2020-05-28 13:06:43 -04:00
|
|
|
class CWallet;
|
2020-05-28 02:13:19 -04:00
|
|
|
namespace interfaces {
|
|
|
|
class Chain;
|
2020-05-28 13:06:43 -04:00
|
|
|
class Wallet;
|
2020-05-28 02:13:19 -04:00
|
|
|
} // namespace interfaces
|
|
|
|
|
2020-05-28 13:06:43 -04:00
|
|
|
using LoadWalletFn = std::function<void(std::unique_ptr<interfaces::Wallet> wallet)>;
|
|
|
|
|
2020-05-28 02:13:19 -04:00
|
|
|
//! WalletContext struct containing references to state shared between CWallet
|
|
|
|
//! instances, like the reference to the chain interface, and the list of opened
|
|
|
|
//! wallets.
|
|
|
|
//!
|
|
|
|
//! Future shared state can be added here as an alternative to adding global
|
|
|
|
//! variables.
|
|
|
|
//!
|
|
|
|
//! The struct isn't intended to have any member functions. It should just be a
|
|
|
|
//! collection of state pointers that doesn't pull in dependencies or implement
|
|
|
|
//! behavior.
|
|
|
|
struct WalletContext {
|
|
|
|
interfaces::Chain* chain{nullptr};
|
2020-05-28 13:06:43 -04:00
|
|
|
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);
|
2020-05-28 02:13:19 -04:00
|
|
|
|
|
|
|
//! Declare default constructor and destructor that are not inline, so code
|
|
|
|
//! instantiating the WalletContext struct doesn't need to #include class
|
|
|
|
//! definitions for smart pointer and container members.
|
|
|
|
WalletContext();
|
|
|
|
~WalletContext();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // BITCOIN_WALLET_CONTEXT_H
|