Skip to content

Commit 48ba56c

Browse files
committed
Delimit code with #ifdef ENABLE_WALLET
Delimit all code that uses the wallet functions in implementation files that conditionally use the wallet.
1 parent 991685d commit 48ba56c

File tree

6 files changed

+101
-24
lines changed

6 files changed

+101
-24
lines changed

src/init.cpp

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@
1010
#include "init.h"
1111

1212
#include "addrman.h"
13+
#include "db.h"
1314
#include "rpcserver.h"
1415
#include "checkpoints.h"
1516
#include "miner.h"
1617
#include "net.h"
1718
#include "txdb.h"
1819
#include "ui_interface.h"
1920
#include "util.h"
21+
#ifdef ENABLE_WALLET
2022
#include "wallet.h"
2123
#include "walletdb.h"
24+
#endif
2225

2326
#include <inttypes.h>
2427
#include <stdint.h>
@@ -35,8 +38,10 @@
3538
using namespace std;
3639
using namespace boost;
3740

41+
#ifdef ENABLE_WALLET
3842
std::string strWalletFile;
3943
CWallet* pwalletMain;
44+
#endif
4045

4146
#ifdef WIN32
4247
// Win32 LevelDB doesn't use filedescriptors, and the ones used for
@@ -108,15 +113,19 @@ void Shutdown()
108113
RenameThread("bitcoin-shutoff");
109114
mempool.AddTransactionsUpdated(1);
110115
StopRPCThreads();
116+
#ifdef ENABLE_WALLET
111117
ShutdownRPCMining();
112118
if (pwalletMain)
113119
bitdb.Flush(false);
114120
GenerateBitcoins(false, NULL, 0);
121+
#endif
115122
StopNode();
116123
{
117124
LOCK(cs_main);
125+
#ifdef ENABLE_WALLET
118126
if (pwalletMain)
119127
pwalletMain->SetBestChain(chainActive.GetLocator());
128+
#endif
120129
if (pblocktree)
121130
pblocktree->Flush();
122131
if (pcoinsTip)
@@ -125,12 +134,16 @@ void Shutdown()
125134
delete pcoinsdbview; pcoinsdbview = NULL;
126135
delete pblocktree; pblocktree = NULL;
127136
}
137+
#ifdef ENABLE_WALLET
128138
if (pwalletMain)
129139
bitdb.Flush(true);
140+
#endif
130141
boost::filesystem::remove(GetPidFile());
131142
UnregisterAllWallets();
143+
#ifdef ENABLE_WALLET
132144
if (pwalletMain)
133145
delete pwalletMain;
146+
#endif
134147
LogPrintf("Shutdown : done\n");
135148
}
136149

@@ -479,7 +492,9 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer)
479492
fPrintToConsole = GetBoolArg("-printtoconsole", false);
480493
fPrintToDebugger = GetBoolArg("-printtodebugger", false);
481494
fLogTimestamps = GetBoolArg("-logtimestamps", true);
495+
#ifdef ENABLE_WALLET
482496
bool fDisableWallet = GetBoolArg("-disablewallet", false);
497+
#endif
483498

484499
if (mapArgs.count("-timeout"))
485500
{
@@ -525,16 +540,17 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer)
525540
InitWarning(_("Warning: -paytxfee is set very high! This is the transaction fee you will pay if you send a transaction."));
526541
}
527542

543+
#ifdef ENABLE_WALLET
528544
strWalletFile = GetArg("-wallet", "wallet.dat");
529-
545+
#endif
530546
// ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log
531547

532548
std::string strDataDir = GetDataDir().string();
533-
549+
#ifdef ENABLE_WALLET
534550
// Wallet file must be a plain filename without a directory
535551
if (strWalletFile != boost::filesystem::basename(strWalletFile) + boost::filesystem::extension(strWalletFile))
536552
return InitError(strprintf(_("Wallet %s resides outside data directory %s"), strWalletFile.c_str(), strDataDir.c_str()));
537-
553+
#endif
538554
// Make sure only a single Bitcoin process is using the data directory.
539555
boost::filesystem::path pathLockFile = GetDataDir() / ".lock";
540556
FILE* file = fopen(pathLockFile.string().c_str(), "a"); // empty lock file; created if it doesn't exist.
@@ -567,7 +583,7 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer)
567583
int64_t nStart;
568584

