Skip to content

Commit 096a0f9

Browse files
committed
Merge #2337: [Wallet] Basic multiwallet support
4734a84 [Cleanup][Tests] Fix chainparams-change in librust tests (random-zebra) ff4cee0 [Trivial] Add wallet filename to backup errors/warning (random-zebra) dc596f3 [Doc] Add multiwallet section to release notes (random-zebra) 36796f2 [Cleanup] Fix formatting in wallet and walletdb (random-zebra) b6dbbf3 wallet: Forbid -salvagewallet, -zapwallettxes, and -upgradewallet with multiple wallets (random-zebra) 60f9b4b wallet: Base backup filenames on original wallet filename (Luke Dashjr) e6efa6b wallet: Include actual backup filename in recovery warning message (Luke Dashjr) 647fbc9 Wallet: Move multiwallet sanity checks to CWallet::Verify, and do other checks on all wallets (Luke Dashjr) b27dcfe Wallet: Support loading multiple wallets if -wallet used more than once (Luke Dashjr) d10acd5 [Tests] move pwalletMain to wallet test fixture + use smart pointer (random-zebra) d6cf608 [Refactor] Remove CWalletDBWrapper::GetUpdateCounter() (random-zebra) 4bbad5c [Wallet] Replace pwalletMain with a vector of wallet pointers (random-zebra) 100d67c Wallet: Sanitise -wallet parameter (Luke Dashjr) 3bfa7d8 Wallet/RPC: Use filename rather than CWallet pointer, for lockwallet RPCRunLater job name (Luke Dashjr) ca6a62d [MOVE-ONLY] Move wallet RPC declarations to rpcwallet.h (random-zebra) 687c2fd RPC: Pass on JSONRPCRequest metadata (URI/user/etc) for "help" method (Luke Dashjr) cc965fe Move nWalletUnlockTime to CWallet::nRelockTime, and name timed task unique per CWallet (Luke Dashjr) 22f8507 [Trivial] Rename pwalletMain --> pwallet for local variables in RPC (random-zebra) 325baaa RPC: Do all wallet access through new GetWalletForJSONRPCRequest (random-zebra) 0e21e09 [Cleanup] Remove un-used printAddresses() function in rpcwallet (random-zebra) a8dd236 RPC/Wallet: Pass CWallet as pointer to helper functions (random-zebra) fb64bbc [Doc] Remove ThreadFlushWalletDB from developer notes (random-zebra) dc2e022 [Refactor] fix WalletTestingSetup fixture (random-zebra) f9d7fe1 refactor: move bdb (bitdb) interaction from init.cpp to wallet.cpp (random-zebra) 9cfb711 CWalletDB: Store the update counter per wallet (Luke Dashjr) 8edb74f Bug: increment counter when writing minversion (random-zebra) 8aa93b9 Bugfix: wallet: Increment "update counter" only after actually making the applicable db changes to avoid potential races (Luke Dashjr) Pull request description: Quite a bit of refactoring to bring us a little closer to upstream in the wallet/walletdb area, introducing basic support for multiple wallets. The PIVX client can now be started with more than one `-wallet` argument (either as startup flags, or as multiple lines in pivx.conf). The wallets will be all loaded and kept separated, with individual balances, keys and received transactions. Even though only the first wallet will be used in the GUI/RPC for the moment (selectable wallets will be added later), all other loaded wallets will remain synchronized to the node's current tip and update their internal data. Bulk of changes coming from: - bitcoin#8775 RPC refactoring: Access wallet using new GetWalletForJSONRPCRequest - bitcoin#8694 Basic multiwallet support - bitcoin#11713 Fix for mismatched extern definition in wallet tests - bitcoin#11781 tests: move pwalletMain to wallet test fixture ACKs for top commit: furszy: Code ACK 4734a84 after rebase and inclusion of 4734a84. Tree-SHA512: 483fc34310c86070ffde08487605b25da957e55fbc8ef1b9cc1f682c6af0789619bb40839e915618d603097a1bdcf6b2110c7fabf017f8351b3a426976ca77a9
2 parents db5e692 + 4734a84 commit 096a0f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1623
-1213
lines changed

doc/developer-notes.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,6 @@ Threads
301301

302302
- DumpAddresses : Dumps IP addresses of nodes to peers.dat.
303303

304-
- ThreadFlushWalletDB : Close the wallet.dat file if it hasn't been used in 500ms.
305-
306304
- ThreadRPCServer : Remote procedure call handler, listens on port 8332 for connections and services them.
307305

