Browse Source

Delimit code with #ifdef ENABLE_WALLET

Delimit all code that uses the wallet functions
in implementation files that conditionally use the wallet.
0.10
Wladimir J. van der Laan 11 years ago
parent
commit
48ba56cdfd
  1. 41
      src/init.cpp
  2. 9
      src/rpcnet.cpp
  3. 15
      src/rpcrawtransaction.cpp
  4. 45
      src/rpcserver.cpp
  5. 5
      src/test/rpc_tests.cpp
  6. 10
      src/test/test_bitcoin.cpp

41
src/init.cpp

@ -10,6 +10,7 @@
#include "init.h" #include "init.h"
#include "addrman.h" #include "addrman.h"
#include "db.h"
#include "rpcserver.h" #include "rpcserver.h"
#include "checkpoints.h" #include "checkpoints.h"
#include "miner.h" #include "miner.h"
@ -17,8 +18,10 @@
#include "txdb.h" #include "txdb.h"
#include "ui_interface.h" #include "ui_interface.h"
#include "util.h" #include "util.h"
#ifdef ENABLE_WALLET
#include "wallet.h" #include "wallet.h"
#include "walletdb.h" #include "walletdb.h"
#endif
#include <inttypes.h> #include <inttypes.h>
#include <stdint.h> #include <stdint.h>
@ -35,8 +38,10 @@
using namespace std; using namespace std;
using namespace boost; using namespace boost;
#ifdef ENABLE_WALLET
std::string strWalletFile; std::string strWalletFile;
CWallet* pwalletMain; CWallet* pwalletMain;
#endif
#ifdef WIN32 #ifdef WIN32
// Win32 LevelDB doesn't use filedescriptors, and the ones used for // Win32 LevelDB doesn't use filedescriptors, and the ones used for
@ -108,15 +113,19 @@ void Shutdown()
RenameThread("bitcoin-shutoff"); RenameThread("bitcoin-shutoff");
mempool.AddTransactionsUpdated(1); mempool.AddTransactionsUpdated(1);
StopRPCThreads(); StopRPCThreads();
#ifdef ENABLE_WALLET
ShutdownRPCMining(); ShutdownRPCMining();
if (pwalletMain) if (pwalletMain)
bitdb.Flush(false); bitdb.Flush(false);
GenerateBitcoins(false, NULL, 0); GenerateBitcoins(false, NULL, 0);
#endif
StopNode(); StopNode();
{ {
LOCK(cs_main); LOCK(cs_main);
#ifdef ENABLE_WALLET
if (pwalletMain) if (pwalletMain)
pwalletMain->SetBestChain(chainActive.GetLocator()); pwalletMain->SetBestChain(chainActive.GetLocator());
#endif
if (pblocktree) if (pblocktree)
pblocktree->Flush(); pblocktree->Flush();
if (pcoinsTip) if (pcoinsTip)
@ -125,12 +134,16 @@ void Shutdown()
delete pcoinsdbview; pcoinsdbview = NULL; delete pcoinsdbview; pcoinsdbview = NULL;
delete pblocktree; pblocktree = NULL; delete pblocktree; pblocktree = NULL;
} }
#ifdef ENABLE_WALLET
if (pwalletMain) if (pwalletMain)
bitdb.Flush(true); bitdb.Flush(true);
#endif
boost::filesystem::remove(GetPidFile()); boost::filesystem::remove(GetPidFile());
UnregisterAllWallets(); UnregisterAllWallets();
#ifdef ENABLE_WALLET
if (pwalletMain) if (pwalletMain)
delete pwalletMain; delete pwalletMain;
#endif
LogPrintf("Shutdown : done\n"); LogPrintf("Shutdown : done\n");
} }
@ -479,7 +492,9 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer)
fPrintToConsole = GetBoolArg("-printtoconsole", false); fPrintToConsole = GetBoolArg("-printtoconsole", false);
fPrintToDebugger = GetBoolArg("-printtodebugger", false); fPrintToDebugger = GetBoolArg("-printtodebugger", false);
fLogTimestamps = GetBoolArg("-logtimestamps", true); fLogTimestamps = GetBoolArg("-logtimestamps", true);
#ifdef ENABLE_WALLET
bool fDisableWallet = GetBoolArg("-disablewallet", false); bool fDisableWallet = GetBoolArg("-disablewallet", false);
#endif
if (mapArgs.count("-timeout")) if (mapArgs.count("-timeout"))
{ {
@ -525,16 +540,17 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer)
InitWarning(_("Warning: -paytxfee is set very high! This is the transaction fee you will pay if you send a transaction.")); InitWarning(_("Warning: -paytxfee is set very high! This is the transaction fee you will pay if you send a transaction."));
} }
#ifdef ENABLE_WALLET
strWalletFile = GetArg("-wallet", "wallet.dat"); strWalletFile = GetArg("-wallet", "wallet.dat");
#endif
// ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log // ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log
std::string strDataDir = GetDataDir().string(); std::string strDataDir = GetDataDir().string();
#ifdef ENABLE_WALLET
// Wallet file must be a plain filename without a directory // Wallet file must be a plain filename without a directory
if (strWalletFile != boost::filesystem::basename(strWalletFile) + boost::filesystem::extension(strWalletFile)) if (strWalletFile != boost::filesystem::basename(strWalletFile) + boost::filesystem::extension(strWalletFile))
return InitError(strprintf(_("Wallet %s resides outside data directory %s"), strWalletFile.c_str(), strDataDir.c_str())); return InitError(strprintf(_("Wallet %s resides outside data directory %s"), strWalletFile.c_str(), strDataDir.c_str()));
#endif
// Make sure only a single Bitcoin process is using the data directory. // Make sure only a single Bitcoin process is using the data directory.
boost::filesystem::path pathLockFile = GetDataDir() / ".lock"; boost::filesystem::path pathLockFile = GetDataDir() / ".lock";
FILE* file = fopen(pathLockFile.string().c_str(), "a"); // empty lock file; created if it doesn't exist. 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)
int64_t nStart; int64_t nStart;
// ********************************************************* Step 5: verify wallet database integrity // ********************************************************* Step 5: verify wallet database integrity
#ifdef ENABLE_WALLET
if (!fDisableWallet) { if (!fDisableWallet) {
uiInterface.InitMessage(_("Verifying wallet...")); uiInterface.InitMessage(_("Verifying wallet..."));
@ -613,7 +629,7 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer)
return InitError(_("wallet.dat corrupt, salvage failed")); return InitError(_("wallet.dat corrupt, salvage failed"));
} }
} // (!fDisableWallet) } // (!fDisableWallet)
#endif // ENABLE_WALLET
// ********************************************************* Step 6: network initialization // ********************************************************* Step 6: network initialization
RegisterNodeSignals(GetNodeSignals()); RegisterNodeSignals(GetNodeSignals());
@ -880,7 +896,7 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer)
} }
// ********************************************************* Step 8: load wallet // ********************************************************* Step 8: load wallet
#ifdef ENABLE_WALLET
if (fDisableWallet) { if (fDisableWallet) {
pwalletMain = NULL; pwalletMain = NULL;
LogPrintf("Wallet disabled!\n"); LogPrintf("Wallet disabled!\n");
@ -972,7 +988,9 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer)
nWalletDBUpdated++; nWalletDBUpdated++;
} }
} // (!fDisableWallet) } // (!fDisableWallet)
#else // ENABLE_WALLET
LogPrintf("No wallet compiled in!\n");
#endif // !ENABLE_WALLET
// ********************************************************* Step 9: import blocks // ********************************************************* Step 9: import blocks
// scan for better chains in the block chain database, that are not yet connected in the active best chain // scan for better chains in the block chain database, that are not yet connected in the active best chain
@ -1016,25 +1034,31 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer)
//// debug print //// debug print
LogPrintf("mapBlockIndex.size() = %"PRIszu"\n", mapBlockIndex.size()); LogPrintf("mapBlockIndex.size() = %"PRIszu"\n", mapBlockIndex.size());
LogPrintf("nBestHeight = %d\n", chainActive.Height()); LogPrintf("nBestHeight = %d\n", chainActive.Height());
#ifdef ENABLE_WALLET
LogPrintf("setKeyPool.size() = %"PRIszu"\n", pwalletMain ? pwalletMain->setKeyPool.size() : 0); LogPrintf("setKeyPool.size() = %"PRIszu"\n", pwalletMain ? pwalletMain->setKeyPool.size() : 0);
LogPrintf("mapWallet.size() = %"PRIszu"\n", pwalletMain ? pwalletMain->mapWallet.size() : 0); LogPrintf("mapWallet.size() = %"PRIszu"\n", pwalletMain ? pwalletMain->mapWallet.size() : 0);
LogPrintf("mapAddressBook.size() = %"PRIszu"\n", pwalletMain ? pwalletMain->mapAddressBook.size() : 0); LogPrintf("mapAddressBook.size() = %"PRIszu"\n", pwalletMain ? pwalletMain->mapAddressBook.size() : 0);
#endif
StartNode(threadGroup); StartNode(threadGroup);
#ifdef ENABLE_WALLET
// InitRPCMining is needed here so getwork/getblocktemplate in the GUI debug console works properly. // InitRPCMining is needed here so getwork/getblocktemplate in the GUI debug console works properly.
InitRPCMining(); InitRPCMining();
#endif
if (fServer) if (fServer)
StartRPCThreads(); StartRPCThreads();
#ifdef ENABLE_WALLET
// Generate coins in the background // Generate coins in the background
if (pwalletMain) if (pwalletMain)
GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain, GetArg("-genproclimit", -1)); GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain, GetArg("-genproclimit", -1));
#endif
// ********************************************************* Step 12: finished // ********************************************************* Step 12: finished
uiInterface.InitMessage(_("Done loading")); uiInterface.InitMessage(_("Done loading"));
#ifdef ENABLE_WALLET
if (pwalletMain) { if (pwalletMain) {
// Add wallet transactions that aren't already in a block to mapTransactions // Add wallet transactions that aren't already in a block to mapTransactions
pwalletMain->ReacceptWalletTransactions(); pwalletMain->ReacceptWalletTransactions();
@ -1042,6 +1066,7 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer)
// Run a thread to flush wallet periodically // Run a thread to flush wallet periodically
threadGroup.create_thread(boost::bind(&ThreadFlushWalletDB, boost::ref(pwalletMain->strWalletFile))); threadGroup.create_thread(boost::bind(&ThreadFlushWalletDB, boost::ref(pwalletMain->strWalletFile)));
} }
#endif
return !fRequestShutdown; return !fRequestShutdown;
} }

