mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 12:32:48 +01:00
Wallet: Replace pwalletMain with a vector of wallet pointers
This commit is contained in:
parent
19b3648bb5
commit
b124cf04ea
21
src/init.cpp
21
src/init.cpp
@ -198,8 +198,9 @@ void Shutdown()
|
||||
StopRPC();
|
||||
StopHTTPServer();
|
||||
#ifdef ENABLE_WALLET
|
||||
if (pwalletMain)
|
||||
pwalletMain->Flush(false);
|
||||
for (CWalletRef pwallet : vpwallets) {
|
||||
pwallet->Flush(false);
|
||||
}
|
||||
#endif
|
||||
MapPort(false);
|
||||
UnregisterValidationInterface(peerLogic.get());
|
||||
@ -239,8 +240,9 @@ void Shutdown()
|
||||
pblocktree = NULL;
|
||||
}
|
||||
#ifdef ENABLE_WALLET
|
||||
if (pwalletMain)
|
||||
pwalletMain->Flush(true);
|
||||
for (CWalletRef pwallet : vpwallets) {
|
||||
pwallet->Flush(true);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ENABLE_ZMQ
|
||||
@ -260,8 +262,10 @@ void Shutdown()
|
||||
#endif
|
||||
UnregisterAllValidationInterfaces();
|
||||
#ifdef ENABLE_WALLET
|
||||
delete pwalletMain;
|
||||
pwalletMain = NULL;
|
||||
for (CWalletRef pwallet : vpwallets) {
|
||||
delete pwallet;
|
||||
}
|
||||
vpwallets.clear();
|
||||
#endif
|
||||
globalVerifyHandle.reset();
|
||||
ECC_Stop();
|
||||
@ -1673,8 +1677,9 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
uiInterface.InitMessage(_("Done loading"));
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
if (pwalletMain)
|
||||
pwalletMain->postInitProcess(scheduler);
|
||||
for (CWalletRef pwallet : vpwallets) {
|
||||
pwallet->postInitProcess(scheduler);
|
||||
}
|
||||
#endif
|
||||
|
||||
return !fRequestShutdown;
|
||||
|
@ -474,9 +474,10 @@ void BitcoinApplication::initializeResult(bool success)
|
||||
window->setClientModel(clientModel);
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
if(pwalletMain)
|
||||
// TODO: Expose secondary wallets
|
||||
if (!vpwallets.empty())
|
||||
{
|
||||
walletModel = new WalletModel(platformStyle, pwalletMain, optionsModel);
|
||||
walletModel = new WalletModel(platformStyle, vpwallets[0], optionsModel);
|
||||
|
||||
window->addWallet(BitcoinGUI::DEFAULT_WALLET, walletModel);
|
||||
window->setCurrentWallet(BitcoinGUI::DEFAULT_WALLET);
|
||||
|
@ -439,11 +439,6 @@ void CWalletDBWrapper::IncrementUpdateCounter()
|
||||
++nUpdateCounter;
|
||||
}
|
||||
|
||||
unsigned int CWalletDBWrapper::GetUpdateCounter()
|
||||
{
|
||||
return nUpdateCounter.load();
|
||||
}
|
||||
|
||||
void CDB::Close()
|
||||
{
|
||||
if (!pdb)
|
||||
|
@ -93,13 +93,13 @@ class CWalletDBWrapper
|
||||
friend class CDB;
|
||||
public:
|
||||
/** Create dummy DB handle */
|
||||
CWalletDBWrapper(): env(nullptr)
|
||||
CWalletDBWrapper() : nLastSeen(0), nLastFlushed(0), nLastWalletUpdate(0), env(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
/** Create DB handle to real database */
|
||||
CWalletDBWrapper(CDBEnv *env_in, const std::string &strFile_in) :
|
||||
env(env_in), strFile(strFile_in)
|
||||
nLastSeen(0), nLastFlushed(0), nLastWalletUpdate(0), env(env_in), strFile(strFile_in)
|
||||
{
|
||||
}
|
||||
|
||||
@ -120,13 +120,16 @@ public:
|
||||
void Flush(bool shutdown);
|
||||
|
||||
void IncrementUpdateCounter();
|
||||
unsigned int GetUpdateCounter();
|
||||
|
||||
std::atomic<unsigned int> nUpdateCounter;
|
||||
unsigned int nLastSeen;
|
||||
unsigned int nLastFlushed;
|
||||
int64_t nLastWalletUpdate;
|
||||
|
||||
private:
|
||||
/** BerkeleyDB specific */
|
||||
CDBEnv *env;
|
||||
std::string strFile;
|
||||
std::atomic<unsigned int> nUpdateCounter;
|
||||
|
||||
/** Return whether this database handle is a dummy for testing.
|
||||
* Only to be used at a low level, application should ideally not care
|
||||
|
@ -33,7 +33,8 @@
|
||||
|
||||
CWallet *GetWalletForJSONRPCRequest(const JSONRPCRequest& request)
|
||||
{
|
||||
return pwalletMain;
|
||||
// TODO: Some way to access secondary wallets
|
||||
return vpwallets.empty() ? nullptr : vpwallets[0];
|
||||
}
|
||||
|
||||
std::string HelpRequiringPassphrase(CWallet * const pwallet)
|
||||
|
@ -8,6 +8,8 @@
|
||||
#include "wallet/db.h"
|
||||
#include "wallet/wallet.h"
|
||||
|
||||
CWallet *pwalletMain;
|
||||
|
||||
WalletTestingSetup::WalletTestingSetup(const std::string& chainName):
|
||||
TestingSetup(chainName)
|
||||
{
|
||||
|
@ -19,6 +19,8 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <univalue.h>
|
||||
|
||||
extern CWallet* pwalletMain;
|
||||
|
||||
extern UniValue importmulti(const JSONRPCRequest& request);
|
||||
extern UniValue dumpwallet(const JSONRPCRequest& request);
|
||||
extern UniValue importwallet(const JSONRPCRequest& request);
|
||||
@ -402,8 +404,7 @@ BOOST_FIXTURE_TEST_CASE(rescan, TestChain100Setup)
|
||||
// after.
|
||||
{
|
||||
CWallet wallet;
|
||||
CWallet *backup = ::pwalletMain;
|
||||
::pwalletMain = &wallet;
|
||||
vpwallets.insert(vpwallets.begin(), &wallet);
|
||||
UniValue keys;
|
||||
keys.setArray();
|
||||
UniValue key;
|
||||
@ -434,7 +435,7 @@ BOOST_FIXTURE_TEST_CASE(rescan, TestChain100Setup)
|
||||
"downloading and rescanning the relevant blocks (see -reindex and -rescan "
|
||||
"options).\"}},{\"success\":true}]",
|
||||
0, oldTip->GetBlockTimeMax(), TIMESTAMP_WINDOW));
|
||||
::pwalletMain = backup;
|
||||
vpwallets.erase(vpwallets.begin());
|
||||
}
|
||||
}
|
||||
|
||||
@ -444,7 +445,6 @@ BOOST_FIXTURE_TEST_CASE(rescan, TestChain100Setup)
|
||||
// than or equal to key birthday.
|
||||
BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
|
||||
{
|
||||
CWallet *pwalletMainBackup = ::pwalletMain;
|
||||
LOCK(cs_main);
|
||||
|
||||
// Create two blocks with same timestamp to verify that importwallet rescan
|
||||
@ -470,7 +470,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
|
||||
JSONRPCRequest request;
|
||||
request.params.setArray();
|
||||
request.params.push_back("wallet.backup");
|
||||
::pwalletMain = &wallet;
|
||||
vpwallets.insert(vpwallets.begin(), &wallet);
|
||||
::dumpwallet(request);
|
||||
}
|
||||
|
||||
@ -482,7 +482,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
|
||||
JSONRPCRequest request;
|
||||
request.params.setArray();
|
||||
request.params.push_back("wallet.backup");
|
||||
::pwalletMain = &wallet;
|
||||
vpwallets[0] = &wallet;
|
||||
::importwallet(request);
|
||||
|
||||
BOOST_CHECK_EQUAL(wallet.mapWallet.size(), 3);
|
||||
@ -495,7 +495,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
|
||||
}
|
||||
|
||||
SetMockTime(0);
|
||||
::pwalletMain = pwalletMainBackup;
|
||||
vpwallets.erase(vpwallets.begin());
|
||||
}
|
||||
|
||||
// Check that GetImmatureCredit() returns a newly calculated value instead of
|
||||
|
@ -35,7 +35,7 @@
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
CWallet* pwalletMain = NULL;
|
||||
std::vector<CWalletRef> vpwallets;
|
||||
/** Transaction fee set by the user */
|
||||
CFeeRate payTxFee(DEFAULT_TRANSACTION_FEE);
|
||||
unsigned int nTxConfirmTarget = DEFAULT_TX_CONFIRM_TARGET;
|
||||
@ -3926,7 +3926,6 @@ CWallet* CWallet::CreateWalletFromFile(const std::string walletFile)
|
||||
bool CWallet::InitLoadWallet()
|
||||
{
|
||||
if (GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
|
||||
pwalletMain = NULL;
|
||||
LogPrintf("Wallet disabled!\n");
|
||||
return true;
|
||||
}
|
||||
@ -3943,7 +3942,7 @@ bool CWallet::InitLoadWallet()
|
||||
if (!pwallet) {
|
||||
return false;
|
||||
}
|
||||
pwalletMain = pwallet;
|
||||
vpwallets.push_back(pwallet);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -29,7 +29,8 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
extern CWallet* pwalletMain;
|
||||
typedef CWallet* CWalletRef;
|
||||
extern std::vector<CWalletRef> vpwallets;
|
||||
|
||||
/**
|
||||
* Settings
|
||||
|
@ -760,24 +760,23 @@ void MaybeCompactWalletDB()
|
||||
return;
|
||||
}
|
||||
|
||||
CWalletDBWrapper& dbh = pwalletMain->GetDBHandle();
|
||||
for (CWalletRef pwallet : vpwallets) {
|
||||
CWalletDBWrapper& dbh = pwallet->GetDBHandle();
|
||||
|
||||
static unsigned int nLastSeen = dbh.GetUpdateCounter();
|
||||
static unsigned int nLastFlushed = dbh.GetUpdateCounter();
|
||||
static int64_t nLastWalletUpdate = GetTime();
|
||||
unsigned int nUpdateCounter = dbh.nUpdateCounter;
|
||||
|
||||
if (nLastSeen != dbh.GetUpdateCounter())
|
||||
{
|
||||
nLastSeen = dbh.GetUpdateCounter();
|
||||
nLastWalletUpdate = GetTime();
|
||||
if (dbh.nLastSeen != nUpdateCounter) {
|
||||
dbh.nLastSeen = nUpdateCounter;
|
||||
dbh.nLastWalletUpdate = GetTime();
|
||||
}
|
||||
|
||||
if (nLastFlushed != dbh.GetUpdateCounter() && GetTime() - nLastWalletUpdate >= 2)
|
||||
{
|
||||
if (dbh.nLastFlushed != nUpdateCounter && GetTime() - dbh.nLastWalletUpdate >= 2) {
|
||||
if (CDB::PeriodicFlush(dbh)) {
|
||||
nLastFlushed = dbh.GetUpdateCounter();
|
||||
dbh.nLastFlushed = nUpdateCounter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fOneThread = false;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user