308306
- BitcoinMiner : Generates PIVs (if wallet is enabled).

doc/release-notes.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,26 @@ Cold-Staking Re-Activation
4949
PIVX Core v6.0.0 includes a fix for the vulnerability identified within the cold-staking protocol (see PR [#2258](https://github.com/PIVX-Project/PIVX/pull/2258)).
5050
Therefore the feature will be re-enabled on the network, via `SPORK_19`, shortly after the upgrade enforcement.
5151

52-
#### Protocol changes
52+
### Protocol changes
5353

5454
A new opcode (`0xd2`) is introduced (see PR [#2275](https://github.com/PIVX-Project/PIVX/pull/2275)). It enforces the same rules as the legacy cold-staking opcode, but without allowing a "free" script for the last output of the transaction.
5555
This is in accord with the consensus change introduced with the "Deterministic Masternodes" update, as masternode/budget payments are now outputs of the *coinbase* transaction (rather than the *coinstake*), therefore a "free" output for the coinstake is no longer needed.
5656
The new opcode takes the name of `OP_CHECKCOLDSTAKEVERIFY`, and the legacy opcode (`0xd1`) is renamed to `OP_CHECKCOLDSTAKEVERIFY_LOF` (last-output-free).
5757
Scripts with the old opcode are still accepted on the network (the restriction on the last-output is enforced after the script validation in this case), but the client creates new delegations with the new opcode, by default, after the upgrade enforcement.
5858

5959

60+
Multi-wallet support
61+
--------------------
62+
63+
PIVX Core now supports loading multiple, separate wallets (See [PR 2337](https://github.com/PIVX-Project/PIVX/pull/2337)). The wallets are completely separated, with individual balances, keys and received transactions.
64+
65+
Multi-wallet is enabled by using more than one `-wallet` argument when starting PIVX client, either on the command line or in the pivx.conf config file.
66+
67+
**In pivx-qt, only the first wallet will be displayed and accessible for creating and signing transactions.** GUI selectable multiple wallets will be supported in a future version. However, even in 6.0 other loaded wallets will remain synchronized to the node's current tip in the background.
68+
69+
!TODO: update after endpoint support and multi-wallet RPC support
70+
71+
6072
GUI changes
6173
-----------
6274

@@ -101,6 +113,7 @@ Low-level RPC changes
101113
- `maximumCount` - a number specifying the minimum number of UTXOs
102114
- `minimumSumAmount` - a number specifying the minimum sum value of all UTXOs
103115

116+
104117
#### Show wallet's auto-combine settings in getwalletinfo
105118

106119
`getwalletinfo` now has two additional return fields. `autocombine_enabled` (boolean) and `autocombine_threshold` (numeric) that will show the auto-combine threshold and whether or not it is currently enabled.

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: 35 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Copyright (c) 2009-2010 Satoshi Nakamoto
2-
// Copyright (c) 2009-2015 The Bitcoin developers
2+
// Copyright (c) 2009-2021 The Bitcoin developers
33
// Copyright (c) 2014-2015 The Dash developers
44
// Copyright (c) 2011-2013 The PPCoin developers
55
// Copyright (c) 2013-2014 The NovaCoin Developers
66
// Copyright (c) 2014-2018 The BlackCoin Developers
7-
// Copyright (c) 2015-2020 The PIVX developers
7+
// Copyright (c) 2015-2021 The PIVX developers
88
// Distributed under the MIT software license, see the accompanying
99
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
1010

@@ -58,7 +58,6 @@
5858
#include "zpivchain.h"
5959

6060
#ifdef ENABLE_WALLET
61-
#include "wallet/db.h"
6261
#include "wallet/wallet.h"
6362
#include "wallet/rpcwallet.h"
6463

@@ -222,8 +221,9 @@ void PrepareShutdown()
222221
StopRPC();
223222
StopHTTPServer();
224223
#ifdef ENABLE_WALLET
225-
if (pwalletMain)
226-
bitdb.Flush(false);
224+
for (CWalletRef pwallet : vpwallets) {
225+
pwallet->Flush(false);
226+
}
227227
GenerateBitcoins(false, NULL, 0);
228228
#endif
229229
StopMapPort();
@@ -302,8 +302,9 @@ void PrepareShutdown()
302302
evoDb.reset();
303303
}
304304
#ifdef ENABLE_WALLET
305-
if (pwalletMain)
306-
bitdb.Flush(true);
305+
for (CWalletRef pwallet : vpwallets) {
306+
pwallet->Flush(true);
307+
}
307308
#endif
308309

309310
if (pEvoNotificationInterface) {
@@ -355,8 +356,10 @@ void Shutdown()
355356
PrepareShutdown();
356357
}
357358
#ifdef ENABLE_WALLET
358-
delete pwalletMain;
359-
pwalletMain = NULL;
359+
for (CWalletRef pwallet : vpwallets) {
360+
delete pwallet;
361+
}
362+
vpwallets.clear();
360363
#endif
361364
globalVerifyHandle.reset();
362365
ECC_Stop();
@@ -933,24 +936,6 @@ void InitParameterInteraction()
933936
if (gArgs.SoftSetBoolArg("-discover", false))
934937
LogPrintf("%s : parameter interaction: -externalip set -> setting -discover=0\n", __func__);
935938
}
936-
937-
if (gArgs.GetBoolArg("-salvagewallet", false)) {
938-
// Rewrite just private keys: rescan to find transactions
939-
if (gArgs.SoftSetBoolArg("-rescan", true))
940-
LogPrintf("%s : parameter interaction: -salvagewallet=1 -> setting -rescan=1\n", __func__);
941-
}
942-
943-
int zapwallettxes = gArgs.GetArg("-zapwallettxes", 0);
944-
// -zapwallettxes implies dropping the mempool on startup
945-
if (zapwallettxes != 0 && gArgs.SoftSetBoolArg("-persistmempool", false)) {
946-
LogPrintf("%s: parameter interaction: -zapwallettxes=%s -> setting -persistmempool=0\n", __func__, zapwallettxes);
947-
}
948-
949-
// -zapwallettxes implies a rescan
950-
if (zapwallettxes != 0) {
951-
if (gArgs.SoftSetBoolArg("-rescan", true))
952-
LogPrintf("%s : parameter interaction: -zapwallettxes=%s -> setting -rescan=1\n", __func__, zapwallettxes);
953-
}
954939
}
955940

956941
bool InitNUParams()
@@ -1334,11 +1319,8 @@ bool AppInitMain()
13341319
}
13351320
}
13361321

1337-
// ********************************************************* Step 5: Backup wallet and verify wallet database integrity
1322+
// ********************************************************* Step 5: Verify wallet database integrity
13381323
#ifdef ENABLE_WALLET
1339-
if (!InitAutoBackupWallet()) {
1340-
return false;
1341-
}
13421324
if (!CWallet::Verify()) {
13431325
return false;
13441326
}
@@ -1726,7 +1708,7 @@ bool AppInitMain()
17261708
mempool.ReadFeeEstimates(est_filein);
17271709
fFeeEstimatesInitialized = true;
17281710

1729-
// ********************************************************* Step 8: load wallet
1711+
// ********************************************************* Step 8: Backup and Load wallet
17301712
#ifdef ENABLE_WALLET
17311713
if (!CWallet::InitLoadWallet())
17321714
return false;
@@ -1878,14 +1860,15 @@ bool AppInitMain()
18781860
strBudgetMode = gArgs.GetArg("-budgetvotemode", "auto");
18791861

18801862
#ifdef ENABLE_WALLET
1881-
if (gArgs.GetBoolArg("-mnconflock", DEFAULT_MNCONFLOCK) && pwalletMain) {
1882-
LOCK(pwalletMain->cs_wallet);
1863+
// use only the first wallet here. This section can be removed after transition to DMN
1864+
if (gArgs.GetBoolArg("-mnconflock", DEFAULT_MNCONFLOCK) && !vpwallets.empty() && vpwallets[0]) {
1865+
LOCK(vpwallets[0]->cs_wallet);
18831866
LogPrintf("Locking Masternodes collateral utxo:\n");
18841867
uint256 mnTxHash;
18851868
for (const auto& mne : masternodeConfig.getEntries()) {
18861869
mnTxHash.SetHex(mne.getTxHash());
18871870
COutPoint outpoint = COutPoint(mnTxHash, (unsigned int) std::stoul(mne.getOutputIndex()));
1888-
pwalletMain->LockCoin(outpoint);
1871+
vpwallets[0]->LockCoin(outpoint);
18891872
LogPrintf("Locked collateral, MN: %s, tx hash: %s, output index: %s\n",
18901873
mne.getAlias(), mne.getTxHash(), mne.getOutputIndex());
18911874
}
@@ -1919,11 +1902,13 @@ bool AppInitMain()
19191902

19201903
#ifdef ENABLE_WALLET
19211904
{
1922-
if (pwalletMain) {
1923-
LOCK(pwalletMain->cs_wallet);
1924-
LogPrintf("setKeyPool.size() = %u\n", pwalletMain ? pwalletMain->GetKeyPoolSize() : 0);
1925-
LogPrintf("mapWallet.size() = %u\n", pwalletMain ? pwalletMain->mapWallet.size() : 0);
1926-
LogPrintf("mapAddressBook.size() = %u\n", pwalletMain ? pwalletMain->GetAddressBookSize() : 0);
1905+
int idx = 0;
1906+
for (CWalletRef pwallet : vpwallets) {
1907+
LogPrintf("Wallet %d\n", idx++);
1908+
LOCK(pwallet->cs_wallet);
1909+
LogPrintf("setKeyPool.size() = %u\n", pwallet->GetKeyPoolSize());
1910+
LogPrintf("mapWallet.size() = %u\n", pwallet->mapWallet.size());
1911+
LogPrintf("mapAddressBook.size() = %u\n", pwallet->GetAddressBookSize());
19271912
}
19281913
}
19291914
#endif
@@ -1954,22 +1939,21 @@ bool AppInitMain()
19541939
return UIError(strNodeError);
19551940

19561941
#ifdef ENABLE_WALLET
1957-
// Generate coins in the background
1958-
if (pwalletMain)
1959-
GenerateBitcoins(gArgs.GetBoolArg("-gen", DEFAULT_GENERATE), pwalletMain, gArgs.GetArg("-genproclimit", DEFAULT_GENERATE_PROCLIMIT));
1942+
// Generate coins in the background (disabled on mainnet. use only wallet 0)
1943+
if (!vpwallets.empty())
1944+
GenerateBitcoins(gArgs.GetBoolArg("-gen", DEFAULT_GENERATE), vpwallets[0], gArgs.GetArg("-genproclimit", DEFAULT_GENERATE_PROCLIMIT));
19601945
#endif
19611946

19621947
// ********************************************************* Step 12: finished
19631948

19641949
#ifdef ENABLE_WALLET
1965-
if (pwalletMain) {
1966-
uiInterface.InitMessage(_("Reaccepting wallet transactions..."));
1967-
pwalletMain->postInitProcess(scheduler);
1968-
1969-
// StakeMiner thread disabled by default on regtest
1970-
if (gArgs.GetBoolArg("-staking", !Params().IsRegTestNet() && DEFAULT_STAKING)) {
1971-
threadGroup.create_thread(std::bind(&ThreadStakeMinter));
1972-
}
1950+
uiInterface.InitMessage(_("Reaccepting wallet transactions..."));
1951+
for (CWalletRef pwallet : vpwallets) {
1952+
pwallet->postInitProcess(scheduler);
1953+
}
1954+
// StakeMiner thread disabled by default on regtest
1955+
if (!vpwallets.empty() && gArgs.GetBoolArg("-staking", !Params().IsRegTestNet() && DEFAULT_STAKING)) {
1956+
threadGroup.create_thread(std::bind(&ThreadStakeMinter));
19731957
}
19741958
#endif
19751959

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/rest.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "utilstrencodings.h"
1717
#include "validation.h"
1818
#include "version.h"
19+
#include "wallet/wallet.h"
1920

2021
#include <boost/algorithm/string.hpp>
2122

@@ -60,7 +61,7 @@ struct CCoin {
6061
}
6162
};
6263

63-
extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry);
64+
extern void TxToJSON(CWallet* const pwallet, const CTransaction& tx, const uint256 hashBlock, UniValue& entry);
6465
extern UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false);
6566
extern UniValue mempoolInfoToJSON();
6667
extern UniValue mempoolToJSON(bool fVerbose = false);
@@ -373,7 +374,7 @@ static bool rest_tx(HTTPRequest* req, const std::string& strURIPart)
373374

374375
case RF_JSON: {
375376
UniValue objTx(UniValue::VOBJ);
376-
TxToJSON(*tx, hashBlock, objTx);
377+
TxToJSON(nullptr, *tx, hashBlock, objTx);
377378
std::string strJSON = objTx.write() + "\n";
378379
req->WriteHeader("Content-Type", "application/json");
379380
req->WriteReply(HTTP_OK, strJSON);

src/rpc/blockchain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static std::mutex cs_blockchange;
4242
static std::condition_variable cond_blockchange;
4343
static CUpdatedBlock latestblock;
4444

45-
extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry);
45+
extern void TxToJSON(CWallet* const pwallet, const CTransaction& tx, const uint256 hashBlock, UniValue& entry);
4646

4747
UniValue syncwithvalidationinterfacequeue(const JSONRPCRequest& request)
4848
{
@@ -147,7 +147,7 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx
147147
const CTransaction& tx = *txIn;
148148
if (txDetails) {
149149
UniValue objTx(UniValue::VOBJ);
150-
TxToJSON(tx, UINT256_ZERO, objTx);
150+
TxToJSON(nullptr, tx, UINT256_ZERO, objTx);
151151
txs.push_back(objTx);
152152
} else
153153
txs.push_back(tx.GetHash().GetHex());

src/rpc/budget.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#include "messagesigner.h"
1616
#include "rpc/server.h"
1717
#include "utilmoneystr.h"
18+
#ifdef ENABLE_WALLET
19+
#include "wallet/rpcwallet.h"
20+
#endif
1821

1922
#include <univalue.h>
2023

@@ -97,6 +100,11 @@ void checkBudgetInputs(const UniValue& params, std::string &strProposalName, std
97100

98101
UniValue preparebudget(const JSONRPCRequest& request)
99102
{
103+
CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
104+
105+
if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
106+
return NullUniValue;
107+
100108
if (request.fHelp || request.params.size() != 6)
101109
throw std::runtime_error(
102110
"preparebudget \"proposal-name\" \"url\" payment-count block-start \"pivx-address\" monthy-payment\n"
@@ -117,13 +125,9 @@ UniValue preparebudget(const JSONRPCRequest& request)
117125
HelpExampleCli("preparebudget", "\"test-proposal\" \"https://forum.pivx.org/t/test-proposal\" 2 820800 \"D9oc6C3dttUbv8zd7zGNq1qKBGf4ZQ1XEE\" 500") +
118126
HelpExampleRpc("preparebudget", "\"test-proposal\" \"https://forum.pivx.org/t/test-proposal\" 2 820800 \"D9oc6C3dttUbv8zd7zGNq1qKBGf4ZQ1XEE\" 500"));
119127

120-
if (!pwalletMain) {
121-
throw JSONRPCError(RPC_IN_WARMUP, "Try again after active chain is loaded");
122-
}
123-
124-
LOCK2(cs_main, pwalletMain->cs_wallet);
128+
LOCK2(cs_main, pwallet->cs_wallet);
125129

126-
EnsureWalletIsUnlocked();
130+
EnsureWalletIsUnlocked(pwallet);
127131

128132
std::string strProposalName;
129133
std::string strURL;
@@ -145,19 +149,19 @@ UniValue preparebudget(const JSONRPCRequest& request)
145149

146150
CTransactionRef wtx;
147151
// make our change address
148-
CReserveKey keyChange(pwalletMain);
149-
if (!pwalletMain->CreateBudgetFeeTX(wtx, nHash, keyChange, false)) { // 50 PIV collateral for proposal
152+
CReserveKey keyChange(pwallet);
153+
if (!pwallet->CreateBudgetFeeTX(wtx, nHash, keyChange, false)) { // 50 PIV collateral for proposal
150154
throw std::runtime_error("Error making collateral transaction for proposal. Please check your wallet balance.");
151155
}
152156

153157
//send the tx to the network
154-
const CWallet::CommitResult& res = pwalletMain->CommitTransaction(wtx, keyChange, g_connman.get());
158+
const CWallet::CommitResult& res = pwallet->CommitTransaction(wtx, keyChange, g_connman.get());
155159
if (res.status != CWallet::CommitStatus::OK)
156160
throw JSONRPCError(RPC_WALLET_ERROR, res.ToString());
157161

158162
// Store proposal name as a comment
159-
assert(pwalletMain->mapWallet.count(wtx->GetHash()));
160-
pwalletMain->mapWallet.at(wtx->GetHash()).SetComment("Proposal: " + strProposalName);
163+
assert(pwallet->mapWallet.count(wtx->GetHash()));
164+
pwallet->mapWallet.at(wtx->GetHash()).SetComment("Proposal: " + strProposalName);
161165

162166
return wtx->GetHash().ToString();
163167
}

0 commit comments

Comments
 (0)