9
src/rpcnet.cpp

@ -1,15 +1,16 @@
// Copyright (c) 2009-2013 The Bitcoin developers // Copyright (c) 2009-2013 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "rpcserver.h" #include "rpcserver.h"
#include "net.h" #include "net.h"
#include "netbase.h" #include "netbase.h"
#include "protocol.h" #include "protocol.h"
#include "sync.h" #include "sync.h"
#include "util.h" #include "util.h"
#ifdef ENABLE_WALLET
#include "wallet.h" // for getinfo #include "wallet.h" // for getinfo
#include "init.h" // for getinfo #include "init.h" // for getinfo
#endif
#include "main.h" // for getinfo #include "main.h" // for getinfo
#include <inttypes.h> #include <inttypes.h>
@ -368,23 +369,29 @@ Value getinfo(const Array& params, bool fHelp)
Object obj; Object obj;
obj.push_back(Pair("version", (int)CLIENT_VERSION)); obj.push_back(Pair("version", (int)CLIENT_VERSION));
obj.push_back(Pair("protocolversion",(int)PROTOCOL_VERSION)); obj.push_back(Pair("protocolversion",(int)PROTOCOL_VERSION));
#ifdef ENABLE_WALLET
if (pwalletMain) { if (pwalletMain) {
obj.push_back(Pair("walletversion", pwalletMain->GetVersion())); obj.push_back(Pair("walletversion", pwalletMain->GetVersion()));
obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance()))); obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance())));
} }
#endif
obj.push_back(Pair("blocks", (int)chainActive.Height())); obj.push_back(Pair("blocks", (int)chainActive.Height()));
obj.push_back(Pair("timeoffset", (boost::int64_t)GetTimeOffset())); obj.push_back(Pair("timeoffset", (boost::int64_t)GetTimeOffset()));
obj.push_back(Pair("connections", (int)vNodes.size())); obj.push_back(Pair("connections", (int)vNodes.size()));
obj.push_back(Pair("proxy", (proxy.first.IsValid() ? proxy.first.ToStringIPPort() : string()))); obj.push_back(Pair("proxy", (proxy.first.IsValid() ? proxy.first.ToStringIPPort() : string())));
obj.push_back(Pair("difficulty", (double)GetDifficulty())); obj.push_back(Pair("difficulty", (double)GetDifficulty()));
obj.push_back(Pair("testnet", TestNet())); obj.push_back(Pair("testnet", TestNet()));
#ifdef ENABLE_WALLET
if (pwalletMain) { if (pwalletMain) {
obj.push_back(Pair("keypoololdest", (boost::int64_t)pwalletMain->GetOldestKeyPoolTime())); obj.push_back(Pair("keypoololdest", (boost::int64_t)pwalletMain->GetOldestKeyPoolTime()));
obj.push_back(Pair("keypoolsize", (int)pwalletMain->GetKeyPoolSize())); obj.push_back(Pair("keypoolsize", (int)pwalletMain->GetKeyPoolSize()));
} }
#endif
obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee))); obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee)));
#ifdef ENABLE_WALLET
if (pwalletMain && pwalletMain->IsCrypted()) if (pwalletMain && pwalletMain->IsCrypted())
obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime)); obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime));
#endif
obj.push_back(Pair("errors", GetWarnings("statusbar"))); obj.push_back(Pair("errors", GetWarnings("statusbar")));
return obj; return obj;
} }

