Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2010 Satoshi Nakamoto2// Copyright (c) 2009-present The Bitcoin Core developers3// Distributed under the MIT software license, see the accompanying4// file COPYING or http://www.opensource.org/licenses/mit-license.php.6#ifndef BITCOIN_RPC_PROTOCOL_H7#define BITCOIN_RPC_PROTOCOL_H9#include <string_view>11//! HTTP status codes12enum HTTPStatusCode : int13{14HTTP_OK = 200,15HTTP_NO_CONTENT = 204,16HTTP_BAD_REQUEST = 400,17HTTP_UNAUTHORIZED = 401,18HTTP_FORBIDDEN = 403,19HTTP_NOT_FOUND = 404,20HTTP_BAD_METHOD = 405,21HTTP_CONTENT_TOO_LARGE = 413,22HTTP_INTERNAL_SERVER_ERROR = 500,23HTTP_SERVICE_UNAVAILABLE = 503,24};26//! Mapping of HTTP status codes to short string explanation.27//! Copied from libevent http.c success_phrases[] and client_error_phrases[]28inline std::string_view HTTPStatusReasonString(HTTPStatusCode code)29{30switch (code) {31case HTTP_OK: return "OK";32case HTTP_NO_CONTENT: return "No Content";33case HTTP_BAD_REQUEST: return "Bad Request";34case HTTP_UNAUTHORIZED: return "Unauthorized";35case HTTP_FORBIDDEN: return "Forbidden";36case HTTP_NOT_FOUND: return "Not Found";37case HTTP_BAD_METHOD: return "Method Not Allowed";38case HTTP_CONTENT_TOO_LARGE: return "Content too large";39case HTTP_INTERNAL_SERVER_ERROR: return "Internal Server Error";40case HTTP_SERVICE_UNAVAILABLE: return "Service Unavailable";41}43// Reason phrases are optional and may be replaced by local variants.44// https://httpwg.org/specs/rfc9110.html#rfc.section.15.145return "";46}48//! Bitcoin RPC error codes49enum RPCErrorCode50{51//! Standard JSON-RPC 2.0 errors52// RPC_INVALID_REQUEST is internally mapped to HTTP_BAD_REQUEST (400).53// It should not be used for application-layer errors.54RPC_INVALID_REQUEST = -32600,55// RPC_METHOD_NOT_FOUND is internally mapped to HTTP_NOT_FOUND (404).56// It should not be used for application-layer errors.57RPC_METHOD_NOT_FOUND = -32601,58RPC_INVALID_PARAMS = -32602,59// RPC_INTERNAL_ERROR should only be used for genuine errors in bitcoind60// (for example datadir corruption).61RPC_INTERNAL_ERROR = -32603,62RPC_PARSE_ERROR = -32700,64//! General application defined errors65RPC_MISC_ERROR = -1, //!< std::exception thrown in command handling66RPC_TYPE_ERROR = -3, //!< Unexpected type was passed as parameter67RPC_INVALID_ADDRESS_OR_KEY = -5, //!< Invalid address or key68RPC_OUT_OF_MEMORY = -7, //!< Ran out of memory during operation69RPC_INVALID_PARAMETER = -8, //!< Invalid, missing or duplicate parameter70RPC_DATABASE_ERROR = -20, //!< Database error71RPC_DESERIALIZATION_ERROR = -22, //!< Error parsing or validating structure in raw format72RPC_VERIFY_ERROR = -25, //!< General error during transaction or block submission73RPC_VERIFY_REJECTED = -26, //!< Transaction or block was rejected by network rules74RPC_VERIFY_ALREADY_IN_UTXO_SET = -27, //!< Transaction already in utxo set75RPC_IN_WARMUP = -28, //!< Client still warming up76RPC_METHOD_DEPRECATED = -32, //!< RPC method is deprecated77RPC_LIMIT_EXCEEDED = -37, //!< A bounded resource is currently at capacity79//! Aliases for backward compatibility80RPC_TRANSACTION_ERROR = RPC_VERIFY_ERROR,81RPC_TRANSACTION_REJECTED = RPC_VERIFY_REJECTED,83//! P2P client errors84RPC_CLIENT_NOT_CONNECTED = -9, //!< Bitcoin is not connected85RPC_CLIENT_IN_INITIAL_DOWNLOAD = -10, //!< Still downloading initial blocks86RPC_CLIENT_NODE_ALREADY_ADDED = -23, //!< Node is already added87RPC_CLIENT_NODE_NOT_ADDED = -24, //!< Node has not been added before88RPC_CLIENT_NODE_NOT_CONNECTED = -29, //!< Node to disconnect not found in connected nodes89RPC_CLIENT_INVALID_IP_OR_SUBNET = -30, //!< Invalid IP/Subnet90RPC_CLIENT_P2P_DISABLED = -31, //!< No valid connection manager instance found91RPC_CLIENT_NODE_CAPACITY_REACHED= -34, //!< Max number of outbound or block-relay connections already open93//! Chain errors94RPC_CLIENT_MEMPOOL_DISABLED = -33, //!< No mempool instance found96//! Wallet errors97RPC_WALLET_ERROR = -4, //!< Unspecified problem with wallet (key not found etc.)98RPC_WALLET_INSUFFICIENT_FUNDS = -6, //!< Not enough funds in wallet or account99RPC_WALLET_INVALID_LABEL_NAME = -11, //!< Invalid label name100RPC_WALLET_KEYPOOL_RAN_OUT = -12, //!< Keypool ran out, call keypoolrefill first101RPC_WALLET_UNLOCK_NEEDED = -13, //!< Enter the wallet passphrase with walletpassphrase first102RPC_WALLET_PASSPHRASE_INCORRECT = -14, //!< The wallet passphrase entered was incorrect103RPC_WALLET_WRONG_ENC_STATE = -15, //!< Command given in wrong wallet encryption state (encrypting an encrypted wallet etc.)104RPC_WALLET_ENCRYPTION_FAILED = -16, //!< Failed to encrypt the wallet105RPC_WALLET_ALREADY_UNLOCKED = -17, //!< Wallet is already unlocked106RPC_WALLET_NOT_FOUND = -18, //!< Invalid wallet specified107RPC_WALLET_NOT_SPECIFIED = -19, //!< No wallet specified (error when there are multiple wallets loaded)108RPC_WALLET_ALREADY_LOADED = -35, //!< This same wallet is already loaded109RPC_WALLET_ALREADY_EXISTS = -36, //!< There is already a wallet with the same name111//! Backwards compatible aliases112RPC_WALLET_INVALID_ACCOUNT_NAME = RPC_WALLET_INVALID_LABEL_NAME,114//! Unused reserved codes, kept around for backwards compatibility. Do not reuse.115RPC_FORBIDDEN_BY_SAFE_MODE = -2, //!< Server is in safe mode, and command is not allowed in safe mode116};118#endif // BITCOIN_RPC_PROTOCOL_H