OSDN Git Service

RPC: prevent crash with walletpassphrase
authormonacoinproject <monacoinproject@gmail.com>
Sun, 6 Apr 2014 13:56:52 +0000 (22:56 +0900)
committermonacoinproject <monacoinproject@gmail.com>
Sun, 6 Apr 2014 13:56:52 +0000 (22:56 +0900)
- fix crash with walletpassphrase by checking if RPC server is running
and
give a friendly error message how to fix this (fixes #3100)
- add 3 new RPCErrorCodes RPC_SERVER_NOT_STARTED
- use the new code where needed / missing

Upstream: 4315ec1

Conflicts:
src/rpcnet.cpp
src/rpcwallet.cpp

src/bitcoinrpc.h
src/rpcwallet.cpp

index bea7712..137c045 100644 (file)
@@ -49,6 +49,7 @@ enum RPCErrorCode
     RPC_INVALID_PARAMETER           = -8,  // Invalid, missing or duplicate parameter
     RPC_DATABASE_ERROR              = -20, // Database error
     RPC_DESERIALIZATION_ERROR       = -22, // Error parsing or validating structure in raw format
+    RPC_SERVER_NOT_STARTED          = -18, // RPC server was not started (StartRPCThreads() not called)
 
     // P2P client errors
     RPC_CLIENT_NOT_CONNECTED        = -9,  // Bitcoin is not connected
index 48462d8..af94aff 100644 (file)
@@ -1360,6 +1360,8 @@ Value walletpassphrase(const Array& params, bool fHelp)
             "Stores the wallet decryption key in memory for <timeout> seconds.");
     if (fHelp)
         return true;
+    if (!fServer)
+        throw JSONRPCError(RPC_SERVER_NOT_STARTED, "Error: RPC server was not started, use server=1 to change this.");
     if (!pwalletMain->IsCrypted())
         throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrase was called.");