15
src/rpcrawtransaction.cpp

@ -8,7 +8,12 @@
#include "init.h" #include "init.h"
#include "net.h" #include "net.h"
#include "uint256.h" #include "uint256.h"
#include "core.h"
#include "main.h"
#include "keystore.h"
#ifdef ENABLE_WALLET
#include "wallet.h" #include "wallet.h"
#endif
#include <stdint.h> #include <stdint.h>
@ -190,6 +195,7 @@ Value getrawtransaction(const Array& params, bool fHelp)
return result; return result;
} }
#ifdef ENABLE_WALLET
Value listunspent(const Array& params, bool fHelp) Value listunspent(const Array& params, bool fHelp)
{ {
if (fHelp || params.size() > 3) if (fHelp || params.size() > 3)
@ -303,6 +309,7 @@ Value listunspent(const Array& params, bool fHelp)
return results; return results;
} }
#endif
Value createrawtransaction(const Array& params, bool fHelp) Value createrawtransaction(const Array& params, bool fHelp)
{ {
@ -508,7 +515,9 @@ Value signrawtransaction(const Array& params, bool fHelp)
"this transaction depends on but may not yet be in the block chain.\n" "this transaction depends on but may not yet be in the block chain.\n"
"The third optional argument (may be null) is an array of base58-encoded private\n" "The third optional argument (may be null) is an array of base58-encoded private\n"
"keys that, if given, will be the only keys used to sign the transaction.\n" "keys that, if given, will be the only keys used to sign the transaction.\n"
#ifdef ENABLE_WALLET
+ HelpRequiringPassphrase() + "\n" + HelpRequiringPassphrase() + "\n"
#endif
"\nArguments:\n" "\nArguments:\n"
"1. \"hexstring\" (string, required) The transaction hex string\n" "1. \"hexstring\" (string, required) The transaction hex string\n"
@ -605,8 +614,10 @@ Value signrawtransaction(const Array& params, bool fHelp)
tempKeystore.AddKey(key); tempKeystore.AddKey(key);
} }
} }
#ifdef ENABLE_WALLET
else else
EnsureWalletIsUnlocked(); EnsureWalletIsUnlocked();
#endif
// Add previous txouts given in the RPC call: // Add previous txouts given in the RPC call:
if (params.size() > 1 && params[1].type() != null_type) if (params.size() > 1 && params[1].type() != null_type)
@ -662,7 +673,11 @@ Value signrawtransaction(const Array& params, bool fHelp)
} }
} }
#ifdef ENABLE_WALLET
const CKeyStore& keystore = ((fGivenKeys || !pwalletMain) ? tempKeystore : *pwalletMain); const CKeyStore& keystore = ((fGivenKeys || !pwalletMain) ? tempKeystore : *pwalletMain);
#else
const CKeyStore& keystore = tempKeystore;
#endif
int nHashType = SIGHASH_ALL; int nHashType = SIGHASH_ALL;
if (params.size() > 3 && params[3].type() != null_type) if (params.size() > 3 && params[3].type() != null_type)

