Branch data Line data Source code
1 : : // Copyright (c) 2010 Satoshi Nakamoto
2 : : // Copyright (c) 2009-present 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.
5 : :
6 : : #ifndef BITCOIN_RPC_PROTOCOL_H
7 : : #define BITCOIN_RPC_PROTOCOL_H
8 : :
9 : : //! HTTP status codes
10 : : enum HTTPStatusCode : int
11 : : {
12 : : HTTP_OK = 200,
13 : : HTTP_NO_CONTENT = 204,
14 : : HTTP_BAD_REQUEST = 400,
15 : : HTTP_UNAUTHORIZED = 401,
16 : : HTTP_FORBIDDEN = 403,
17 : : HTTP_NOT_FOUND = 404,
18 : : HTTP_BAD_METHOD = 405,
19 : : HTTP_CONTENT_TOO_LARGE = 413,
20 : : HTTP_INTERNAL_SERVER_ERROR = 500,
21 : : HTTP_SERVICE_UNAVAILABLE = 503,
22 : : };
23 : :
24 : : //! Mapping of HTTP status codes to short string explanation.
25 : : //! Copied from libevent http.c success_phrases[] and client_error_phrases[]
26 : 2 : inline std::string_view HTTPStatusReasonString(HTTPStatusCode code)
27 : : {
28 [ + - - - : 2 : switch (code) {
- - - - -
- - ]
29 : 2 : case HTTP_OK: return "OK";
30 : 0 : case HTTP_NO_CONTENT: return "No Content";
31 : 0 : case HTTP_BAD_REQUEST: return "Bad Request";
32 : 0 : case HTTP_UNAUTHORIZED: return "Unauthorized";
33 : 0 : case HTTP_FORBIDDEN: return "Forbidden";
34 : 0 : case HTTP_NOT_FOUND: return "Not Found";
35 : 0 : case HTTP_BAD_METHOD: return "Method Not Allowed";
36 : 0 : case HTTP_CONTENT_TOO_LARGE: return "Content too large";
37 : 0 : case HTTP_INTERNAL_SERVER_ERROR: return "Internal Server Error";
38 : 0 : case HTTP_SERVICE_UNAVAILABLE: return "Service Unavailable";
39 : : }
40 : :
41 : : // Reason phrases are optional and may be replaced by local variants.
42 : : // https://httpwg.org/specs/rfc9110.html#rfc.section.15.1
43 : 0 : return "";
44 : : }
45 : :
46 : : //! Bitcoin RPC error codes
47 : : enum RPCErrorCode
48 : : {
49 : : //! Standard JSON-RPC 2.0 errors
50 : : // RPC_INVALID_REQUEST is internally mapped to HTTP_BAD_REQUEST (400).
51 : : // It should not be used for application-layer errors.
52 : : RPC_INVALID_REQUEST = -32600,
53 : : // RPC_METHOD_NOT_FOUND is internally mapped to HTTP_NOT_FOUND (404).
54 : : // It should not be used for application-layer errors.
55 : : RPC_METHOD_NOT_FOUND = -32601,
56 : : RPC_INVALID_PARAMS = -32602,
57 : : // RPC_INTERNAL_ERROR should only be used for genuine errors in bitcoind
58 : : // (for example datadir corruption).
59 : : RPC_INTERNAL_ERROR = -32603,
60 : : RPC_PARSE_ERROR = -32700,
61 : :
62 : : //! General application defined errors
63 : : RPC_MISC_ERROR = -1, //!< std::exception thrown in command handling
64 : : RPC_TYPE_ERROR = -3, //!< Unexpected type was passed as parameter
65 : : RPC_INVALID_ADDRESS_OR_KEY = -5, //!< Invalid address or key
66 : : RPC_OUT_OF_MEMORY = -7, //!< Ran out of memory during operation
67 : : RPC_INVALID_PARAMETER = -8, //!< Invalid, missing or duplicate parameter
68 : : RPC_DATABASE_ERROR = -20, //!< Database error
69 : : RPC_DESERIALIZATION_ERROR = -22, //!< Error parsing or validating structure in raw format
70 : : RPC_VERIFY_ERROR = -25, //!< General error during transaction or block submission
71 : : RPC_VERIFY_REJECTED = -26, //!< Transaction or block was rejected by network rules
72 : : RPC_VERIFY_ALREADY_IN_UTXO_SET = -27, //!< Transaction already in utxo set
73 : : RPC_IN_WARMUP = -28, //!< Client still warming up
74 : : RPC_METHOD_DEPRECATED = -32, //!< RPC method is deprecated
75 : :
76 : : //! Aliases for backward compatibility
77 : : RPC_TRANSACTION_ERROR = RPC_VERIFY_ERROR,
78 : : RPC_TRANSACTION_REJECTED = RPC_VERIFY_REJECTED,
79 : :
80 : : //! P2P client errors
81 : : RPC_CLIENT_NOT_CONNECTED = -9, //!< Bitcoin is not connected
82 : : RPC_CLIENT_IN_INITIAL_DOWNLOAD = -10, //!< Still downloading initial blocks
83 : : RPC_CLIENT_NODE_ALREADY_ADDED = -23, //!< Node is already added
84 : : RPC_CLIENT_NODE_NOT_ADDED = -24, //!< Node has not been added before
85 : : RPC_CLIENT_NODE_NOT_CONNECTED = -29, //!< Node to disconnect not found in connected nodes
86 : : RPC_CLIENT_INVALID_IP_OR_SUBNET = -30, //!< Invalid IP/Subnet
87 : : RPC_CLIENT_P2P_DISABLED = -31, //!< No valid connection manager instance found
88 : : RPC_CLIENT_NODE_CAPACITY_REACHED= -34, //!< Max number of outbound or block-relay connections already open
89 : :
90 : : //! Chain errors
91 : : RPC_CLIENT_MEMPOOL_DISABLED = -33, //!< No mempool instance found
92 : :
93 : : //! Wallet errors
94 : : RPC_WALLET_ERROR = -4, //!< Unspecified problem with wallet (key not found etc.)
95 : : RPC_WALLET_INSUFFICIENT_FUNDS = -6, //!< Not enough funds in wallet or account
96 : : RPC_WALLET_INVALID_LABEL_NAME = -11, //!< Invalid label name
97 : : RPC_WALLET_KEYPOOL_RAN_OUT = -12, //!< Keypool ran out, call keypoolrefill first
98 : : RPC_WALLET_UNLOCK_NEEDED = -13, //!< Enter the wallet passphrase with walletpassphrase first
99 : : RPC_WALLET_PASSPHRASE_INCORRECT = -14, //!< The wallet passphrase entered was incorrect
100 : : RPC_WALLET_WRONG_ENC_STATE = -15, //!< Command given in wrong wallet encryption state (encrypting an encrypted wallet etc.)
101 : : RPC_WALLET_ENCRYPTION_FAILED = -16, //!< Failed to encrypt the wallet
102 : : RPC_WALLET_ALREADY_UNLOCKED = -17, //!< Wallet is already unlocked
103 : : RPC_WALLET_NOT_FOUND = -18, //!< Invalid wallet specified
104 : : RPC_WALLET_NOT_SPECIFIED = -19, //!< No wallet specified (error when there are multiple wallets loaded)
105 : : RPC_WALLET_ALREADY_LOADED = -35, //!< This same wallet is already loaded
106 : : RPC_WALLET_ALREADY_EXISTS = -36, //!< There is already a wallet with the same name
107 : :
108 : : //! Backwards compatible aliases
109 : : RPC_WALLET_INVALID_ACCOUNT_NAME = RPC_WALLET_INVALID_LABEL_NAME,
110 : :
111 : : //! Unused reserved codes, kept around for backwards compatibility. Do not reuse.
112 : : RPC_FORBIDDEN_BY_SAFE_MODE = -2, //!< Server is in safe mode, and command is not allowed in safe mode
113 : : };
114 : :
115 : : #endif // BITCOIN_RPC_PROTOCOL_H
|