Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show All 36 Lines | |||||
#include <wallet/finaltx.h> | #include <wallet/finaltx.h> | ||||
#include <boost/algorithm/string/replace.hpp> | #include <boost/algorithm/string/replace.hpp> | ||||
#include <algorithm> | #include <algorithm> | ||||
#include <cassert> | #include <cassert> | ||||
#include <future> | #include <future> | ||||
static std::vector<CWallet *> vpwallets; | static CCriticalSection cs_wallets; | ||||
static std::vector<CWallet *> vpwallets GUARDED_BY(cs_wallets); | |||||
bool AddWallet(CWallet *wallet) { | bool AddWallet(CWallet *wallet) { | ||||
LOCK(cs_wallets); | |||||
assert(wallet); | assert(wallet); | ||||
std::vector<CWallet *>::const_iterator i = | std::vector<CWallet *>::const_iterator i = | ||||
std::find(vpwallets.begin(), vpwallets.end(), wallet); | std::find(vpwallets.begin(), vpwallets.end(), wallet); | ||||
if (i != vpwallets.end()) { | if (i != vpwallets.end()) { | ||||
return false; | return false; | ||||
} | } | ||||
vpwallets.push_back(wallet); | vpwallets.push_back(wallet); | ||||
return true; | return true; | ||||
} | } | ||||
bool RemoveWallet(CWallet *wallet) { | bool RemoveWallet(CWallet *wallet) { | ||||
LOCK(cs_wallets); | |||||
assert(wallet); | assert(wallet); | ||||
std::vector<CWallet *>::iterator i = | std::vector<CWallet *>::iterator i = | ||||
std::find(vpwallets.begin(), vpwallets.end(), wallet); | std::find(vpwallets.begin(), vpwallets.end(), wallet); | ||||
if (i == vpwallets.end()) { | if (i == vpwallets.end()) { | ||||
return false; | return false; | ||||
} | } | ||||
vpwallets.erase(i); | vpwallets.erase(i); | ||||
return true; | return true; | ||||
} | } | ||||
bool HasWallets() { | bool HasWallets() { | ||||
LOCK(cs_wallets); | |||||
return !vpwallets.empty(); | return !vpwallets.empty(); | ||||
} | } | ||||
std::vector<CWallet *> GetWallets() { | std::vector<CWallet *> GetWallets() { | ||||
LOCK(cs_wallets); | |||||
return vpwallets; | return vpwallets; | ||||
} | } | ||||
CWallet *GetWallet(const std::string &name) { | CWallet *GetWallet(const std::string &name) { | ||||
LOCK(cs_wallets); | |||||
for (CWallet *wallet : vpwallets) { | for (CWallet *wallet : vpwallets) { | ||||
if (wallet->GetName() == name) { | if (wallet->GetName() == name) { | ||||
return wallet; | return wallet; | ||||
} | } | ||||
} | } | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 4,608 Lines • Show Last 20 Lines |