569585
// ********************************************************* Step 5: verify wallet database integrity
570-
586+
#ifdef ENABLE_WALLET
571587
if (!fDisableWallet) {
572588
uiInterface.InitMessage(_("Verifying wallet..."));
573589

@@ -613,7 +629,7 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer)
613629
return InitError(_("wallet.dat corrupt, salvage failed"));
614630
}
615631
} // (!fDisableWallet)
616-
632+
#endif // ENABLE_WALLET
617633
// ********************************************************* Step 6: network initialization
618634

619635
RegisterNodeSignals(GetNodeSignals());
@@ -880,7 +896,7 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer)
880896
}
881897

882898
// ********************************************************* Step 8: load wallet
883-
899+
#ifdef ENABLE_WALLET
884900
if (fDisableWallet) {
885901
pwalletMain = NULL;
886902
LogPrintf("Wallet disabled!\n");
@@ -972,7 +988,9 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer)
972988
nWalletDBUpdated++;
973989
}
974990
} // (!fDisableWallet)
975-
991+
#else // ENABLE_WALLET
992+
LogPrintf("No wallet compiled in!\n");
993+
#endif // !ENABLE_WALLET
976994
// ********************************************************* Step 9: import blocks
977995

978996
// scan for better chains in the block chain database, that are not yet connected in the active best chain
@@ -1016,32 +1034,39 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer)
10161034
//// debug print
10171035
LogPrintf("mapBlockIndex.size() = %"PRIszu"\n", mapBlockIndex.size());
10181036
LogPrintf("nBestHeight = %d\n", chainActive.Height());
1037+
#ifdef ENABLE_WALLET
10191038
LogPrintf("setKeyPool.size() = %"PRIszu"\n", pwalletMain ? pwalletMain->setKeyPool.size() : 0);
10201039
LogPrintf("mapWallet.size() = %"PRIszu"\n", pwalletMain ? pwalletMain->mapWallet.size() : 0);
10211040
LogPrintf("mapAddressBook.size() = %"PRIszu"\n", pwalletMain ? pwalletMain->mapAddressBook.size() : 0);
1041+
#endif
10221042

10231043
StartNode(threadGroup);
1024-
1044+
#ifdef ENABLE_WALLET
10251045
// InitRPCMining is needed here so getwork/getblocktemplate in the GUI debug console works properly.
10261046
InitRPCMining();
1047+
#endif
10271048
if (fServer)
10281049
StartRPCThreads();
10291050

1051+
#ifdef ENABLE_WALLET
10301052
// Generate coins in the background
10311053
if (pwalletMain)
10321054
GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain, GetArg("-genproclimit", -1));
1055+
#endif
10331056

10341057
// ********************************************************* Step 12: finished
10351058

10361059
uiInterface.InitMessage(_("Done loading"));
10371060

1061+
#ifdef ENABLE_WALLET
10381062
if (pwalletMain) {
10391063
// Add wallet transactions that aren't already in a block to mapTransactions
10401064
pwalletMain->ReacceptWalletTransactions();
10411065

10421066
// Run a thread to flush wallet periodically
10431067
threadGroup.create_thread(boost::bind(&ThreadFlushWalletDB, boost::ref(pwalletMain->strWalletFile)));
10441068
}
1069+
#endif
10451070

10461071
return !fRequestShutdown;
10471072
}

src/rpcnet.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
// Copyright (c) 2009-2013 The Bitcoin developers
22
// Distributed under the MIT/X11 software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4-
54
#include "rpcserver.h"
65
#include "net.h"
76
#include "netbase.h"
87
#include "protocol.h"
98
#include "sync.h"
109
#include "util.h"
10+
#ifdef ENABLE_WALLET
1111
#include "wallet.h" // for getinfo
1212
#include "init.h" // for getinfo
13+
#endif
1314
#include "main.h" // for getinfo
1415

