Merge #12001: [RPC] Adding ::minRelayTxFee amount to getmempoolinfo and updating...
[bitcoinplatinum.git] / src / rpc / protocol.h
blob00b92f19567d9e019bd5d5561c59886031ddebe0
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2017 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 #ifndef BITCOIN_RPCPROTOCOL_H
7 #define BITCOIN_RPCPROTOCOL_H
9 #include <fs.h>
11 #include <list>
12 #include <map>
13 #include <stdint.h>
14 #include <string>
16 #include <univalue.h>
18 //! HTTP status codes
19 enum HTTPStatusCode
21 HTTP_OK = 200,
22 HTTP_BAD_REQUEST = 400,
23 HTTP_UNAUTHORIZED = 401,
24 HTTP_FORBIDDEN = 403,
25 HTTP_NOT_FOUND = 404,
26 HTTP_BAD_METHOD = 405,
27 HTTP_INTERNAL_SERVER_ERROR = 500,
28 HTTP_SERVICE_UNAVAILABLE = 503,
31 //! Bitcoin RPC error codes
32 enum RPCErrorCode
34 //! Standard JSON-RPC 2.0 errors
35 // RPC_INVALID_REQUEST is internally mapped to HTTP_BAD_REQUEST (400).
36 // It should not be used for application-layer errors.
37 RPC_INVALID_REQUEST = -32600,
38 // RPC_METHOD_NOT_FOUND is internally mapped to HTTP_NOT_FOUND (404).
39 // It should not be used for application-layer errors.
40 RPC_METHOD_NOT_FOUND = -32601,
41 RPC_INVALID_PARAMS = -32602,
42 // RPC_INTERNAL_ERROR should only be used for genuine errors in bitcoind
43 // (for example datadir corruption).
44 RPC_INTERNAL_ERROR = -32603,
45 RPC_PARSE_ERROR = -32700,
47 //! General application defined errors
48 RPC_MISC_ERROR = -1, //!< std::exception thrown in command handling
49 RPC_FORBIDDEN_BY_SAFE_MODE = -2, //!< Server is in safe mode, and command is not allowed in safe mode
50 RPC_TYPE_ERROR = -3, //!< Unexpected type was passed as parameter
51 RPC_INVALID_ADDRESS_OR_KEY = -5, //!< Invalid address or key
52 RPC_OUT_OF_MEMORY = -7, //!< Ran out of memory during operation
53 RPC_INVALID_PARAMETER = -8, //!< Invalid, missing or duplicate parameter
54 RPC_DATABASE_ERROR = -20, //!< Database error
55 RPC_DESERIALIZATION_ERROR = -22, //!< Error parsing or validating structure in raw format
56 RPC_VERIFY_ERROR = -25, //!< General error during transaction or block submission
57 RPC_VERIFY_REJECTED = -26, //!< Transaction or block was rejected by network rules
58 RPC_VERIFY_ALREADY_IN_CHAIN = -27, //!< Transaction already in chain
59 RPC_IN_WARMUP = -28, //!< Client still warming up
60 RPC_METHOD_DEPRECATED = -32, //!< RPC method is deprecated
62 //! Aliases for backward compatibility
63 RPC_TRANSACTION_ERROR = RPC_VERIFY_ERROR,
64 RPC_TRANSACTION_REJECTED = RPC_VERIFY_REJECTED,
65 RPC_TRANSACTION_ALREADY_IN_CHAIN= RPC_VERIFY_ALREADY_IN_CHAIN,
67 //! P2P client errors
68 RPC_CLIENT_NOT_CONNECTED = -9, //!< Bitcoin is not connected
69 RPC_CLIENT_IN_INITIAL_DOWNLOAD = -10, //!< Still downloading initial blocks
70 RPC_CLIENT_NODE_ALREADY_ADDED = -23, //!< Node is already added
71 RPC_CLIENT_NODE_NOT_ADDED = -24, //!< Node has not been added before
72 RPC_CLIENT_NODE_NOT_CONNECTED = -29, //!< Node to disconnect not found in connected nodes
73 RPC_CLIENT_INVALID_IP_OR_SUBNET = -30, //!< Invalid IP/Subnet
74 RPC_CLIENT_P2P_DISABLED = -31, //!< No valid connection manager instance found
76 //! Wallet errors
77 RPC_WALLET_ERROR = -4, //!< Unspecified problem with wallet (key not found etc.)
78 RPC_WALLET_INSUFFICIENT_FUNDS = -6, //!< Not enough funds in wallet or account
79 RPC_WALLET_INVALID_ACCOUNT_NAME = -11, //!< Invalid account name
80 RPC_WALLET_KEYPOOL_RAN_OUT = -12, //!< Keypool ran out, call keypoolrefill first
81 RPC_WALLET_UNLOCK_NEEDED = -13, //!< Enter the wallet passphrase with walletpassphrase first
82 RPC_WALLET_PASSPHRASE_INCORRECT = -14, //!< The wallet passphrase entered was incorrect
83 RPC_WALLET_WRONG_ENC_STATE = -15, //!< Command given in wrong wallet encryption state (encrypting an encrypted wallet etc.)
84 RPC_WALLET_ENCRYPTION_FAILED = -16, //!< Failed to encrypt the wallet
85 RPC_WALLET_ALREADY_UNLOCKED = -17, //!< Wallet is already unlocked
86 RPC_WALLET_NOT_FOUND = -18, //!< Invalid wallet specified
87 RPC_WALLET_NOT_SPECIFIED = -19, //!< No wallet specified (error when there are multiple wallets loaded)
90 UniValue JSONRPCRequestObj(const std::string& strMethod, const UniValue& params, const UniValue& id);
91 UniValue JSONRPCReplyObj(const UniValue& result, const UniValue& error, const UniValue& id);
92 std::string JSONRPCReply(const UniValue& result, const UniValue& error, const UniValue& id);
93 UniValue JSONRPCError(int code, const std::string& message);
95 /** Generate a new RPC authentication cookie and write it to disk */
96 bool GenerateAuthCookie(std::string *cookie_out);
97 /** Read the RPC authentication cookie from disk */
98 bool GetAuthCookie(std::string *cookie_out);
99 /** Delete RPC authentication cookie from disk */
100 void DeleteAuthCookie();
101 /** Parse JSON-RPC batch reply into a vector */
102 std::vector<UniValue> JSONRPCProcessBatchReply(const UniValue &in, size_t num);
104 #endif // BITCOIN_RPCPROTOCOL_H