Skip to content

Commit

Permalink
RPC: error code changes and prevent crash with walletpassphrase
Browse files Browse the repository at this point in the history
- 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, RPC_NODE_ALREADY_ADDED
  and RCP_NODE_NOT_ADDED (I checked the source to not use a number already
  in use for RPC_SERVER_NOT_STARTED)
- use the new codes where needed / missing
- add missing use of RPC_INVALID_PARAMETER

Conflicts:
	src/rpcwallet.cpp
  • Loading branch information
Philip Kaufmann authored and l0rdicon committed Oct 30, 2014
1 parent 7861305 commit 634fcb5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/bitcoinrpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@ 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
RPC_CLIENT_IN_INITIAL_DOWNLOAD = -10, // Still downloading initial blocks
RPC_CLIENT_NODE_ALREADY_ADDED = -23, // Node is already added
RPC_CLIENT_NODE_NOT_ADDED = -24, // Node has not been added before

// Wallet errors
RPC_WALLET_ERROR = -4, // Unspecified problem with wallet (key not found etc.)
Expand Down
6 changes: 3 additions & 3 deletions src/rpcnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ Value addnode(const Array& params, bool fHelp)
if (strCommand == "add")
{
if (it != vAddedNodes.end())
throw JSONRPCError(-23, "Error: Node already added");
throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: Node already added");
vAddedNodes.push_back(strNode);
}
else if(strCommand == "remove")
{
if (it == vAddedNodes.end())
throw JSONRPCError(-24, "Error: Node has not been added.");
throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, "Error: Node has not been added.");
vAddedNodes.erase(it);
}

Expand Down Expand Up @@ -163,7 +163,7 @@ Value getaddednodeinfo(const Array& params, bool fHelp)
break;
}
if (laddedNodes.size() == 0)
throw JSONRPCError(-24, "Error: Node has not been added.");
throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, "Error: Node has not been added.");
}

if (!fDns)
Expand Down
2 changes: 2 additions & 0 deletions src/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,8 @@ Value walletpassphrase(const Array& params, bool fHelp)
"if [stakingonly] is true sending functions are disabled.");
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.");

Expand Down

0 comments on commit 634fcb5

Please sign in to comment.