45
src/rpcserver.cpp

@ -9,7 +9,10 @@
#include "init.h" #include "init.h"
#include "main.h" #include "main.h"
#include "util.h" #include "util.h"
#include "ui_interface.h"
#ifdef ENABLE_WALLET
#include "wallet.h" #include "wallet.h"
#endif
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/asio.hpp> #include <boost/asio.hpp>
@ -149,8 +152,10 @@ string CRPCTable::help(string strCommand) const
continue; continue;
if (strCommand != "" && strMethod != strCommand) if (strCommand != "" && strMethod != strCommand)
continue; continue;
#ifdef ENABLE_WALLET
if (pcmd->reqWallet && !pwalletMain) if (pcmd->reqWallet && !pwalletMain)
continue; continue;
#endif
try try
{ {
@ -228,11 +233,26 @@ static const CRPCCommand vRPCCommands[] =
{ "getaddednodeinfo", &getaddednodeinfo, true, true, false }, { "getaddednodeinfo", &getaddednodeinfo, true, true, false },
{ "getnettotals", &getnettotals, true, true, false }, { "getnettotals", &getnettotals, true, true, false },
{ "getdifficulty", &getdifficulty, true, false, false }, { "getdifficulty", &getdifficulty, true, false, false },
{ "getinfo", &getinfo, true, false, false },
{ "getrawmempool", &getrawmempool, true, false, false },
{ "getblock", &getblock, false, false, false },
{ "getblockhash", &getblockhash, false, false, false },
{ "settxfee", &settxfee, false, false, true },
{ "getrawtransaction", &getrawtransaction, false, false, false },
{ "createrawtransaction", &createrawtransaction, false, false, false },
{ "decoderawtransaction", &decoderawtransaction, false, false, false },
{ "decodescript", &decodescript, false, false, false },
{ "signrawtransaction", &signrawtransaction, false, false, false },
{ "sendrawtransaction", &sendrawtransaction, false, false, false },
{ "gettxoutsetinfo", &gettxoutsetinfo, true, false, false },
{ "gettxout", &gettxout, true, false, false },
{ "verifychain", &verifychain, true, false, false },
#ifdef ENABLE_WALLET
{ "getnetworkhashps", &getnetworkhashps, true, false, false }, { "getnetworkhashps", &getnetworkhashps, true, false, false },
{ "getgenerate", &getgenerate, true, false, false }, { "getgenerate", &getgenerate, true, false, false },
{ "setgenerate", &setgenerate, true, true, false }, { "setgenerate", &setgenerate, true, true, false },
{ "gethashespersec", &gethashespersec, true, false, false }, { "gethashespersec", &gethashespersec, true, false, false },
{ "getinfo", &getinfo, true, false, false },
{ "getmininginfo", &getmininginfo, true, false, false }, { "getmininginfo", &getmininginfo, true, false, false },
{ "getnewaddress", &getnewaddress, true, false, true }, { "getnewaddress", &getnewaddress, true, false, true },
{ "getaccountaddress", &getaccountaddress, true, false, true }, { "getaccountaddress", &getaccountaddress, true, false, true },
@ -258,9 +278,6 @@ static const CRPCCommand vRPCCommands[] =
{ "sendmany", &sendmany, false, false, true }, { "sendmany", &sendmany, false, false, true },
{ "addmultisigaddress", &addmultisigaddress, false, false, true }, { "addmultisigaddress", &addmultisigaddress, false, false, true },
{ "createmultisig", &createmultisig, true, true , false }, { "createmultisig", &createmultisig, true, true , false },
{ "getrawmempool", &getrawmempool, true, false, false },
{ "getblock", &getblock, false, false, false },
{ "getblockhash", &getblockhash, false, false, false },
{ "gettransaction", &gettransaction, false, false, true }, { "gettransaction", &gettransaction, false, false, true },
{ "listtransactions", &listtransactions, false, false, true }, { "listtransactions", &listtransactions, false, false, true },
{ "listaddressgroupings", &listaddressgroupings, false, false, true }, { "listaddressgroupings", &listaddressgroupings, false, false, true },
@ -268,7 +285,6 @@ static const CRPCCommand vRPCCommands[] =
{ "verifymessage", &verifymessage, false, false, false }, { "verifymessage", &verifymessage, false, false, false },
{ "getwork", &getwork, true, false, true }, { "getwork", &getwork, true, false, true },
{ "listaccounts", &listaccounts, false, false, true }, { "listaccounts", &listaccounts, false, false, true },
{ "settxfee", &settxfee, false, false, true },
{ "getblocktemplate", &getblocktemplate, true, false, false }, { "getblocktemplate", &getblocktemplate, true, false, false },
{ "submitblock", &submitblock, false, false, false }, { "submitblock", &submitblock, false, false, false },
{ "listsinceblock", &listsinceblock, false, false, true }, { "listsinceblock", &listsinceblock, false, false, true },
@ -277,17 +293,9 @@ static const CRPCCommand vRPCCommands[] =
{ "importprivkey", &importprivkey, false, false, true }, { "importprivkey", &importprivkey, false, false, true },
{ "importwallet", &importwallet, false, false, true }, { "importwallet", &importwallet, false, false, true },
{ "listunspent", &listunspent, false, false, true }, { "listunspent", &listunspent, false, false, true },
{ "getrawtransaction", &getrawtransaction, false, false, false },
{ "createrawtransaction", &createrawtransaction, false, false, false },
{ "decoderawtransaction", &decoderawtransaction, false, false, false },
{ "decodescript", &decodescript, false, false, false },
{ "signrawtransaction", &signrawtransaction, false, false, false },
{ "sendrawtransaction", &sendrawtransaction, false, false, false },
{ "gettxoutsetinfo", &gettxoutsetinfo, true, false, false },
{ "gettxout", &gettxout, true, false, false },
{ "lockunspent", &lockunspent, false, false, true }, { "lockunspent", &lockunspent, false, false, true },
{ "listlockunspent", &listlockunspent, false, false, true }, { "listlockunspent", &listlockunspent, false, false, true },
{ "verifychain", &verifychain, true, false, false }, #endif // ENABLE_WALLET
}; };
CRPCTable::CRPCTable() CRPCTable::CRPCTable()
@ -788,8 +796,10 @@ json_spirit::Value CRPCTable::execute(const std::string &strMethod, const json_s
const CRPCCommand *pcmd = tableRPC[strMethod]; const CRPCCommand *pcmd = tableRPC[strMethod];
if (!pcmd) if (!pcmd)
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found"); throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found");
#ifdef ENABLE_WALLET
if (pcmd->reqWallet && !pwalletMain) if (pcmd->reqWallet && !pwalletMain)
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found (disabled)"); throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found (disabled)");
#endif
// Observe safe mode // Observe safe mode
string strWarning = GetWarnings("rpc"); string strWarning = GetWarnings("rpc");
@ -804,6 +814,7 @@ json_spirit::Value CRPCTable::execute(const std::string &strMethod, const json_s
{ {
if (pcmd->threadSafe) if (pcmd->threadSafe)
result = pcmd->actor(params, false); result = pcmd->actor(params, false);
#ifdef ENABLE_WALLET
else if (!pwalletMain) { else if (!pwalletMain) {
LOCK(cs_main); LOCK(cs_main);
result = pcmd->actor(params, false); result = pcmd->actor(params, false);
@ -811,6 +822,12 @@ json_spirit::Value CRPCTable::execute(const std::string &strMethod, const json_s
LOCK2(cs_main, pwalletMain->cs_wallet); LOCK2(cs_main, pwalletMain->cs_wallet);
result = pcmd->actor(params, false); result = pcmd->actor(params, false);
} }
#else // ENABLE_WALLET
else {
LOCK(cs_main);
result = pcmd->actor(params, false);
}
#endif // !ENABLE_WALLET
} }
return result; return result;
} }

