You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

protocol.h 4.9KB

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