1516
#include <inttypes.h>
@@ -368,23 +369,29 @@ Value getinfo(const Array& params, bool fHelp)
368369
Object obj;
369370
obj.push_back(Pair("version", (int)CLIENT_VERSION));
370371
obj.push_back(Pair("protocolversion",(int)PROTOCOL_VERSION));
372+
#ifdef ENABLE_WALLET
371373
if (pwalletMain) {
372374
obj.push_back(Pair("walletversion", pwalletMain->GetVersion()));
373375
obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance())));
374376
}
377+
#endif
375378
obj.push_back(Pair("blocks", (int)chainActive.Height()));
376379
obj.push_back(Pair("timeoffset", (boost::int64_t)GetTimeOffset()));
377380
obj.push_back(Pair("connections", (int)vNodes.size()));
378381
obj.push_back(Pair("proxy", (proxy.first.IsValid() ? proxy.first.ToStringIPPort() : string())));
379382
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
380383
obj.push_back(Pair("testnet", TestNet()));
384+
#ifdef ENABLE_WALLET
381385
if (pwalletMain) {
382386
obj.push_back(Pair("keypoololdest", (boost::int64_t)pwalletMain->GetOldestKeyPoolTime()));
383387
obj.push_back(Pair("keypoolsize", (int)pwalletMain->GetKeyPoolSize()));
384388
}
389+
#endif
385390
obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee)));
391+
#ifdef ENABLE_WALLET
386392
if (pwalletMain && pwalletMain->IsCrypted())
387393
obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime));
394+
#endif
388395
obj.push_back(Pair("errors", GetWarnings("statusbar")));
389396
return obj;
390397
}

src/rpcrawtransaction.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
#include "init.h"
99
#include "net.h"
1010
#include "uint256.h"
11+
#include "core.h"
12+
#include "main.h"
13+
#include "keystore.h"
14+
#ifdef ENABLE_WALLET
1115
#include "wallet.h"
16+
#endif
1217

1318
#include <stdint.h>
1419

@@ -190,6 +195,7 @@ Value getrawtransaction(const Array& params, bool fHelp)
190195
return result;
191196
}
192197

198+
#ifdef ENABLE_WALLET
193199
Value listunspent(const Array& params, bool fHelp)
194200
{
195201
if (fHelp || params.size() > 3)
@@ -303,6 +309,7 @@ Value listunspent(const Array& params, bool fHelp)
303309

304310
return results;
305311
}
312+
#endif
306313

307314
Value createrawtransaction(const Array& params, bool fHelp)
308315
{
@@ -508,7 +515,9 @@ Value signrawtransaction(const Array& params, bool fHelp)
508515
"this transaction depends on but may not yet be in the block chain.\n"
509516
"The third optional argument (may be null) is an array of base58-encoded private\n"
510517
"keys that, if given, will be the only keys used to sign the transaction.\n"
518+
#ifdef ENABLE_WALLET
511519
+ HelpRequiringPassphrase() + "\n"
520+
#endif
512521

513522
"\nArguments:\n"
514523
"1. \"hexstring\" (string, required) The transaction hex string\n"
@@ -605,8 +614,10 @@ Value signrawtransaction(const Array& params, bool fHelp)
605614
tempKeystore.AddKey(key);
606615
}
607616
}
617+
#ifdef ENABLE_WALLET
608618
else
609619
EnsureWalletIsUnlocked();
620+
#endif
610621

611622
// Add previous txouts given in the RPC call:
612623
if (params.size() > 1 && params[1].type() != null_type)
@@ -662,7 +673,11 @@ Value signrawtransaction(const Array& params, bool fHelp)
662673
}
663674
}
664675

676+
#ifdef ENABLE_WALLET
665677
const CKeyStore& keystore = ((fGivenKeys || !pwalletMain) ? tempKeystore : *pwalletMain);
678+
#else
679+
const CKeyStore& keystore = tempKeystore;
680+
#endif
666681

667682
int nHashType = SIGHASH_ALL;
668683
if (params.size() > 3 && params[3].type() != null_type)

0 commit comments

Comments
 (0)