5
src/test/rpc_tests.cpp

@ -23,6 +23,7 @@ createArgs(int nRequired, const char* address1=NULL, const char* address2=NULL)
return result; return result;
} }
#ifdef ENABLE_WALLET
BOOST_AUTO_TEST_CASE(rpc_addmultisig) BOOST_AUTO_TEST_CASE(rpc_addmultisig)
{ {
rpcfn_type addmultisig = tableRPC["addmultisigaddress"]->actor; rpcfn_type addmultisig = tableRPC["addmultisigaddress"]->actor;
@ -59,6 +60,7 @@ BOOST_AUTO_TEST_CASE(rpc_addmultisig)
string short2(address1Hex+1, address1Hex+sizeof(address1Hex)); // first byte missing string short2(address1Hex+1, address1Hex+sizeof(address1Hex)); // first byte missing
BOOST_CHECK_THROW(addmultisig(createArgs(2, short2.c_str()), false), runtime_error); BOOST_CHECK_THROW(addmultisig(createArgs(2, short2.c_str()), false), runtime_error);
} }
#endif
static Value CallRPC(string args) static Value CallRPC(string args)
{ {
@ -79,6 +81,7 @@ static Value CallRPC(string args)
} }
} }
#ifdef ENABLE_WALLET
BOOST_AUTO_TEST_CASE(rpc_wallet) BOOST_AUTO_TEST_CASE(rpc_wallet)
{ {
// Test RPC calls for various wallet statistics // Test RPC calls for various wallet statistics
@ -106,7 +109,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet)
BOOST_CHECK_NO_THROW(CallRPC("listreceivedbyaccount 0 true")); BOOST_CHECK_NO_THROW(CallRPC("listreceivedbyaccount 0 true"));
BOOST_CHECK_THROW(CallRPC("listreceivedbyaccount 0 true extra"), runtime_error); BOOST_CHECK_THROW(CallRPC("listreceivedbyaccount 0 true extra"), runtime_error);
} }
#endif
BOOST_AUTO_TEST_CASE(rpc_rawparams) BOOST_AUTO_TEST_CASE(rpc_rawparams)
{ {

10
src/test/test_bitcoin.cpp

@ -7,7 +7,9 @@
#include "txdb.h" #include "txdb.h"
#include "ui_interface.h" #include "ui_interface.h"
#include "util.h" #include "util.h"
#ifdef ENABLE_WALLET
#include "wallet.h" #include "wallet.h"
#endif
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
@ -26,7 +28,9 @@ struct TestingSetup {
TestingSetup() { TestingSetup() {
fPrintToDebugger = true; // don't want to write to debug.log file fPrintToDebugger = true; // don't want to write to debug.log file
noui_connect(); noui_connect();
#ifdef ENABLE_WALLET
bitdb.MakeMock(); bitdb.MakeMock();
#endif
pathTemp = GetTempPath() / strprintf("test_bitcoin_%lu_%i", (unsigned long)GetTime(), (int)(GetRand(100000))); pathTemp = GetTempPath() / strprintf("test_bitcoin_%lu_%i", (unsigned long)GetTime(), (int)(GetRand(100000)));
boost::filesystem::create_directories(pathTemp); boost::filesystem::create_directories(pathTemp);
mapArgs["-datadir"] = pathTemp.string(); mapArgs["-datadir"] = pathTemp.string();
@ -34,10 +38,12 @@ struct TestingSetup {
pcoinsdbview = new CCoinsViewDB(1 << 23, true); pcoinsdbview = new CCoinsViewDB(1 << 23, true);
pcoinsTip = new CCoinsViewCache(*pcoinsdbview); pcoinsTip = new CCoinsViewCache(*pcoinsdbview);
InitBlockIndex(); InitBlockIndex();
#ifdef ENABLE_WALLET
bool fFirstRun; bool fFirstRun;
pwalletMain = new CWallet("wallet.dat"); pwalletMain = new CWallet("wallet.dat");
pwalletMain->LoadWallet(fFirstRun); pwalletMain->LoadWallet(fFirstRun);
RegisterWallet(pwalletMain); RegisterWallet(pwalletMain);
#endif
nScriptCheckThreads = 3; nScriptCheckThreads = 3;
for (int i=0; i < nScriptCheckThreads-1; i++) for (int i=0; i < nScriptCheckThreads-1; i++)
threadGroup.create_thread(&ThreadScriptCheck); threadGroup.create_thread(&ThreadScriptCheck);
@ -46,12 +52,16 @@ struct TestingSetup {
{ {
threadGroup.interrupt_all(); threadGroup.interrupt_all();
threadGroup.join_all(); threadGroup.join_all();
#ifdef ENABLE_WALLET
delete pwalletMain; delete pwalletMain;
pwalletMain = NULL; pwalletMain = NULL;
#endif
delete pcoinsTip; delete pcoinsTip;
delete pcoinsdbview; delete pcoinsdbview;
delete pblocktree; delete pblocktree;
#ifdef ENABLE_WALLET
bitdb.Flush(true); bitdb.Flush(true);
#endif
boost::filesystem::remove_all(pathTemp); boost::filesystem::remove_all(pathTemp);
} }
}; };

Loading…
Cancel
Save