Skip to content

Commit 4bbad5c

Browse files
committed
[Wallet] Replace pwalletMain with a vector of wallet pointers
>>> adapts bitcoin/bitcoin@b124cf0
1 parent 100d67c commit 4bbad5c

21 files changed

+84
-54
lines changed

src/budget/budgetmanager.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,17 @@ uint256 CBudgetManager::SubmitFinalBudget()
107107
// create the collateral tx, send it to the network and return
108108
CTransactionRef wtx;
109109
// Get our change address
110-
CReserveKey keyChange(pwalletMain);
111-
if (!pwalletMain->CreateBudgetFeeTX(wtx, budgetHash, keyChange, true)) {
110+
if (vpwallets.empty() || !vpwallets[0]) {
111+
LogPrint(BCLog::MNBUDGET,"%s: Wallet not found\n", __func__);
112+
return UINT256_ZERO;
113+
}
114+
CReserveKey keyChange(vpwallets[0]);
115+
if (!vpwallets[0]->CreateBudgetFeeTX(wtx, budgetHash, keyChange, true)) {
112116
LogPrint(BCLog::MNBUDGET,"%s: Can't make collateral transaction\n", __func__);
113117
return UINT256_ZERO;
114118
}
115119
// Send the tx to the network
116-
const CWallet::CommitResult& res = pwalletMain->CommitTransaction(wtx, keyChange, g_connman.get());
120+
const CWallet::CommitResult& res = vpwallets[0]->CommitTransaction(wtx, keyChange, g_connman.get());
117121
if (res.status == CWallet::CommitStatus::OK) {
118122
const uint256& collateraltxid = wtx->GetHash();
119123
mapUnconfirmedFeeTx.emplace(budgetHash, collateraltxid);

src/init.cpp

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,9 @@ void PrepareShutdown()
221221
StopRPC();
222222
StopHTTPServer();
223223
#ifdef ENABLE_WALLET
224-
if (pwalletMain)
225-
pwalletMain->Flush(false);
224+
for (CWalletRef pwallet : vpwallets) {
225+
pwallet->Flush(false);
226+
}
226227
GenerateBitcoins(false, NULL, 0);
227228
#endif
228229
StopMapPort();
@@ -301,8 +302,9 @@ void PrepareShutdown()
301302
evoDb.reset();
302303
}
303304
#ifdef ENABLE_WALLET
304-
if (pwalletMain)
305-
pwalletMain->Flush(true);
305+
for (CWalletRef pwallet : vpwallets) {
306+
pwallet->Flush(true);
307+
}
306308
#endif
307309

308310
if (pEvoNotificationInterface) {
@@ -354,8 +356,10 @@ void Shutdown()
354356
PrepareShutdown();
355357
}
356358
#ifdef ENABLE_WALLET
357-
delete pwalletMain;
358-
pwalletMain = NULL;
359+
for (CWalletRef pwallet : vpwallets) {
360+
delete pwallet;
361+
}
362+
vpwallets.clear();
359363
#endif
360364
globalVerifyHandle.reset();
361365
ECC_Stop();
@@ -1877,14 +1881,15 @@ bool AppInitMain()
18771881
strBudgetMode = gArgs.GetArg("-budgetvotemode", "auto");
18781882

18791883
#ifdef ENABLE_WALLET
1880-
if (gArgs.GetBoolArg("-mnconflock", DEFAULT_MNCONFLOCK) && pwalletMain) {
1881-
LOCK(pwalletMain->cs_wallet);
1884+
// use only the first wallet here. This section can be removed after transition to DMN
1885+
if (gArgs.GetBoolArg("-mnconflock", DEFAULT_MNCONFLOCK) && !vpwallets.empty() && vpwallets[0]) {
1886+
LOCK(vpwallets[0]->cs_wallet);
18821887
LogPrintf("Locking Masternodes collateral utxo:\n");
18831888
uint256 mnTxHash;
18841889
for (const auto& mne : masternodeConfig.getEntries()) {
18851890
mnTxHash.SetHex(mne.getTxHash());
18861891
COutPoint outpoint = COutPoint(mnTxHash, (unsigned int) std::stoul(mne.getOutputIndex()));
1887-
pwalletMain->LockCoin(outpoint);
1892+
vpwallets[0]->LockCoin(outpoint);
18881893
LogPrintf("Locked collateral, MN: %s, tx hash: %s, output index: %s\n",
18891894
mne.getAlias(), mne.getTxHash(), mne.getOutputIndex());
18901895
}
@@ -1918,11 +1923,13 @@ bool AppInitMain()
19181923

19191924
#ifdef ENABLE_WALLET
19201925
{
1921-
if (pwalletMain) {
1922-
LOCK(pwalletMain->cs_wallet);
1923-
LogPrintf("setKeyPool.size() = %u\n", pwalletMain ? pwalletMain->GetKeyPoolSize() : 0);
1924-
LogPrintf("mapWallet.size() = %u\n", pwalletMain ? pwalletMain->mapWallet.size() : 0);
1925-
LogPrintf("mapAddressBook.size() = %u\n", pwalletMain ? pwalletMain->GetAddressBookSize() : 0);
1926+
int idx = 0;
1927+
for (CWalletRef pwallet : vpwallets) {
1928+
LogPrintf("Wallet %d\n", idx++);
1929+
LOCK(pwallet->cs_wallet);
1930+
LogPrintf("setKeyPool.size() = %u\n", pwallet->GetKeyPoolSize());
1931+
LogPrintf("mapWallet.size() = %u\n", pwallet->mapWallet.size());
1932+
LogPrintf("mapAddressBook.size() = %u\n", pwallet->GetAddressBookSize());
19261933
}
19271934
}
19281935
#endif
@@ -1953,22 +1960,21 @@ bool AppInitMain()
19531960
return UIError(strNodeError);
19541961

19551962
#ifdef ENABLE_WALLET
1956-
// Generate coins in the background
1957-
if (pwalletMain)
1958-
GenerateBitcoins(gArgs.GetBoolArg("-gen", DEFAULT_GENERATE), pwalletMain, gArgs.GetArg("-genproclimit", DEFAULT_GENERATE_PROCLIMIT));
1963+
// Generate coins in the background (disabled on mainnet. use only wallet 0)
1964+
if (!vpwallets.empty())
1965+
GenerateBitcoins(gArgs.GetBoolArg("-gen", DEFAULT_GENERATE), vpwallets[0], gArgs.GetArg("-genproclimit", DEFAULT_GENERATE_PROCLIMIT));
19591966
#endif
19601967

19611968
// ********************************************************* Step 12: finished
19621969

19631970
#ifdef ENABLE_WALLET
1964-
if (pwalletMain) {
1965-
uiInterface.InitMessage(_("Reaccepting wallet transactions..."));
1966-
pwalletMain->postInitProcess(scheduler);
1967-
1968-
// StakeMiner thread disabled by default on regtest
1969-
if (gArgs.GetBoolArg("-staking", !Params().IsRegTestNet() && DEFAULT_STAKING)) {
1970-
threadGroup.create_thread(std::bind(&ThreadStakeMinter));
1971-
}
1971+
uiInterface.InitMessage(_("Reaccepting wallet transactions..."));
1972+
for (CWalletRef pwallet : vpwallets) {
1973+
pwallet->postInitProcess(scheduler);
1974+
}
1975+
// StakeMiner thread disabled by default on regtest
1976+
if (!vpwallets.empty() && gArgs.GetBoolArg("-staking", !Params().IsRegTestNet() && DEFAULT_STAKING)) {
1977+
threadGroup.create_thread(std::bind(&ThreadStakeMinter));
19721978
}
19731979
#endif
19741980

src/masternode.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ bool CMasternodeBroadcast::Create(const std::string& strService,
251251
}
252252

253253
std::string strError;
254-
if (!pwalletMain->GetMasternodeVinAndKeys(txin, pubKeyCollateralAddressNew, keyCollateralAddressNew, strTxHash, strOutputIndex, strError)) {
254+
// Use wallet-0 here. Legacy mnb creation can be removed after transition to DMN
255+
if (vpwallets.empty() || !vpwallets[0]->GetMasternodeVinAndKeys(txin, pubKeyCollateralAddressNew, keyCollateralAddressNew, strTxHash, strOutputIndex, strError)) {
255256
strErrorRet = strError; // GetMasternodeVinAndKeys logs this error. Only returned for GUI error notification.
256257
LogPrint(BCLog::MASTERNODE,"CMasternodeBroadcast::Create -- %s\n", strprintf("Could not allocate txin %s:%s for masternode %s", strTxHash, strOutputIndex, strService));
257258
return false;

src/miner.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ void GenerateBitcoins(bool fGenerate, CWallet* pwallet, int nThreads)
306306
void ThreadStakeMinter()
307307
{
308308
boost::this_thread::interruption_point();
309-
LogPrintf("ThreadStakeMinter started\n");
310-
CWallet* pwallet = pwalletMain;
309+
LogPrintf("ThreadStakeMinter started. Using wallet-0\n");
310+
CWallet* pwallet = vpwallets[0];
311311
try {
312312
BitcoinMiner(pwallet, true);
313313
boost::this_thread::interruption_point();

src/qt/pivx.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,9 @@ void BitcoinApplication::initializeResult(int retval)
487487
window->setClientModel(clientModel);
488488

489489
#ifdef ENABLE_WALLET
490-
if (pwalletMain) {
491-
walletModel = new WalletModel(pwalletMain, optionsModel);
490+
// TODO: Expose secondary wallets
491+
if (!vpwallets.empty()) {
492+
walletModel = new WalletModel(vpwallets[0], optionsModel);
492493
walletModel->setClientModel(clientModel);
493494

494495
window->addWallet(PIVXGUI::DEFAULT_WALLET, walletModel);

src/test/librust/sapling_rpc_wallet_tests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
#include <univalue.h>
2727

28+
extern CWallet* pwalletMain;
29+
2830
extern UniValue CallRPC(std::string args); // Implemented in rpc_tests.cpp
2931

3032
namespace {

src/test/librust/sapling_wallet_tests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
#include <boost/test/unit_test.hpp>
2727

28+
extern CWallet* pwalletMain;
29+
2830
void setupWallet(CWallet& wallet)
2931
{
3032
wallet.SetMinVersion(FEATURE_SAPLING);

src/test/librust/wallet_zkeys_tests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include "util/system.h"
1313
#include <boost/test/unit_test.hpp>
1414

15+
extern CWallet* pwalletMain;
16+
1517
/**
1618
* This test covers methods on CWallet
1719
* GenerateNewZKey()

src/test/miner_tests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#include <boost/test/unit_test.hpp>
1919

20+
extern CWallet* pwalletMain;
21+
2022
// future: this should be MAINNET.
2123
BOOST_FIXTURE_TEST_SUITE(miner_tests, WalletRegTestingSetup)
2224

src/test/script_P2CS_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ BOOST_AUTO_TEST_CASE(fake_script_test)
307307
{
308308
BOOST_ASSERT(!g_IsV6Active);
309309

310-
CWallet& wallet = *pwalletMain;
310+
CWallet& wallet = *vpwallets[0];
311311
LOCK(wallet.cs_wallet);
312312
setupWallet(wallet);
313313
CKey stakerKey; // dummy staker key (not in the wallet)

0 commit comments

Comments
 (0)