aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2013-12-08 15:26:08 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2013-12-09 08:44:57 +0100
commit4a85e067502a5df340e1b8c49df21e4c30a0de68 (patch)
treee036991e5f02c9d5017e9230cceace4433f1d297 /src
parent70370ae502df8756f3a067a00ccd61b9fc819581 (diff)
Allow mining RPCs with --disable-wallet
The following mining-related RPC calls don't use the wallet: - getnetworkhashps - getmininginfo - getblocktemplate - submitblock Enable them when compiling with --disable-wallet.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am4
-rw-r--r--src/init.cpp4
-rw-r--r--src/miner.cpp9
-rw-r--r--src/rpcmining.cpp24
-rw-r--r--src/rpcserver.cpp19
5 files changed, 40 insertions, 20 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index df4087c313..62dd63abef 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -48,9 +48,11 @@ libbitcoin_server_a_SOURCES = \
keystore.cpp \
leveldbwrapper.cpp \
main.cpp \
+ miner.cpp \
net.cpp \
noui.cpp \
rpcblockchain.cpp \
+ rpcmining.cpp \
rpcnet.cpp \
rpcrawtransaction.cpp \
txdb.cpp \
@@ -61,9 +63,7 @@ libbitcoin_server_a_SOURCES = \
libbitcoin_wallet_a_SOURCES = \
db.cpp \
crypter.cpp \
- miner.cpp \
rpcdump.cpp \
- rpcmining.cpp \
rpcwallet.cpp \
wallet.cpp \
walletdb.cpp \
diff --git a/src/init.cpp b/src/init.cpp
index fc15df0594..f4424b6ba5 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -113,8 +113,8 @@ void Shutdown()
RenameThread("bitcoin-shutoff");
mempool.AddTransactionsUpdated(1);
StopRPCThreads();
-#ifdef ENABLE_WALLET
ShutdownRPCMining();
+#ifdef ENABLE_WALLET
if (pwalletMain)
bitdb.Flush(false);
GenerateBitcoins(false, NULL, 0);
@@ -1041,10 +1041,8 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer)
#endif
StartNode(threadGroup);
-#ifdef ENABLE_WALLET
// InitRPCMining is needed here so getwork/getblocktemplate in the GUI debug console works properly.
InitRPCMining();
-#endif
if (fServer)
StartRPCThreads();
diff --git a/src/miner.cpp b/src/miner.cpp
index ecc40ac708..384ebd27cf 100644
--- a/src/miner.cpp
+++ b/src/miner.cpp
@@ -10,8 +10,11 @@
#include "net.h"
#include "wallet.h"
+#ifdef ENABLE_WALLET
+// These globals are only used by the built-in miner
double dHashesPerSec = 0.0;
int64_t nHPSTimerStart = 0;
+#endif
//////////////////////////////////////////////////////////////////////////////
//
@@ -381,6 +384,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
return pblocktemplate.release();
}
+#ifdef ENABLE_WALLET
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)
{
CPubKey pubkey;
@@ -390,6 +394,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)
CScript scriptPubKey = CScript() << pubkey << OP_CHECKSIG;
return CreateNewBlock(scriptPubKey);
}
+#endif
void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& nExtraNonce)
{
@@ -454,7 +459,7 @@ void FormatHashBuffers(CBlock* pblock, char* pmidstate, char* pdata, char* phash
memcpy(phash1, &tmp.hash1, 64);
}
-
+#ifdef ENABLE_WALLET
bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey)
{
uint256 hash = pblock->GetHash();
@@ -665,5 +670,5 @@ void GenerateBitcoins(bool fGenerate, CWallet* pwallet, int nThreads)
minerThreads->create_thread(boost::bind(&BitcoinMiner, pwallet));
}
-
+#endif
diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp
index 131a258c84..b81433120e 100644
--- a/src/rpcmining.cpp
+++ b/src/rpcmining.cpp
@@ -20,7 +20,8 @@
using namespace json_spirit;
using namespace std;
-// Key used by getwork/getblocktemplate miners.
+#ifdef ENABLE_WALLET
+// Key used by getwork miners.
// Allocated in InitRPCMining, free'd in ShutdownRPCMining
static CReserveKey* pMiningKey = NULL;
@@ -40,6 +41,14 @@ void ShutdownRPCMining()
delete pMiningKey; pMiningKey = NULL;
}
+#else
+void InitRPCMining()
+{
+}
+void ShutdownRPCMining()
+{
+}
+#endif
// Return average network hashes per second based on the last 'lookup' blocks,
// or from the last difficulty change if 'lookup' is nonpositive.
@@ -99,7 +108,7 @@ Value getnetworkhashps(const Array& params, bool fHelp)
return GetNetworkHashPS(params.size() > 0 ? params[0].get_int() : 120, params.size() > 1 ? params[1].get_int() : -1);
}
-
+#ifdef ENABLE_WALLET
Value getgenerate(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 0)
@@ -197,7 +206,6 @@ Value setgenerate(const Array& params, bool fHelp)
return Value::null;
}
-
Value gethashespersec(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 0)
@@ -216,6 +224,7 @@ Value gethashespersec(const Array& params, bool fHelp)
return (boost::int64_t)0;
return (boost::int64_t)dHashesPerSec;
}
+#endif
Value getmininginfo(const Array& params, bool fHelp)
@@ -248,16 +257,19 @@ Value getmininginfo(const Array& params, bool fHelp)
obj.push_back(Pair("currentblocktx", (uint64_t)nLastBlockTx));
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
obj.push_back(Pair("errors", GetWarnings("statusbar")));
- obj.push_back(Pair("generate", getgenerate(params, false)));
obj.push_back(Pair("genproclimit", (int)GetArg("-genproclimit", -1)));
- obj.push_back(Pair("hashespersec", gethashespersec(params, false)));
obj.push_back(Pair("networkhashps", getnetworkhashps(params, false)));
obj.push_back(Pair("pooledtx", (uint64_t)mempool.size()));
obj.push_back(Pair("testnet", TestNet()));
+#ifdef ENABLE_WALLET
+ obj.push_back(Pair("generate", getgenerate(params, false)));
+ obj.push_back(Pair("hashespersec", gethashespersec(params, false)));
+#endif
return obj;
}
+#ifdef ENABLE_WALLET
Value getwork(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 1)
@@ -381,7 +393,7 @@ Value getwork(const Array& params, bool fHelp)
return CheckWork(pblock, *pwalletMain, *pMiningKey);
}
}
-
+#endif
Value getblocktemplate(const Array& params, bool fHelp)
{
diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp
index 2dc7b34f88..c95f450c82 100644
--- a/src/rpcserver.cpp
+++ b/src/rpcserver.cpp
@@ -248,12 +248,14 @@ static const CRPCCommand vRPCCommands[] =
{ "gettxout", &gettxout, true, false, false },
{ "verifychain", &verifychain, true, false, false },
-#ifdef ENABLE_WALLET
+ /* Mining */
{ "getnetworkhashps", &getnetworkhashps, true, false, false },
- { "getgenerate", &getgenerate, true, false, false },
- { "setgenerate", &setgenerate, true, true, false },
- { "gethashespersec", &gethashespersec, true, false, false },
{ "getmininginfo", &getmininginfo, true, false, false },
+ { "getblocktemplate", &getblocktemplate, true, false, false },
+ { "submitblock", &submitblock, false, false, false },
+
+#ifdef ENABLE_WALLET
+ /* Wallet */
{ "getnewaddress", &getnewaddress, true, false, true },
{ "getaccountaddress", &getaccountaddress, true, false, true },
{ "getrawchangeaddress", &getrawchangeaddress, true, false, true },
@@ -283,10 +285,7 @@ static const CRPCCommand vRPCCommands[] =
{ "listaddressgroupings", &listaddressgroupings, false, false, true },
{ "signmessage", &signmessage, false, false, true },
{ "verifymessage", &verifymessage, false, false, false },
- { "getwork", &getwork, true, false, true },
{ "listaccounts", &listaccounts, false, false, true },
- { "getblocktemplate", &getblocktemplate, true, false, false },
- { "submitblock", &submitblock, false, false, false },
{ "listsinceblock", &listsinceblock, false, false, true },
{ "dumpprivkey", &dumpprivkey, true, false, true },
{ "dumpwallet", &dumpwallet, true, false, true },
@@ -295,6 +294,12 @@ static const CRPCCommand vRPCCommands[] =
{ "listunspent", &listunspent, false, false, true },
{ "lockunspent", &lockunspent, false, false, true },
{ "listlockunspent", &listlockunspent, false, false, true },
+
+ /* Wallet-enabled mining */
+ { "getgenerate", &getgenerate, true, false, false },
+ { "setgenerate", &setgenerate, true, true, false },
+ { "gethashespersec", &gethashespersec, true, false, false },
+ { "getwork", &getwork, true, false, true },
#endif // ENABLE_WALLET
};